unitycontainer / configuration

Unity.Configuration package
Apache License 2.0
13 stars 13 forks source link

Problems when when using Unity.Container and Unity.Configuration in .NET 5.0.6 class library via C++\CLI wrapper #37

Open bairog opened 3 years ago

bairog commented 3 years ago

I have a solution with the following structure:

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:

<ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
</ItemGroup>

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}: image image

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

Sfairait commented 3 years ago

I'm encountering the same issue. Looking forward to get the solution.

ENikS commented 3 years ago

The development and support for this project is on pause until financial situation is improved https://github.com/unitycontainer/unity/discussions/368