简体   繁体   中英

How to build and configure .net assembly so it ignores version of referenced DLL at runtime?

I am building a DLL in C# that references another DLL. I don't want the DLL that I am building to care about which version of the referenced DLL is on the customer's computer at runtime (note: I do not ship the referenced DLL to them, only the one that I build). It turns out that they have a newer version of the referenced DLL on their machine and when they tried to execute the code in my DLL they got the following error:

Exception calling ".ctor" with "0" argument(s): "Could not loadfile or assembly ', Version=, Culture=neutral

In case it helps to know, the Specific Version property on the referenced DLL is set to False in my Visual Studio. How can I build my DLLs so that it won't complain about the version of the referenced DLL that the customer has deployed on their machine?

When you build an assembly the dll version of referenced assembly is written into your assembly. Generally, and without any configuration, it will have no troubles if you replace originally referenced assembly with the one of higher version, where only first 3 numbers matter. 1.1.1.x - x doesn't matter. And as long as "replacement assembly" contains API that your code may call. It seems that you have exactly that issue - a different constructor in the version you using that wasn't present in original assembly.

For making your assembly work with various versions of referenced dlls you can try to tweak app.config to set version range for this dll. Read about redirecting assembly version .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM