I would like to view the instance address on a .net application developed on C# programming language. For a value type instance (unboxed) I can see its address using the follow statement:
fixed( void* p = &pt){Console.WriteLine(“Address: {0}”, (IntPtr) p));}
(Consider pt a value type variable)
However for a reference type instance I can’t apply the same solution in C#. Using C++ programming language it’s easy, so I developed a new component with that functionality, called AddrInspector. To use that component in C#, I had to compile AddrInspector for a managed environment using /clr option on C++ compiler.
This way I get a solution to see the address of any instance, but when I run my application and AddrInspector, I get the follow exception:
Unhandled Exception: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
“module could not be found...” Ok, it seems like something is missing. Looking for a solution on Web I get this link http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx:
<<
C Run-Time Libraries
This topic discusses the various .lib files that comprise the C run-time libraries as well as their associated compiler options and preprocessor directives. …
>>
Some lines bellow I can read that /clr option on C++ compiler will require msvcm80.dll. This scenario applies when “Used for mixed managed/native code”. Ok, that’s right.
After confirming that dll doesn’t exist on my machine, I start looking where I can get it! So, I find this nice link saying:
<<
Microsoft Visual C++ 2005 Redistributable Package (x86)
The Microsoft Visual C++ 2005 Redistributable Package (x86) installs runtime components of Visual C++ Libraries required to run applications developed with Visual C++ …
>>
The scope is fine and it’s referred on many sites as the solution for this problem. But the reality is different. The installation process doesn’t work very well and block the msci.exe process.
It could be just a problem of my machine, but the behavior was the same when I try it on a colleague’s machine.
Without setup I have to used the old fashion way. I get the DLL on VS2005 DVDs. After copy it I used the traditional regsrv32 to registry the DLL. This time I get the error: “Registering DLL failed, No entry point found”. Second try: I put the DLLs on well known PATH. But it doesn’t work too.
Ok, let’s start from the beginning. I ran Orcas (beta version of Visual Studio 2008) setup again and try to find if something is missing. That’s everything installed, including the C++ Run-Time Libraries. So what the hell is missing?
So, I start looking again for all DLLs on Orcas destination folder and this time something calls my attention. Why two folders:
- C:\Program Files\Microsoft Visual Studio 8\VC\
- C:\Program Files\Microsoft Visual Studio 9.0\VC\
On VS2005 there was just the first one. Probably the 9.0 is related with the new version VS2008/Orcas? And probably the msvcm80.dll now is called msvcm90.dll. Gotcha, there it is the msvcm90.dll on:
C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT
Ok, let’s try to registry this one with regsrv32. Bah, the same error again: “Registering DLL failed, No entry point found”.
2nd try, let’s copy it to a well known PATH. YES, this time the application and AddrInspector works as expected. Is just lost a complete afternoon.