clr

Resolve assembly references from another folder

偶尔善良 提交于 2019-11-26 22:35:52
I am developing an application which references and uses some third party assemblies from a certain Vendor; in development box I have these 3 assemblies in a reference folder in my source tree and I can reference them and build the application, application builds but does not run because the whole server application is not installed, but this is fine. On the server where I want to copy this custom application and run all assemblies I am referencing are in folder something like: D:\ProgramFiles\VendorName\ProductName\Support\API\Bin64 and if I copy my small executable in that folder and run it,

How to detect which .NET runtime is being used (MS vs. Mono)?

£可爱£侵袭症+ 提交于 2019-11-26 22:20:11
I would like to know during execution of a program whether it is being executed using the Mono runtime or the Microsoft runtime. I'm currently using the following code to determine whether I'm on a MS CLR: static bool IsMicrosoftCLR() { return RuntimeEnvironment.GetRuntimeDirectory().Contains("Microsoft"); } However, this is somewhat dependent on the installation folder of the runtime and I'm not sure whether this will work on all installations. Is there a better way to check for the current runtime? From the Mono Project's Guide to Porting Winforms Applications : public static bool

Try-catch speeding up my code?

ⅰ亾dé卋堺 提交于 2019-11-26 22:13:35
问题 I wrote some code for testing the impact of try-catch, but seeing some surprising results. static void Main(string[] args) { Thread.CurrentThread.Priority = ThreadPriority.Highest; Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; long start = 0, stop = 0, elapsed = 0; double avg = 0.0; long temp = Fibo(1); for (int i = 1; i < 100000000; i++) { start = Stopwatch.GetTimestamp(); temp = Fibo(100); stop = Stopwatch.GetTimestamp(); elapsed = stop - start; avg = avg + (

explicitly cast generic type parameters to any interface

情到浓时终转凉″ 提交于 2019-11-26 22:13:04
In Generics FAQ: Best Practices says : The compiler will let you explicitly cast generic type parameters to any interface, but not to a class: interface ISomeInterface {...} class SomeClass {...} class MyClass<T> { void SomeMethod(T t) { ISomeInterface obj1 = (ISomeInterface)t;//Compiles SomeClass obj2 = (SomeClass)t; //Does not compile } } I see limitation reasonable for both, classes and interfaces, unless the class/interface is not specified as constraint type. So why such behavior, why it is allowed for interfaces ? I believe this is because the cast to SomeClass can mean any number of

CLR JIT optimizations violates causality?

荒凉一梦 提交于 2019-11-26 22:00:40
问题 I was writing an instructive example for a colleague to show him why testing floats for equality is often a bad idea. The example I went with was adding .1 ten times, and comparing against 1.0 (the one I was shown in my introductory numerical class). I was surprised to find that the two results were equal (code + output). float @float = 0.0f; for(int @int = 0; @int < 10; @int += 1) { @float += 0.1f; } Console.WriteLine(@float == 1.0f); Some investigation showed that this result could not be

How do I find the current time and date at compilation time in .net/C# application?

本小妞迷上赌 提交于 2019-11-26 21:37:10
问题 I want to include the current time and date in a .net application so I can include it in the start up log to show the user what version they have. Is it possible to retrieve the current time during compilation, or would I have to get the creation/modification time of the executable? E.g. Welcome to ApplicationX. This was built day-month-year at time . 回答1: If you're using reflection for your build number you can use that to figure out when a build was compiled. Version information for an

typeof(T) may return null

房东的猫 提交于 2019-11-26 21:36:01
问题 When using the typeof operator on type created through TypeBuilder, the operator will return null. I'm curious why this happens and how to prevent it. I'm starting to think this is a VS bug in the immediate window, but I'm not quite sure. It's very easy to blame others first. Ok... code to reproduce issue: static void Main() { AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName("MyAssembly"), AssemblyBuilderAccess.RunAndSave); ModuleBuilder

Boxing / Unboxing Nullable Types - Why this implementation?

落爺英雄遲暮 提交于 2019-11-26 21:09:04
问题 Extract from CLR via C# on Boxing / Unboxing value types ... On Boxing: If the nullable instance is not null , the CLR takes the value out of the nullable instance and boxes it. In other words a Nullable < Int32 > with a value of 5 is boxed into a boxed-Int32 with a value of 5. On Unboxing: Unboxing is simply the act of obtaining a reference to the unboxed portion of a boxed object. The problem is that a boxed value type cannot be simply unboxed into a nullable version of that value type

LNK2022 metadata operation: Inconsistent layout information in duplicated types

只愿长相守 提交于 2019-11-26 20:56:28
问题 I'm having a new-to-me linker error in a project I'm working with: 1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200004e). 1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std:

Why only literal strings saved in the intern pool by default?

丶灬走出姿态 提交于 2019-11-26 20:20:44
问题 Why by default only literal strings are saved in the intern pool? Example from MSDN: String s1 = "MyTest"; String s2 = new StringBuilder().Append("My").Append("Test").ToString(); String s3 = String.Intern(s2); Console.WriteLine("s1 == '{0}'", s1); Console.WriteLine("s2 == '{0}'", s2); Console.WriteLine("s3 == '{0}'", s3); Console.WriteLine("Is s2 the same reference as s1?: {0}", (Object)s2==(Object)s1); Console.WriteLine("Is s3 the same reference as s1?: {0}", (Object)s3==(Object)s1); /* This