clr

How does the CLR know the type of a boxed object?

When a value type is boxed, it is placed inside an untyped reference object. So what causes the invalid cast exception here? long l = 1; object obj = (object)l; double d = (double)obj; ...

Reflecting over classes in .NET produces methods only differing by a modifier

I'm a bit boggled by something, I hope the CLR gearheads can help. Apparently my gears aren't big enough. I have a reflector utility that generates assembly stubs for Cola for .NET, and I find classes have methods that only differ by a modifier, such as virtual. Example below, from Oracle.DataAccess.dll, method GetType(): class OracleT...

Criteria for triggering garbage collection in .Net

I've come across some curious behavior with regard to garbage collection in .Net. The following program will throw an OutOfMemoryException very quickly (after less than a second on a 32-bit, 2GB machine). The Foo finalizer is never called. class Foo { Guid guid = Guid.NewGuid(); byte[] buffer = new byte[1000000]; static Ra...

How does the Garbage Collector decide when to kill objects held by WeakReferences?

I have an object, which I believe is held only by a WeakReference. I've traced its reference holders using SOS and SOSEX, and both confirm that this is the case (I'm not an SOS expert, so I could be wrong on this point). The standard explanation of WeakReferences is that the GC ignores them when doing its sweeps. Nonetheless, my object ...

Oracle Data Provider to CLR type mapping

Where can I find the listing of ODP to CLR type mapping? On Oracle database, the NUMBER(9,0) type comes out in .NET app as System.Decimal from the MS Oracle driver, but as System.Int32 from ODP driver. I need an exact specification of types coming out from database (not the CLR to DB parameter mapping). ...

Why "Finalize method should not reference any other objects" ?

I have been pondering why it is recommended that we should not release managed resources inside finalize. If you see the code example at http://msdn.microsoft.com/en-us/library/system.gc.suppressfinalize.aspx , and search for string "Dispose(bool disposing) executes in two distinct scenarios" and read that comment, you will understand w...

variable scope in statement blocks

for (int i = 0; i < 10; i++) { Foo(); } int i = 10; // error, 'i' already exists ---------------------------------------- for (int i = 0; i < 10; i++) { Foo(); } i = 10; // error, 'i' doesn't exist By my understanding of scope, the first example should be fine. The fact neither of them are allowed seems even more odd. Sur...

System.Reflection - Global methods aren't available for reflection

System.Reflection does not (AFAIK) support reflecting on global methods in an assembly. At the assembly level, I must start with the root types. My compiler can produce assemblies with global methods, and my standard bootstrap lib is a dll that includes some global methods. My compiler uses System.Reflection to import assembly metadata ...

What is SyncBlockIndex and what is it used in .NET for?

Hi Guys I'm trying to gain deeper understanding of the way CLR works and can't find a good determination of "SyncBlockIndex". I've found out that each managed object has it, but what is it? What is it used for? ...

Overlaying several CLR reference fields with each other in explicit struct?

Edit: I'm well aware of that this works very well with value types, my specific question is about using this for reference types. Edit2: I'm also aware that you can't overlay reference types and value types in a struct, this is just for the case of overlaying several reference type fields with each other. I've been tinkering around wit...

code access security

Why do I need to Demand permission? Why can't it simply fail (commenting out the .Demand() call)? ref: http://support.microsoft.com/kb/315529 Thanks! try { // Demand the permission to access the C:\Temp folder. permFileIO.Demand(); resultText.Append("The demand for permission to access the C:\\Temp folder succeeded.\n\n"); } -- edi...

String interning?

The second ReferenceEquals call returns false. Why isn't the string in s4 interned? string s1 = "tom"; string s2 = "tom"; Console.Write(object.ReferenceEquals(s2, s1)); //true string s3 = "tom"; string s4 = "to"; s4 += "m"; Console.Write(object.ReferenceEquals(s3, s4)); //false --edit-- To add to the question, this discussion is ...

Can a .NET app that was built against 1.1 be guaranteed to run on any machine with newer versions of .NET?

My new Windows 7 machine for instance doesn't appear to have a .NET installation folder with 1.1 assemblies. Will an app built and targeting 1.1 run without modify this machine with an older distribution of .NET? ...

How do I select the right version of the CLR in VS2010?

hi all At the time of creating the new project, i not able to session entry for previous version of .net framework in the drop drown box it should only .net Framework 4 and hyper link for more framework.Even those i have .net 2.0 ,3.0 and 3.5. Can anyone suggest me what can be done? Thanks and Regards Sameer ahmed.s ...

calling managed c# functions from unmanaged c++

How to call managed c# functions from unmanaged c++ ...

Is MarshalByRefObject special?

.NET has a thing called remoting where you can pass objects around between separate appdomains or even physical machines. I don't fully understand how the magic is done, hence this question. In remoting there are two base ways of passing objects around - either they can be serialized (converted to a bunch of bytes and the rebuilt at the...

Best way to prevent early garbage collection in CLR

Hello, I have written a managed class that wraps around an unmanaged C++ object, but I found that - when using it in C# - the GC kicks in early while I'm executing a method on the object. I have read up on garbage collection and how to prevent it from happening early. One way is to use a "using" statement to control when the object is d...

.NET 4.0 application on network share causes SecurityException

Today I experienced a weird problem while trying to remotely debug an application built for the .NET 4.0 runtime. The application resides on a network share and executed by a remote machine. However the application crashes each time during load because of a SecurityException raised by a permission demand in the System.Configuration.Conf...

Can I safely move my project to .NET 4.0?

I've migrated my project to VS2010 but have not yet targeted .NET 4.0. It's currently targeting 3.5 SP1 (and CLR 2). The project relies on several third party components -- mostly open source -- that were presumably built against the 2.0 CLR. Can I simply retarget my project to the 4.0 runtime? Or do I have to get new versions of all...

Friend Assemblies in C#

I'm trying to create some 'friend assemblies' using the [InternalsVisibleTo()] attribute, but I can't seem to get it working. I've followed Microsoft's instructions for creating signed friend assemblies and I can't see where I'm going wrong. So I'll detail my steps here and hopefully someone can spot my deliberate mistake...? Create a s...