clr

Why does my program work if my Main method in C# is private?

大城市里の小女人 提交于 2019-12-01 21:15:04
By default the type modifier for every member in a class is a private, even the Main() function type modifier is private. How does the CLR call the main method which is not visible to the outside world? Thats not true. It has to be public. For e.g. public static void Main() . EDIT: Here is what I found & learned today, on why Main need not be public . http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/9184c55b-4629-4fbf-ad77-2e96eadc4d62/ The CLR does not care about the accessibility of main . "Visible to the outside world" only applies to the code , not the runtime . Try using

How does the C# garbage collector find objects whose only reference is an interior pointer?

丶灬走出姿态 提交于 2019-12-01 21:03:39
In C#, ref and out params are, as far as I know, passed by passing only the raw address of the relevant value. That address may be an interior pointer to an element in an array or a field within an object. If a garbage collection occurs, it's possible that the only reference to some object is through one of these interior pointers, as in: using System; public class Foo { public int field; public static void Increment(ref int x) { System.GC.Collect(); x = x + 1; Console.WriteLine(x); } public static void Main() { Increment(ref new Foo().field); } } In that case, the GC needs to find the

Iterating through !DumpHeap output to read value at memory offset

江枫思渺然 提交于 2019-12-01 20:53:16
I'm trying to come up with a WinDbg command line expression that takes the output of the !DumpHeap command and for each address, reads a 64-bit value from offset 0x08 after the address. I think this is possible (not sure about it) but every attempt I made so far fails with some error. I searched a lot but most WinDbg articles show simple examples which I can try but my attempts fail. I have a process dump of an ASP.NET worker process. The process has some memory growth but there's no clear offender so I'm trying to list a number of objects that appear many times in memory. I'm using sos.dll

What is the CLR implementation behind raising/generating a null reference exception?

夙愿已清 提交于 2019-12-01 19:17:46
We do come across this particular and one of the most common exception in our coding/development life day or another day. My Question is NOT about WHY (I am aware it raises when we try to access properties of a reference variable which actually points to null) but its is about HOW the NULL REFERENCE EXCEPTION is generated by CLR. Sometimes I am forced to think the mechanism for identifying a reference to a null (Perhaps null is a reserved space in memory) and then raising an Exception by CLR. How CLR identify and raises this particular Exception. Does OS play any role in it? I would like to

How to define what “Type” means

↘锁芯ラ 提交于 2019-12-01 17:59:41
Excerpt from Eric Lippert's Blog about What the meaning of "is", is : A common conception of types is that a type is a set [...] of values, and that assignment compatibility is merely checking to see if a given value is a member of the necessary set. But that’s not the case in C#. The counter example he gives is that null is string returns false , but string b = null is totally fine by the C# compiler. Perhaps this is a silly question, but what is a better way to define the idea of "type" in a C#.Net context? Is it just a word used to define ... memory footprint rules? ... to the CLR? I

What is the CLR implementation behind raising/generating a null reference exception?

半城伤御伤魂 提交于 2019-12-01 17:56:07
问题 We do come across this particular and one of the most common exception in our coding/development life day or another day. My Question is NOT about WHY (I am aware it raises when we try to access properties of a reference variable which actually points to null) but its is about HOW the NULL REFERENCE EXCEPTION is generated by CLR. Sometimes I am forced to think the mechanism for identifying a reference to a null (Perhaps null is a reserved space in memory) and then raising an Exception by CLR.

Are arrays in .NET naturally aligned?

拜拜、爱过 提交于 2019-12-01 17:43:44
问题 Does .NET make any guarantees that .NET byte arrays are always properly aligned? I do need this to treat e.g. a byte array in unsafe context as longs in x64 to modify chunks of data with the native register size. But so far I have not found any documentation that the CLR does give me any guarantees that my memory access is then properly aligned. 回答1: No. And in fact arrays can be mis-aligned for the x86 jitter. Particularly a problem with double[] and long[], the garbage collector only

Are arrays in .NET naturally aligned?

江枫思渺然 提交于 2019-12-01 17:15:13
Does .NET make any guarantees that .NET byte arrays are always properly aligned? I do need this to treat e.g. a byte array in unsafe context as longs in x64 to modify chunks of data with the native register size. But so far I have not found any documentation that the CLR does give me any guarantees that my memory access is then properly aligned. No. And in fact arrays can be mis-aligned for the x86 jitter. Particularly a problem with double[] and long[], the garbage collector only provides a guarantee that they will be aligned at 4. Which explains the special rule for double[], such an array

How does .Net CLR implement an “Interface” internally?

我是研究僧i 提交于 2019-12-01 17:06:32
问题 Just curious about how .NET CLR handles interfaces internally? Q1] What happens when CLR encounters something like : simple interface example. (same used below.) interface ISampleInterface { void SampleMethod(); } class ImplementationClass : ISampleInterface { // Explicit interface member implementation: public void SampleMethod() { // Method implementation. } static void Main() { //Declare an interface instance. ISampleInterface mySampleIntobj = new ImplementationClass(); // (A) // Call the

System.Math.Abs() calls into native method System.AppDomain.GetId()?

喜夏-厌秋 提交于 2019-12-01 16:56:47
My conditional breakpoint sometimes works fine, and sometimes fails, with the following error: The condition for a breakpoint failed to execute. The condition was 'Math.Abs(-4.36767421599683 -x) < 1e-5'. The error returned was 'Evaluation of method System.Math.Abs() calls into native method System.AppDomain.GetId(). Evaluation of native methods in this context is not supported.'. How does it only work some of the time? Is there runtime trickery happening where the conditional breakpoint code isn't the same each time I run it? If there was, why on earth would any version of the code for Abs()