A Tool (attached) to help figure out how to emit a type

After being in Exchange for almost a year, I tend to forget the how to run Reflection.Emit that I was once so familiared with.  Occasionally, I would receive emails from this blog asking how to emit this, how to emit that. Before, the solutions came directly from my memory, but now I need some help. The way for me to…


I am moving onto Exchange Team

I am going to program in the Server world using managed code! Maybe after some time, I will start a new blog for IT professionals about Clustering in Exchange. But currently this blog is not likely to have new contents about the most updated CLR technology. Thanks. Yiru


Sample Code to invoke managed code inside profiling API

ProfilerCallback.cpp // This is the function that will invoke the managed code through COM interop on another thread // this function creates the CCW object // [in] this pointerDWORD WINAPI CreateManagedStub(LPVOID lpParam){    _ManagedStub * pIManagedStub = NULL;    HRESULT hr = CoCreateInstance(CLSID_ManagedStub, NULL, CLSCTX_INPROC_SERVER, IID__ManagedStub, (void **)&pIManagedStub);     if (FAILED(hr))    {        printf(“Fail to CoCreateInstance on ManagedStub class 0x%x\n”, hr);       …


CLR Profiling API

I think CLR Profiling API is one of the coolest things in CLR. Here is a nice article I just found on msdn about Whidbey Profiling APIs. Note that Everett Profiling API and Whidbey Profiling API are completely not compatible. You have to explicitly implement ICorProfilerCallback2 interface to make profiling work on Whidbey. Profiling provides…


Something about ReflectionOnly Context

I was reading Joel’s blog about new stuff in Reflection and he mentioned ReflectionOnly context. Apart from the Generics, token handle resolutions, LCG, ReflectionOnly context (actually a loader feature) had a big impact in Reflection area in Whidbey. It reminds me to talk about ReflectionOnly context thing in detail in my blog. ReflectionOnly context is first of…


GetMethod limitation regarding Generics

I’ve got several inquiry emails about this issue, so I think it is a good idea to publish the problem here. Say we have: public class Test {   public void Teste<U>(U teste, int i) { Console.WriteLine(teste); }    public void Teste<U> (U teste) { } } Is it possible to use GetMethod to get void Teste<U>(U teste,…


HaiboLuo’s blog

Our Reflection QA definitely knows a lot and he is now having a blog of his own: http://blogs.msdn.com/haibo_luo A little advertisement, I know he is going to have something cool coming up soon. Just keep an eye on it.      


Reflection.Emit is not ThreadSafe

Users are not supposed to operate on same Reflection.Emit object on multiple threads. Reflection.Emit Objects are *NOT* thread-safe. It is certainly OK to operate on different Reflection.Emit objects on different threads. We have been discovering issues when users trying to do the first scenario and we are trying hard to make the program not to crash. 🙂 But…


Unexpected TypeLoadException during Type Creation

We have found some limitations in Reflection.Emit that you cannot emit types that can be compiled in C# compiler. You are unlikely to hit it in daily emit job but if ever you met one: public class E{    public struct N1    {         public E e;    }     public struct N2    {         public N1 n1;   …


Token Handle Resolution with Generics

In Whidbey, apart from the token handle resolution APIs I mentioned earlier, there are some overloads making these APIs look a bit more complicated. Again, I am using APIs related to MethodInfo as an representitive example: Token -> Info public class Module {           public MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) } Handle->Info  public class…