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; ...
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; ...
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...
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...
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 ...
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). ...
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...
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 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 ...
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? ...
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...
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...
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 ...
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? ...
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 ...
How to call managed c# functions from unmanaged c++ ...
.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...
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...
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...
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...
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...