I have a .net core console app and I’ve added the nuget System.Configuration.ConfigurationManager.
At runtime I get
Unhandled exception. System.BadImageFormatException: Could not load file or assembly ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
File name: ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ —> System.BadImageFormatException: Cannot load a reference assembly for execution.
at ConsoleApplication6.Program.Main(String[] args)
I recall we saw this before with .net framework, I think the deps.json file from ebuild is wrong.
Curious. I’ve had to tweak the ref vs lib thing several times now, because of inconsistencies. I’ll need to have a look at the concrete case, but unfortunately I’m out of the office most of the day today; I’ll check tomorrow. whats the exact versions of .NET Core you’re building with?
As a side note, \ vs / seems wrong too; will fix that as well.
To be clear, everything is fine for what is copy-located (System.Configuration.ConfigurationManager.dll is not copied next to the exe), the only issue is what’s in the .deps, correct?
Because the current logic is (and changing intact is gonna break the 387 other issues we had with whit before) is that if a package resolves to not the exact target framework type (eg (. NET or .NET Core) but a common one (eg “.NET Standard”), we don’t copy-local or otherwise process the lib folder, and just use ref.
system.security.permissions resolves to a .NET Core 3.0 version for lib and ref, so we copy-local it; but system.configuration.configurationmanager resolves to a. .NET Standard 2.0 one for ref and lib, so we ignore lib.
Changing that is gonna break whatever scenario I fixed for you 3 months ago.
I really wish there was any, you know, documentation or something silly like that, on how all this was supposed to be handled… :(.
I was under the impression that should never copy local a ref or have it in the deps.json. ie only lib files are copied local or in the deps.json ? The ref is only for use in a build ?
Yes. That’s the fix I made. Sonde this is not copylocal (references from “ref” and the platform is not an exact match for “lib” – standard vs core), I’m not adding it to the deps.
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The system cannot find the file specified.
File name: ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’
at ConsoleApplication6.Program.Main(String[] args)
If i create a 4.7.2 .net console and add the nuget it wont compile.
It says
“C:\Program Files (x86)\RemObjects Software\Elements\Bin\EBuild.exe” D:\develop\ConsoleApplication6\ConsoleApplication6.sln --logger:fire --configuration:Debug --no-goal --verbosity:normal --xml:D:\develop\ConsoleApplication6\obj\ConsoleApplication6.water.xml --build --setting:TreatFixableErrorsAsWarnings=True
RemObjects EBuild. An open source build engine for Elements and beyond.
Copyright RemObjects Software 2016-2020. All Rights Reserved. Created by marc hoffman.
Version 10.0.0.2489 (develop) built on bajor, 20200228-152023. Commit 2465bd5.
W: Reference Assemblies folder for .NETFramework version 4.7.2 (‘C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2’) does not exist.
Reference ‘mscorlib’ was resolved to ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7\mscorlib.dll’ for target ‘Echoes’.
Reference ‘System’ was resolved to ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7\System.dll’ for target ‘Echoes’.
Reference ‘System.Core’ was resolved to ‘C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7\System.Core.dll’ for target ‘Echoes’.
Reference ‘System.Configuration.ConfigurationManager’ already was resolved to ‘C:\Users\john\AppData\Local\RemObjects Software\EBuild\Packages\NuGet\system.configuration.configurationmanager\4.7.0\ref\net461\System.Configuration.ConfigurationManager.dll’ for target ‘Echoes’.
Reference ‘System.Security.Permissions’ already was resolved to ‘C:\Users\john\AppData\Local\RemObjects Software\EBuild\Packages\NuGet\system.security.permissions\4.7.0\ref\net461\System.Security.Permissions.dll’ for target ‘Echoes’.
Reference ‘System.Security.AccessControl’ already was resolved to ‘C:\Users\john\AppData\Local\RemObjects Software\EBuild\Packages\NuGet\system.security.accesscontrol\4.7.0\ref\net461\System.Security.AccessControl.dll’ for target ‘Echoes’.
Reference ‘System.Security.Principal.Windows’ already was resolved to ‘C:\Users\john\AppData\Local\RemObjects Software\EBuild\Packages\NuGet\system.security.principal.windows\4.7.0\ref\net461\System.Security.Principal.Windows.dll’ for target ‘Echoes’.
RemObjects Elements (Oxygene, C#, Swift and Java) Compiler for .NET, Cocoa, Java and Island.
Version 10.0.0.2489 (develop) built on bajor, 20200228-152023. Commit 2465bd5.
Copyright 2003-2020 RemObjects Software, LLC. All rights reserved.
E: Unknown identifier “ConfigurationManager” [D:\develop\ConsoleApplication6\ConsoleApplication\Program.pas (13)]
Project ‘ConsoleApplication’ failed to build.
H: Local variable “value” is assigned to but never read [D:\develop\ConsoleApplication6\Program.pas (19)]
Solution ‘ConsoleApplication6’ failed to build project ‘ConsoleApplication6’.
of course I cannot speak for whats inside that .dll or not. But it looks like for the .NET framework, System.Configuration.ConfigurationManager is inside the standard System.Configuration.dll dll thats in the framework, not in this NuGet package.