fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Cannot load "System.Configuration.ConfigurationManager >= 5" in dotnet fsi

Open SchlenkR opened this issue 3 years ago • 7 comments

Any transitive or direct usage of System.Configuration.ConfigurationManager with a version >=5 results in an error in FSI.

Repro steps

This can be reproduced by evaluating this in FSI:

#r "nuget: System.Configuration.ConfigurationManager, 6.0"
typeof<System.Configuration.ConfigurationManager>

Expected behavior

The correct type of ConfigurationManager should be available.

Actual behavior

A Could not load file or assembly 'System.Configuration.ConfigurationManager... error is raised. This is the complete FSI output:

Welcome to F# Interactive for .NET Core in Visual Studio. To execute code, either
  1. Use 'Send to Interactive' (Alt-Enter or right-click) from an F# script. The F# Interactive process will
     use any global.json settings associated with that script.
  2. Press 'Enter' to start. The F# Interactive process will use default settings.
> 

Microsoft (R) F# Interactive, Version 12.0.0.0 für F# 6.0
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Um Hilfe zu erhalten, geben Sie "#help;;" ein.

> [Loading C:\Users\ronal\AppData\Local\Temp\nuget\12404--36dd1648-705f-4ba7-a0e9-5ccf88db4578\Project.fsproj.fsx]
namespace FSI_0002.Project

Binding session to 'C:/Users/xxx/.nuget/packages/system.configuration.configurationmanager/6.0.0/lib/net6.0/System.Configuration.ConfigurationManager.dll'...
> 

error FS0193: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

error FS0193: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL'. Das System kann die angegebene Datei nicht finden.

Known workarounds

In this related issue and post, renaming C:\Program Files\dotnet\sdk\6.0.101\FSharp\System.Configuration.ConfigurationManager.dll to System.Configuration.ConfigurationManager.bak.dll solved the issue.

Further technical details

OS: WIndows 11 dotnet: 6.0.101 Microsoft Visual Studio Community 2022 (64-bit), Version 17.0.4

SchlenkR avatar Feb 06 '22 13:02 SchlenkR

Related to: https://github.com/dotnet/SqlClient/issues/1397

SchlenkR avatar Feb 06 '22 13:02 SchlenkR

Same problem with System.Security.Cryptography.Xml:

#r "nuget: System.Security.Cryptography.Xml, 6.0.0.0"
typeof<System.Security.Cryptography.Xml.SignedXml>

Output:

        #r "nuget: System.Security.Cryptography.Xml, 6.0.0.0"
        typeof<System.Security.Cryptography.Xml.SignedXml>
;;

Microsoft (R) F# Interactive version 12.0.0.0 for F# 6.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

>         #r "nuget: System.Security.Cryptography.Xml, 6.0.0.0"
-         typeof<System.Security.Cryptography.Xml.SignedXml>
- ;;
[Loading /var/folders/6d/_vznfncd2mlf0p0_swdy6fcc0000gq/T/nuget/7303--88244410-ffc4-433b-b713-2400a91d8205/Project.fsproj.fsx]
namespace FSI_0002.Project

Binding session to '/Users/moisesnessim/.nuget/packages/system.security.cryptography.xml/6.0.0/lib/net6.0/System.Security.Cryptography.Xml.dll'...

error FS0193: Could not load file or assembly 'System.Security.Cryptography.Xml, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

error FS0193: Could not load file or assembly 'System.Security.Cryptography.Xml, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL'. The system cannot find the file specified.

> 

dotnet --info:

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.5
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  6.0.100 [/nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.0 [/nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0 [/nix/store/nwyx15pwbkfqxl818q2nhh3cmnmvygik-dotnet-sdk-6.0.100/shared/Microsoft.NETCore.App]

moinessim avatar Feb 24 '22 19:02 moinessim

This needs the update to .NET 6 for dotnet fsi e.g. #12734

dsyme avatar Feb 24 '22 20:02 dsyme

@KevinRansom This is still a problem

C:\GitHub\dsyme\fsharp>artifacts\bin\fsi\Debug\net6.0\fsi.exe

Microsoft (R) F# Interactive version 12.0.0.0 for F# 6.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> #r "nuget: System.Configuration.ConfigurationManager, 6.0"
- typeof<System.Configuration.ConfigurationManager>
- ;;
[Loading C:\Users\dsyme\AppData\Local\Temp\114264--939928db-26d5-4667-9b3a-d982cdebbc5b\Project.fsproj.fsx]
namespace FSI_0002.Project

Binding session to 'C:/Users/dsyme/.nuget/packages/system.configuration.configurationmanager/6.0.0/lib/net6.0/System.Configuration.ConfigurationManager.dll'...


error FS0193: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

ilxGen.LookupGeneratedValue for v=it caught exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   at FSI_0003.get_it()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at FSharp.Compiler.IlxGen.LookupGeneratedValue(ImportMap amap, ExecutionContext ctxt, IlxGenEnv eenv, Val v) in C:\GitHub\dsyme\fsharp\src\fsharp\IlxGen.fs:line 8706

Binding session to 'C:/Users/dsyme/.nuget/packages/system.configuration.configurationmanager/6.0.0/lib/net6.0/System.Configuration.ConfigurationManager.dll'...

dsyme avatar Mar 03 '22 22:03 dsyme

Any ideas on this? Just stung me again with MS.Data.SqlClient.

isaacabraham avatar Apr 26 '22 17:04 isaacabraham

Any ideas on this? Just stung me again with MS.Data.SqlClient.

Same here. Wanted to play around with Microsoft.Data.SqlClient in fsi on Linux, but stuck with System.Configuration.ConfigurationManager error.

Maybe there is at least a temporary workaround available?

ashenwolf avatar Jun 14 '22 17:06 ashenwolf

I hit the same problem while playing with System.Runtime.Caching.MemoryCache.

System.Runtime.Caching uses the ConfigurationManager to get configuration for the system.runtime.caching/memoryCache section. So any library using dotnet`s memory caching will not run in fsi.

temporary work around is adding #r "nuget:System.Configuration.ConfigurationManager, 4.7.0"

What is the reason ConfigurationManager not playing nice with fsi??

wavewizard avatar Jun 16 '22 16:06 wavewizard

I can load it currently:

> #r "nuget: System.Configuration.ConfigurationManager, 6.0";;
> typeof<System.Configuration.ConfigurationManager>.CustomAttributes;;

val it:
  System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData>
= [||]

It was likely happening because fsi ships with msbuild and transitive dependencies (System.Dom, System.Configuration.ConfigurationManager, etc) and when trying to load some specific version, it was failing due to inability to load it properly alongside existing one.

I will close it for now. If it is happening with any of the other assemblies, please open a new one. In this case we will need to rethink how should we load assemblies, specifically for the dependency manager...probably use separate ALC for it. Or an external process.

vzarytovskii avatar May 15 '24 14:05 vzarytovskii