AppDomain CreateInstanceAndUnwrap w/ Visual Studio 2008
I recently converted a project form Visual Studio 2005 to Visual Studio 2008 RTM. I am using AppDomain.CurrentDomain.CreateInstanceAndUnwrap to dynamically create an instance similar to the following
string assembly = "Test.dll";
string type = "Test.MyClass";
MyClass obj = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(assembly, type) as MyClass;
This worked fine in 2005 but gets an exception in 2008 - "could not load file or assembly or one of it's dependancies". Looking at the fusion log, which is now in the exception info window in Studio (very nice), I could see that it was looking for Test.dll.dll, Test.dll.exe. So, the extension is being appended to the end of the assembly name. After removing ".dll" from the name of the assembly, the code works fine.
string assembly = "Test.dll";
string type = "Test.MyClass";
MyClass obj = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(assembly, type) as MyClass;
This worked fine in 2005 but gets an exception in 2008 - "could not load file or assembly or one of it's dependancies". Looking at the fusion log, which is now in the exception info window in Studio (very nice), I could see that it was looking for Test.dll.dll, Test.dll.exe. So, the extension is being appended to the end of the assembly name. After removing ".dll" from the name of the assembly, the code works fine.
4 Comments:
If you add "dll",you should use "CreateInstanceFromAndUnwrap",
or else you use "CreateInstanceAndUnwrap" without a "dll".
Thanks. I didn't even try that one...good to know.
Then changed the base directory for the AppDomain used by the test runner from the location of the test assemblies in VS 2005 to the IDE's folder in VS 2008, so the test assemblies can't be resolved as they used to. Using CreateInstanceFromAndUnwrap does the trick indeed.
Great tool, thank you! Can I use it to parse my dll files http://fix4dll.com/msvcp120_dll from the dynamic library? It would be cool!
Post a Comment
Subscribe to Post Comments [Atom]
<< Home