Reputation: 123
How can I dynamically load a DLL?
Please don't suggest:
Assembly.LoadFrom(...)
since this functionality works at debugging not outside the project.If I copy that DLL/exe onto a test machine outside the project then it shows an error: could not load .dll.
I also asked a question at the MSDN forums.
Could anyone help me?
Thanks
Ashish
Upvotes: 0
Views: 207
Reputation: 123
1) Try using assembly.loadfile function instead of loadfrom. It will work outside the project also. 2) If u got assembly mixed mode error then, just need to copy xml file along with dll generated in bin folder.xml file contains app.config file data. Code in app.config file is...
also check link... http://social.msdn.microsoft.com/Forums/en/csharpide/thread/99691cc4-27df-48e7-b4aa-377f74109425
Upvotes: 0
Reputation: 9660
System.Reflection.Assembly.LoadFile()
works just fine for this.
If you are getting BadImageFormatException
, check whether the assembly you are trying to load is compiled for the same platform target (x86 or x64) as the assembly doing the loading.
Update based on comments
Sounds like you are trying to load a .NET 2.0 assembly into a .NET 4.0 application, and you have already put the following in your application configuration file:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
In that case, check to make sure your configuration file is getting deployed on your target machine alongside your executable. For example, if your application is called MyProgram.exe
, your configuration file should be called MyProgram.exe.config
- and it needs to be copied to the same folder as the executable on your target machine to have any effect - the framework will load this file when it starts up, if it exists.
Upvotes: 2