clr

What happens when a .net application is started?

给你一囗甜甜゛ 提交于 2019-11-28 04:22:50
I have been developing apps using .net for quite sometime now. But, I am still not sure how does the CLR know that a .net app has started. Is there like one instance of CLR per app? I don't think this can be the case as there is just one GC which manages all the memory for all .net apps. Does the CLR kind of run in background? I am quite confused. Hmm, let me take a shot at this too. Somebody builds a .NET application in C#, or .NET 'Intermediate Language', or another managed language. The compiler for that language csc.exe (C#), or ilasm.exe (bytecode assembler), or whichever, produces a PE

No AppDomains in .NET Core! Why?

故事扮演 提交于 2019-11-28 04:03:18
Is there a strong reason why Microsoft chose not to support AppDomains in .NET Core? AppDomains are particularly useful when building long running server apps, where we may want to update the assemblies loaded by the server is a graceful manner, without shutting down the server. Without AppDomains, how are we going to replace our assemblies in a long running server process? AppDomains also provide us a way to isolate different parts of server code. Like, a custom websocket server can have socket code in primary appdomain, while our services run in secondary appdomain. Without AppDomains, the

How extension methods are implemented internally

大憨熊 提交于 2019-11-28 03:44:18
问题 How are extension methods implemented internally? I mean what happens when the compiler sees a declaration for an extension method and what happens at runtime when there is a call to an extension method. Is reflection involved? Or when you have an extension method is its code injected in the target class type metadata with some additional flags noting that this is an extension method and then the CLR knows how to handle that? So in general, what happens under the hood? 回答1: As already have

Why does struct alignment depend on whether a field type is primitive or user-defined?

大城市里の小女人 提交于 2019-11-28 03:21:43
In Noda Time v2, we're moving to nanosecond resolution. That means we can no longer use an 8-byte integer to represent the whole range of time we're interested in. That has prompted me to investigate the memory usage of the (many) structs of Noda Time, which has in turn led me to uncover a slight oddity in the CLR's alignment decision. Firstly, I realize that this is an implementation decision, and that the default behaviour could change at any time. I realize that I can modify it using [StructLayout] and [FieldOffset] , but I'd rather come up with a solution which didn't require that if

Adding code to the beginning / end of methods in runtime dynamically

≯℡__Kan透↙ 提交于 2019-11-28 03:17:38
问题 I know instrumentation is a technique to add trace code dynamically into the methods to enable tracing and debugging. I was wondering if this is only a "Trace" option, hard coded into the CLR to add only trace code, or is there the ability to add any code to the methods? For example, I want to check for a condition in the beginning of every single method call in a certain class (say for permissions). Can I do this via adding dynamic code to the beginning of the methods in execution time? I'm

Force x86 CLR on an 'Any CPU' .NET assembly

早过忘川 提交于 2019-11-28 03:15:09
In .NET, the 'Platform Target: Any CPU' compiler option allows a .NET assembly to run as 64 bit on a x64 machine, and 32 bit on an x86 machine. It is also possible to force an assembly to run as x86 on an x64 machine using the 'Platform Target: x86' compiler option. Is it possible to run an assembly with the 'Any CPU' flag, but determine whether it should be run in the x86 or x64 CLR? Normally this decision is made by the CLR/OS Loader (as is my understanding) based on the bitness of the underlying system. I am trying to write a C# .NET application that can interact with (read: inject code

How does C# compilation get around needing header files?

老子叫甜甜 提交于 2019-11-28 03:02:32
I've spent my professional life as a C# developer. As a student I occasionally used C but did not deeply study it's compilation model. Recently I jumped on the bandwagon and have begun studying Objective-C. My first steps have only made me aware of holes in my pre-existing knowledge. From my research, C/C++/ObjC compilation requires all encountered symbols to be pre-declared. I also understand that building is a two-step process. First you compile each individual source file into individual object files. These object files might have undefined "symbols" (which generally correspond to the

Is there a way to get the .Net JIT or C# compiler to optimize away empty for-loops?

做~自己de王妃 提交于 2019-11-28 02:58:27
问题 A followup to Does .NET JIT optimize empty loops away?: The following program just runs an empty loop a billion times and prints out the time to run. It takes 700 ms on my machine, and I'm curious if there's a way to get the jitter to optimize away the empty loop. using System; namespace ConsoleApplication1 { class Program { static void Main() { var start = DateTime.Now; for (var i = 0; i < 1000000000; i++) {} Console.WriteLine((DateTime.Now - start).TotalMilliseconds); } } } As far as I can

CLR vs JIT

心不动则不痛 提交于 2019-11-28 02:48:28
What is the difference between the JIT compiler and CLR? If you compile your code to il and CLR runs that code then what is the JIT doing? How has JIT compilation changed with the addition of generics to the CLR? The JIT is one aspect of the CLR. Specifically it is the part responsible for changing CIL/MSIL (hereafter called IL) produced by the original language's compiler (csc.exe for Microsoft c# for example) into machine code native to the current processor (and architecture that it exposes in the current process, for example 32/64bit). If the assembly in question was ngen'd then the the

Get Current .NET CLR version at runtime?

早过忘川 提交于 2019-11-28 02:24:12
问题 How can I get the current CLR Runtime version in a running .NET program ? 回答1: Check out System.Environment.Version property (http://msdn.microsoft.com/en-us/library/system.environment.version.aspx). 回答2: Since .NET 4.5 you can't really use System.Environment.Version (it will only return 4.0.{something}, allowing you to verify that you're "at least" on 4.0 but not telling you which actual version is available unless you can map a full list of build numbers in). Instead (as @jim-w mentioned)