I'm porting a .Net framework projet to .Net 5. This project uses an external library which seems to be compiled against .Net Framework 2 (I see mscorlib 2.0 in the references in dotPeek). I don't have the sources of this dll, and rewriting it from scratch is not possible.
I've seen here that .Net core offers some compatibility shims, and if the apis are covered, it may load alright.
I have loaded the assembly in the .Net Portability Analyzer which gives me these results
.NET,Version=v5.0 | .NET Core,Version=v3.1 | .NET Standard + Platform Extensions,Version=v2.0 | .NET Standard,Version=v2.1 |
---|---|---|---|
100 | 100 | 62.5 | 100 |
In the details section I can see the missing target members for the .Net standard 2.0 and that everything is supported for the other platforms.
Target member | .NET,Version=v5.0 | .NET Core,Version=v3.1 | .NET Standard + Platform Extensions,Version=v2.0 | .NET Standard,Version=v2.1 | Recommended changes |
---|---|---|---|---|---|
T:System.Runtime.InteropServices.TypeLibTypeAttribute | Supported: 5.0+ | Supported: 2.0+ | Not supported | Supported: 2.1+ | |
M:System.Runtime.InteropServices.TypeLibTypeAttribute.#ctor(System.Int16) | Supported: 5.0+ | Supported: 2.0+ | Not supported | Supported: 2.1+ | |
T:System.Runtime.InteropServices.ImportedFromTypeLibAttribute | Supported: 5.0+ | Supported: 2.0+ | Not supported | Supported: 2.1+ | Remove usage. |
M:System.Runtime.InteropServices.ImportedFromTypeLibAttribute.#ctor(System.String) | Supported: 5.0+ | Supported: 2.0+ | Not supported | Supported: 2.1+ | Remove usage. |
T:System.Runtime.InteropServices.TypeLibVersionAttribute | Supported: 5.0+ | Supported: 2.0+ | Not supported | Supported: 2.1+ | |
M:System.Runtime.InteropServices.TypeLibVersionAttribute.#ctor(System.Int32,System.Int32) | Supported: 5.0+ | Supported: 2.0+ | Not supported | Supported: 2.1+ |
If I interpret this correctly, my dll should run fine in my .Net 5 project. I have copied my dll in the project directory, set it to copy to the output directory and added it in the references.
Now when the code runs, I get an exception :
Retrieving the COM class factory for component with CLSID {51A3A6E0-1414-11D7-BD2E-08004608C318} failed due to the following error: 80040154 Classe non enregistrée (0x80040154 (REGDB_E_CLASSNOTREG)).
After more searches I set the target platform to x86 instead of Any CPU, but the exception remains.
Do you have any ideas to make this work ?