You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NET5ClassLibraryInterface - .NET 5.0.6 class library with net5.0-windows TFM. Refefences latest Unity.Container 5.11.11 and Unity.Configuration 5.11.2 nuget packages. Contains IDataCreate interface and a static class that calls functions from that interface (uses container.Resolve<IDataCreate>()). Compiled as x86. Also contains App.config:
NET5ClassLibraryImplementation (references NET5ClassLibraryInterface) - .NET 5.0.6 class library with net5.0-windows TFM - contains DataCreate class that implements IDataCreate interface. Compiled as x86.
NET5ClassLibraryTest (references NET5ClassLibraryInterface) - .NET 5.0.6 console application with net5.0-windows TFM - calls functions from NET5ClassLibraryInterface static class. Compiled as x86. Works with no problem!!!.
NET5ClassLibraryInterop (references NET5ClassLibraryInterface) - .NET 5.0.6 C++\CLI wrapper. Compiled as x86, Multi-byte Character Set, wchar_t-.
NET5ClassLibraryInteropTest - C++ console test application. Compiled as x86, Multi-byte Character Set, wchar_t-.
When I run NET5ClassLibraryInteropTest line var dataGreate = container.Resolve<IDataCreate>(); throws an exception:
System.TypeInitializationException: ''The type initializer for 'NET5ClassLibraryInterface.Class1' threw an exception.'
Inner exception: 'InvalidCastException: Unable to cast object of type 'NET5ClassLibraryImplementation.DataCreate' to type 'NET5ClassLibraryInterface.IDataCreate'.'
I've investigated the problem deeper and found out that if I manually add the following line to NET5ClassLibraryInterop.vcxproj:
the problem transforms. Line var section = c.GetSection("unity") as UnityConfigurationSection now returns section = null despite of the fact that c.GetSection("unity") is exactly {Microsoft.Practices.Unity.Configuration.UnityConfigurationSection}:
Sample repo -https://github.com/bairog/NET5ClassLibraryWithUnityInteropTest
Compile it (for some reason you need to compile twice for compiling NET5ClassLibraryInteropTest project) and start debugging NET5ClassLibraryInterop project (it starts NET5ClassLibraryInteropTest in project Debug settings)
Version information
Target framework: .NET 5.0.6
Operating system: Windows 10 x64 1909
IDE: Visual Studio 2019 16.10.0 REL Community
The text was updated successfully, but these errors were encountered:
I have a solution with the following structure:
IDataCreate
interface and a static class that calls functions from that interface (usescontainer.Resolve<IDataCreate>()
). Compiled as x86. Also contains App.config:DataCreate
class that implementsIDataCreate
interface. Compiled as x86.When I run NET5ClassLibraryInteropTest line
var dataGreate = container.Resolve<IDataCreate>();
throws an exception:I've investigated the problem deeper and found out that if I manually add the following line to NET5ClassLibraryInterop.vcxproj:
the problem transforms. Line
![image](https://user-images.githubusercontent.com/44995181/121294237-b5594000-c8f5-11eb-8be6-952027554937.png)
![image](https://user-images.githubusercontent.com/44995181/121294272-c609b600-c8f5-11eb-8161-3e55c9a70e35.png)
var section = c.GetSection("unity") as UnityConfigurationSection
now returnssection = null
despite of the fact thatc.GetSection("unity")
is exactly{Microsoft.Practices.Unity.Configuration.UnityConfigurationSection}
:Sample repo -https://github.com/bairog/NET5ClassLibraryWithUnityInteropTest
Compile it (for some reason you need to compile twice for compiling NET5ClassLibraryInteropTest project) and start debugging NET5ClassLibraryInterop project (it starts NET5ClassLibraryInteropTest in project Debug settings)
Version information
Target framework: .NET 5.0.6
Operating system: Windows 10 x64 1909
IDE: Visual Studio 2019 16.10.0 REL Community
The text was updated successfully, but these errors were encountered: