Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error accessing System.Configuration.ConfigurationManager in F# Script and F# Interactive on Visual Studio 16.8.0 #10550

Closed
alexchro93 opened this issue Nov 25, 2020 · 2 comments · Fixed by #10572
Labels
Area-FSI Area-VS-FSI VS window and commands for F# Interactive
Milestone

Comments

@alexchro93
Copy link

alexchro93 commented Nov 25, 2020

In Visual Studio 16.8.0 error FS0039 is encountered when trying to access System.Configuration.ConfigurationManager after bringing in the NuGet package via #r "nuget: System.Configuration.ConfigurationManager".

Repro steps

  1. Paste the following code in to an F# Scrip file in Visual Studio.
//
// ==== Bring in Dependency ====
//

#r "nuget: System.Configuration.ConfigurationManager"

//
// ==== Set Environment ====
//

System.Configuration.ConfigurationManager.AppSettings.Item "Environment" <- "LOCAL"

//
// ==== Get Environment ====
//

let env = System.Configuration.ConfigurationManager.AppSettings.Item "Environment"

match env with
| "LOCAL" -> printf $"In LOCAL environment"
| _ -> printf $"Environment unknown"
  1. The following error appears in Visual Studio editor

image

  1. Try to execute in F# interactive, the following error is shown

image

  1. If you run the script via command line, everything works

image

Expected behavior

Expected to be able to execute above code in F# Interactive Window

Actual behavior

Cannot execute above code in F# Interactive Window

Known workarounds

I can just execute via command line, but that's no fun.

Related information

  • Windows 10 Version 1909
  • dotnet SDK 5.1.100
  • Visual Studio 16.8.0
@cartermp
Copy link
Contributor

Offhand this looks to be a quirk related to differences in dotnet fsi and fsi.exe, the latter of which is used by Visual Studio.

@cartermp cartermp added Area-FSI Area-VS-FSI VS window and commands for F# Interactive labels Nov 26, 2020
@cartermp cartermp added this to the Backlog milestone Nov 26, 2020
@KevinRansom
Copy link
Member

The desktop build of fsi doesn't preload System.Configuration.dll, and never has.

To make this work on desktop FSI, add this at the top of the script:
#r @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Configuration.dll"

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>fsi

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

For help type #help;;

> #r @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Configuration.dll"
- #r "nuget: System.Configuration.ConfigurationManager"
- open System.Configuration
- System.Configuration.ConfigurationManager.AppSettings.Item "Environment" <- "LOCAL";;

--> Referenced 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Configuration.dll' (file may be locked by F# Interactive process)

[Loading C:\Users\codec\AppData\Local\Temp\nuget\2408--83596b72-a4c3-4bc9-87f9-5c2a043adedd\Project.fsproj.fsx]
namespace FSI_0002.Project

val it : unit = ()

>

I will look at a fix in the product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Area-VS-FSI VS window and commands for F# Interactive
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants