.net - How can a C# program use a COM dll of any version? -


this question sequel of this question

we're creating dll, written in c++, providing access hardware. dll implements , accessed using com interfaces. have c# program uses dll through com objects.

we're having issue versions. indeed, when running c# program, absolutely wants use exact com/c++ dll version used when compiling. i.e. if c# program compiled using com/c++ dll 1.2.3.4, program refuse run com/c++ dll 1.2.3.5.

unhandled exception: system.typeinitializationexception: type initializer 'mydllverify.app' threw exception. ---> system.io.filenotfoundexception: not load file or assembly 'mycorp.mydll.interop, version=1.2.3.4, culture =neutral, publickeytoken=ced78d295d1e0f2b' or 1 of dependencies. system cannot find file specified. file name: 'mycorp.mydll.interop, version=1.2.3.4, culture=neutral, publickey token=ced78d295d1e0f2b'   @ mydllverify.app..cctor() 

i'd instruct c# program use com/c++ dll version 1.2.anything.

where can configure in c# project?

i suggest not directly reference com-dll in c# project. if that, @ build time there new com-interop-dll generated. can lead lot of problems.

it better approach create com-interop-dll, store in library folder , reference library in c# project. keep com-interop-dll static possible. if that, can replace used com-dll as want, long interfaces not change.

you try manipulate interop assembly , make version checking 1.2.* there, if realy want (i not recommend that, cause serious confusion).

explanation: com-interop-dll regular .net assembly. works wrapper between c# code , com-c++-code want use in c# code.

the com-interop-dll don't have registered com. can install assembly many times like. requires com-dll registered com.

useful tools:

  • tlbimp
  • regasm
  • sn

Comments