.net core system.configuration.configurationmanager

Hi,

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.

  "System.Configuration.ConfigurationManager/4.7.0": {
    "dependencies": {
      "System.Security.Cryptography.ProtectedData": "4.7.0",
      "System.Security.Permissions": "4.7.0"
    },
    "runtime": {
      "ref\\netstandard2.0\\System.Configuration.ConfigurationManager.dll": {
        "assemblyVersion": "4.0.3.0",
        "fileVersion": "4.700.19.56404"
      }
    }
  },

Its trying to pull in a file from the ref folder, which it shouldnt be doing.

Using visual studio I get this

  "System.Configuration.ConfigurationManager/4.7.0": {
    "dependencies": {
      "System.Security.Cryptography.ProtectedData": "4.7.0",
      "System.Security.Permissions": "4.7.0"
    },
    "runtime": {
      "lib/netstandard2.0/System.Configuration.ConfigurationManager.dll": {
        "assemblyVersion": "4.0.3.0",
        "fileVersion": "4.700.19.56404"
      }
    }
  },

From Water

ConsoleApplication6.zip (318.0 KB)

From Visual Studio

ConsoleApp42.zip (247.4 KB)

Cheers,
John

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.

Thanks, logged as bugs://83998

3.1

1 Like

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?

I think so.

Does VC# copy-local the lib ref?

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.

by comparison:

ref: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.configuration.configurationmanager/4.7.0/ref/netstandard2.0/System.Configuration.ConfigurationManager.dll
ref: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.security.permissions/4.7.0/ref/netcoreapp3.0/System.Security.Permissions.dll
lib: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.security.permissions/4.7.0/lib/netcoreapp3.0/System.Security.Permissions.dll

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… :(.

No its not copied local

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 ?

I think this was the related issue

For .net framework the solution was to reference ref but only copy lib. So for core its reference ref but only us lib in the deps.json

Yeah, I co muted a potential fix that does just that, now.

that said, your snipped from VC# does have it in the deps.json… :wink:

1 Like

The visual studio deps, runtime points to the lib ?

Right, but according to the copy local, it shouldn’t, because the file isn’t copy-local’ed.

I never noticed that visual studio doesnt havent a copy local for .net core ?

Did you mean to remove the runtime reference ?

Its changed from this

"System.Configuration.ConfigurationManager/4.7.0": {
    "dependencies": {
      "System.Security.Cryptography.ProtectedData": "4.7.0",
      "System.Security.Permissions": "4.7.0"
    },
    "runtime": {
      "ref\\netstandard2.0\\System.Configuration.ConfigurationManager.dll": {
        "assemblyVersion": "4.0.3.0",
        "fileVersion": "4.700.19.56404"
      }
    }
  },

to

      "System.Configuration.ConfigurationManager/4.7.0": {
        "dependencies": {
          "System.Security.Cryptography.ProtectedData": "4.7.0",
          "System.Security.Permissions": "4.7.0"
        },
        "compile": {
          "ref/netstandard2.0/System.Configuration.ConfigurationManager.dll": {
          }
        }
      },

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.

I now get this

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)

:(.

Bloody fucking mess.

Yes.

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’.

I see int being referenced correctly:

                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/mscorlib.dll
                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/System.Core.dll
                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/System.Data.DataSetExtensions.dll
                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/System.Data.dll
                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/System.dll
                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/System.Xml.dll
                  Reference: /Users/mh/Code/Fire Support/_NETFramework/v4.7/System.Xml.Linq.dll
                  Reference: /Users/mh/Code/Fire/Bin/Build/macOS/Fire.app/Contents/Resources/Reference Paths/Echoes/../../References/Echoes/NET/Echoes.dll
                  Reference: /Users/mh/Code/Fire/Bin/Build/macOS/Fire.app/Contents/Resources/Reference Paths/Echoes/../../References/Echoes/NET/Elements.dll
                  Reference: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.configuration.configurationmanager/4.7.0/ref/net461/System.Configuration.ConfigurationManager.dll
                  Reference: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.security.accesscontrol/4.7.0/ref/net461/System.Security.AccessControl.dll
                  Reference: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.security.permissions/4.7.0/ref/net461/System.Security.Permissions.dll
                  Reference: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Packages/NuGet/system.security.principal.windows/4.7.0/ref/net461/System.Security.Principal.Windows.dll
                  Reference: /Users/mh/Code/Fire/Bin/Build/macOS/Fire.app/Contents/Resources/RemObjects.Elements.Cirrus.dll

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.

Yes I would just added system.configuration for a .net framework app, I just wanted to see what would happen if I added this nuget