Hi, there
I've written a small application implementing the idea of dynamic loading and demonstrating the issue. Here is the link: https://www.dropbox.com/s/8nhftd9cy7rhv31/Loader.7z?dl=0
the application provided with binaries, so I hope all you need is open VS and start debugging
The expected behavior is being able to load ClientConfigSection from config.
What get is an exception notifying that ConfigurationManager assembly cannot be loaded although ConfigurationManager assembly already successfully loaded to context. The exception happens in Application.cs:29 - method 'Run'
What extra information should I provide?
Is this an issue in .netcore code or an issue in my understanding of how it should work?
UPD:
Envirounment info
.NET Core SDK (reflecting any global.json):
Version: 2.2.202
Commit: 8a7ff6789d
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.202\
Host (useful for support):
Version: 2.2.3
Commit: 6b8ad509b6
hi, there.
I assume that this happens because of magic in ConfigurationManager.TypeUtls.GetImplicitType. Not really sure yet what it does, but seems like something is wrong there
best,
ilya
@sdmaclea after that comment https://github.com/dotnet/coreclr/issues/23757#issuecomment-489261268 I've tried to upgrade my very simple application to netcore 3 preview 5. I also upgraded all the dependencies to last previews.
In result, I get an exception that assembly System.Configuration.ConfigurationManager, version 4.0.2.0 can not be loaded.
here is log entry from resolver:
2019-05-17 11:23:14,088 [1] INFO Loader.Program - Resolving of assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51', requesting assembly:C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.0.0-preview5-27626-15\System.dll, LoadContext:"Default" System.Runtime.Loader.DefaultAssemblyLoadContext #0
New System.dll requests some stuff which I do not have locally
best,
ilya
guys, I managed to resolve my issue by updating .dll.config file.
types description were referring types from assembly System, Version=2.0.0.0 or 4.0.0.0. If I replace this part by System.Configuration.ConfigurationManager, then it works as expected.
Sorry for confusion
best,
ilya
Hi @shvez ,
How exactly did you solve this? (I can't download your app any more)
The reason is because I'm having the same problem. I updated to .Net Core 3.1 today, coming from 2.2, and a program that was working fine is now failing.
The program uses a DLL, let's call it general.dll. This DLL uses System.Configuration.Configuration manager to read settings. The DLL is built in .Net 4.7 (it's shared among core and .net framework projects)
This DLL is installed via NuGet package, everything compiles and runs properly when the application is compiled with netcoreapp2.2. But if I switch the project to netcoreapp3.1, it fails.
Specifically:
Unhandled exception. System.TypeInitializationException: The type initializer for 'SomeClass' threw an exception.
---> System.IO.FileLoadException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
I also found in Stackoverflow someone else having similar issue:
https://stackoverflow.com/questions/57324985/configurationmanager-in-a-net-core-application
cc @ericstj anything come immediately to mind that could have caused this regression?
@ngcdev I'm not able to answer today. In short I set correct version of system assembly in assembly.config file. It was 2.0.0, I set 4.0.2 or something like that.
But I'm affraid it was working with netcore2.1. Netcore3 was not released yet.
This could happen if you have a desktop library as you said, since the compatibility shims for System.dll that ship in .NETCore's shared framework will reference the version of the libraries (even those in the compat pack) that we build at the same time as the rest of the product.
To fix this, update your PackageReference of System.Configuration.ConfigurationManager to the latest version (4.7.0).
I'll give it a try and report back. Thanks
Before I tried to update to 4.7, I noticed (in VS) that when the package System.Configuration.ConfigurationManager gets added, a reference to assembly System.Configuration.dll is also added to the project (which is not part of the package). So that got me thinking, this is something the package assumes the runtime will have.
So I did a quick search for the files and I found it under NuGetFallbackFolder for my older SDKs, but not for 3.x:
ngcdev@sirius:/usr/share/dotnet/sdk$ ls
2.1.105 2.1.802 2.2.402 3.0.101 3.1.100 NuGetFallbackFolder
ngcdev@sirius:/usr/share/dotnet/sdk$ find . -iname "System.Configuration.*"
./NuGetFallbackFolder/microsoft.netcore.app/2.1.1/ref/netcoreapp2.1/System.Configuration.dll
./NuGetFallbackFolder/microsoft.netcore.app/2.0.6/ref/netcoreapp2.0/System.Configuration.dll
./NuGetFallbackFolder/microsoft.netcore.app/2.1.0/ref/netcoreapp2.1/System.Configuration.dll
./NuGetFallbackFolder/microsoft.netcore.app/2.0.0/ref/netcoreapp2.0/System.Configuration.dll
./NuGetFallbackFolder/microsoft.netcore.app/2.2.0/ref/netcoreapp2.2/System.Configuration.dll
ngcdev@sirius:/usr/share/dotnet/sdk$
Could it be that 3.x does not include this fallback file?
System.Configuration.dll is part of the shared framework, that's the compatibility shim I referred to in https://github.com/dotnet/runtime/issues/627#issuecomment-562655611. I mentioned System.dll but there is also System.Configuration.dll, mscorlib.dll, System.Xml.dll, etc.
The reason you don't see this in that folder is that we changed the way we ship the reference assemblies (and runtime packs) in 3.0. We still have that file and the problem is that it will reference the version of System.Configuration.ConfigurationManager.dll that we shipped with 3.1, so you need to update the package that brings that file into your application.
OK after updating the .Net 4.7 library to use System.Configuration.ConfigurationManager 4.7, now .Net Core 3.1 application is working. So I don't think there's an issue any more.
OK, I'll close this again. Thanks @ngcdev for the update.
the issue is still here even with .net 3.1 and the nuget package with the System.Configuration.ConfigurationManager 4.7 version
Most helpful comment
the issue is still here even with .net 3.1 and the nuget package with the System.Configuration.ConfigurationManager 4.7 version