Use Old .net dll inside Modern .net application

0

I have a .net dll file called PcapNet.dll this file is a wrapper around C++ WanPacket.dll library.

But PcapNet.dll built with .net3.5, every time I reference it in modern .net application eg, .net 4.7

Shows me this message:

System.IO.FileLoadException: 'Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.'

Then I added

<supportedRuntime version="v2.0" sku=".NETFramework,Version=v2.0"/>

to App.config.

And This shows me the next message:

System.IO.FileLoadException: 'Could not load file or assembly 'PcapNet.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)'

Then I Changed TargetFrameWork to 3.5. And Now Everything worked correctly. And I Can use it.

But this is a big problem I can not stick with .net 3.5 I need 4.7 because I will use it in wpf application.

So how can i use this legacy library 3.5 with modern .net 4.7.

Notice: I do not have the source code of this library, I can only access the dll.

c#
.net
.net-assembly
asked on Stack Overflow Feb 18, 2020 by Al Banna Techno logy • edited Feb 18, 2020 by Uwe Keim

1 Answer

0

Using

<startup useLegacyV2RuntimeActivationPolicy="true">

Solved The Problem.


User contributions licensed under CC BY-SA 3.0