clr

Why would System.Type.GetType(“Xyz”) return null if typeof(Xyz) exists?

落花浮王杯 提交于 2019-11-30 06:45:47
I have come across a strange behaviour in my (huge) .NET 4 project. At some point in the code, I am referring to a fully qualified type, say: System.Type type = typeof (Foo.Bar.Xyz); later on, I do this: System.Type type = System.Type.GetType ("Foo.Bar.Xyz"); and I get back null . I cannot make sense of why this is happening, because my type name is correct, and I have checked with other types and they get resolved properly. Moreover, the following LINQ query finds the type: var types = from assembly in System.AppDomain.CurrentDomain.GetAssemblies () from assemblyType in assembly.GetTypes ()

“Object has been disconnected or does not exist at the server” exception

試著忘記壹切 提交于 2019-11-30 05:50:27
问题 I need to use cross-appdomain calls in my app, and sometimes I have this RemotingException: Object '/2fa53226_da41_42ba_b185_ec7d9c454712/ygiw+xfegmkhdinj7g2kpkhc_7.rem' has been disconnected or does not exist at the server. The target object is still alive, I have checked it. UPD I've set breakpoint in the finalizer of the target object, and it never hits. Thus, this object is alive and wasn't GC'ed. 回答1: That is probably because the local garbage collector at the server side collects the

Relation between System.Object class and Structs

心不动则不痛 提交于 2019-11-30 05:43:34
问题 I know that my question seems dumb but I am confused. I appreciate if someone clarify this for me. I know that structs, e.g. Int32, are value types and are instantiated on stack while classes are reference types and are instantiated on heap. I also know that all the structs are derived from System.Object type, which is a class. I wonder how this is possible that the supertype, System.Object, is a reference type and the subtype, Int32, is a value type? Where should I look to understand how

A way How to Compile C library into .Net dll?

社会主义新天地 提交于 2019-11-30 05:42:37
问题 Can we compile C library as .Net dll (containing and opening access to all C libs functions) by just compiling cpp project containing code like extern "C" { #include <library.h> } with /clr:pure argument with VS? (VS10) Or we should do something more trickey? 回答1: I found it is the best to use the old style Managed C++ for this. CLR:PURE just wont cut it. Example: extern "C" int _foo(int bar) { return bar; } namespace Bar { public __gc class Foo { public: Foo() {} static int foo(int bar) {

What is the (fnptr)* type and how to create it?

99封情书 提交于 2019-11-30 05:16:22
The following IL code creates a Type instance named (fnptr)* (token 0x2000000 - invalid, module mscorlib.dll). ldtoken method void* ()* call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle) What's the purpose of this type? Is it possible to create this type instance in C# without writing any IL code, maybe with reflection? Module.ResolveType on the token throws ArgumentOutOfRangeException . Edit: It's clear the (fnptr) type is an internal CLR type representation of an IL method pointer type, though when removing the last * , it

Number of CLR and GC instances running on a machine?

旧城冷巷雨未停 提交于 2019-11-30 05:08:31
I create 2 .NET applications and run them on a machine - how many CLR's and gc's will be there? In addition: I would like to have some background information on how Windows handles COM components and CLR in particular. Hope someone could detail down to how CLR loads in memory and what it means if I get multiple CLR instances listed on running this command: tasklist /m mscor* Is it multiple CLRs actually or a single CLR as a COM server for all .NET processes? Each process will have its own copy of the CLR as a hosting process. However, since the CLR is really just a couple of DLLs Windows will

Strange casting behaviour. Cannot cast object (int) to long

房东的猫 提交于 2019-11-30 04:39:18
I have the following code: int intNumber1 = 100; object intNumber2 = 100; bool areNumberOfTheSameType = intNumber1.GetType() == intNumber2.GetType(); // TRUE bool areEqual = intNumber1.Equals(intNumber2); // TRUE long longNumber1 = (long) intNumber1; // OK long longNumber2 = (long) intNumber2; // InvalidCastException. Why? Why doesn't the second cast work? I realize that it might be because the object doesn’t have an explicit cast to a long, but if we look at its type on runtime it is System.Int32 . If I use var or dynamic instead of object , it works. Any thoughts? svick Cast from int to long

Switching off the .net JIT compiler optimisations

那年仲夏 提交于 2019-11-30 04:02:13
When we remote a method (that is using generics) the remoting sink cannot seem to discover our method from the other identical named ones. Debugging with .net source code attached I've got it to where there is a MethodInfo.MakeGenericMethod call. However I cannot look at any of the surrounding data as its been jit optimised. I couple of weeks ago I came across a registry setting that would disable this setting (it specifically mentioned that it aid debugging with the source). However being a wally I've lost what I did with it and am having trouble finding it again. I don't know about a

Interpreting JavaScript outside of the browser?

醉酒当歌 提交于 2019-11-30 03:56:24
This is more out of curiosity that a real requirement, but I'm wondering if it's possible to treat JavaScript as (ideally) a first-class .NET citizen, or (secondarily) have some way of invoking/interpreting pure JavaScript functions (that don't require the DOM) in a desktop setting? Has anyone ever attempted implementing a CLR version of JavaScript? Something tugs at the back of my mind concerning this, but now that I think about it it was probably PHP, not JavaScript. For your second option, there's Rhino and things like it . Using the DLR (Dynamic Language Runtime) you can use Managed

Why GetHashCode is in Object class?

落花浮王杯 提交于 2019-11-30 03:46:54
问题 Why GetHashCode is part of the Object class? Only small part of the objects of the classes are used as keys in hash tables. Wouldn't it be better to have a separate interface which must be implemented when we want objects of the class to serve as keys in hash table. There must be a reason that MS team decided to include this method in Object class and thus make it available "everywhere". 回答1: It was a design mistake copied from Java, IMO. In my perfect world: ToString would be renamed