clr

When does the CLR load an assembly in a .NET process?

回眸只為那壹抹淺笑 提交于 2019-12-05 14:19:12
Is a .NET assembly loaded by the CLR when a class from the assembly is referenced? Or When a class which declares the using namespace from the assembly is loaded? Also having loaded an assembly, does it ever unloads the assembly if it is not used for a long time? It's the JIT compiler that instructs the CLR to load an assembly once it has translated it to machine code which is done on demand and the exact time is not deterministic. As to the second question, once an assembly is loaded into the AppDomain, the only way to unload it is to destroy this AppDomain, there's no other way to unload an

Error <mutex> is not supported when compiling with /clr or /clr:pure

人盡茶涼 提交于 2019-12-05 14:07:02
I have a C++ dll which I will call Dll A where I have used: #include <mutex> Dll As properties are set to "No Common Language Runtime Support" and it builds successfully. I have another Dll B which includes DLL A in its references. Dll Bs properties are set to: "Common Language Runtime Support (/clr)" as it includes C++/CLI code. When I build DLL B I get the error: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\mutex(8): fatal error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure. I know that I cannot include in a CLR supported DLL but is there a

When is a System.Double not a double?

霸气de小男生 提交于 2019-12-05 13:11:32
问题 After seeing how double.Nan == double.NaN is always false in C#, I became curious how the equality was implemented under the hood. So I used Resharper to decompile the Double struct, and here is what I found: public struct Double : IComparable, IFormattable, IConvertible, IComparable<double>, IEquatable<double> { // stuff removed... public const double NaN = double.NaN; // more stuff removed... } This seems to indicate the the struct Double declares a constant that is defined in terms of this

Preventing unmanaged function pointer garbage collection

三世轮回 提交于 2019-12-05 12:21:47
The documentation for converting delegates to unmanaged code states that I am responsible for preventing it's collection myself. I wish to know if the delegate cannot be collected whilst the unmanaged call is live. For example, if I do UnmanagedFunction(arg => somebody); where UnmanagedFunction does not store the function pointer beyond it's invocation. This should be legal, right? The CLR can't collect whilst the UnmanagedFunction is executing. According to CLR Inside Out: Marshaling between Managed and Unmanaged Code : Usually, you won't have to worry about the lifetime of delegates.

Does implicit operator have higher priority over ToString() method? [duplicate]

我的未来我决定 提交于 2019-12-05 12:20:23
This question already has an answer here : Order of implicit conversions in c# (1 answer) Closed 12 months ago . Consider the following code: public class Test { public static implicit operator int(Test t) { return 42; } public override string ToString() { return "Test here!"; } } var test = new Test(); Console.WriteLine(test); // 42 Console.WriteLine((Test)test); // 42 Console.WriteLine((int)test); // 42 Console.WriteLine(test.ToString()); // "Test here!" Why in the first three cases we have answer 42 even if we explicitly cast to Test ? Does implicit operator have higher priority over

Calling methods on value types

半城伤御伤魂 提交于 2019-12-05 12:08:11
Stop me if I make a mistake here. If I understand correctly, when I call a method on an instance of a class, the JIT compiler locates the type object corresponding to the type of the instance and then locates a reference therein to the actual method code. My question is how does this work for value types? I was under the impression that value types did not have a type object pointer like reference types do. If this is the case, how does the CLR manage to navigate to the method code when one is called? Consider an example, suppose we have the following structure: public struct Test { public

CLR 2.0 vs 4.0 performance?

房东的猫 提交于 2019-12-05 12:06:55
Will a .NET program compiled for CLR 2.0 run faster if running unden CLR 4.0? app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0,Profile=Client" /> <supportedRuntime version="v2.0.50727"/> </startup> </configuration> Typically, no - it will be identical. By default, the CLR 4 runtime will load the CLR 2 runtime to execute your CLR 2 code base. Forcing execution under CLR 4 requires setting useLegacyV2RuntimeActivationPolicy in your app.Config. If you add that flag, then it will run in v4 of the

CLR Profiler and 0 Heap Statistics

拈花ヽ惹草 提交于 2019-12-05 12:06:50
Why would I get 0 for my heap statistics allocation for an ASP.NET MVC web application with CLR profiler? I was getting zeroes, but I think doing these two things solved the issue of zeroes: make sure you have "Allocations" checked in the "Profile" section and be sure to end the application before trying to see the profiling info. Either end it through CLR Profiler ("Kill Application") or from within the application itself. I believe both of those things were required to make it work for me. 来源: https://stackoverflow.com/questions/23376436/clr-profiler-and-0-heap-statistics

How often does a managed thread switch OS threads?

╄→гoц情女王★ 提交于 2019-12-05 10:17:07
I understand that managed threads are not guaranteed to run on the same OS thread. If the CLR may switch a managed thread between OS threads, how often does this happen? What influence the frequency? I've got a separate question on how to stop the switching from happening. Second prize for me would be for this to not happen too often (less than once a minute would be fine). It completely depends on the host. There is no guarantee as to when or where a thread switch might take place (if at all), given any particular host. However, since .NET 2.0, you have been able to call the static

What does RuntimeHelpers.GetHashCode do

一曲冷凌霜 提交于 2019-12-05 09:39:23
问题 The RuntimeHelpers.GetHashCode(object) method allows generating hash codes based on the identity of an object. MSDN states: The RuntimeHelpers.GetHashCode method always calls the Object.GetHashCode method non-virtually, even if the object's type has overridden the Object.GetHashCode method. [MethodImpl(MethodImplOptions.InternalCall)] [SecuritySafeCritical] public static extern int GetHashCode(object o); However, when inspecting the Object.GetHashCode() method using Reflector (.NET 4.0), we