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

Crash when project lies at network location | Failed to save settings: An error occurred loading a configuration file #112410

Closed
Rsge opened this issue Feb 11, 2025 · 11 comments

Comments

@Rsge
Copy link

Rsge commented Feb 11, 2025

Description

When trying to save changed settings from a project on a network location (network drive or UNC path) in .NET 9 using My.Settings.Save() or Properties.Settings.Default.Save();, respectively, a program crash occurs.

Reproduction Steps

  1. Create an application (e.g. WinForms) using .NET 9. at a network location (Network drive or UNC path)
  2. Create the settings by adding any setting, e.g. a String Test with value "X".
  3. Change this setting in the running program using My.Settings.Test = "Y" or Properties.Settings.Default.Test = "Y";, respectively.
  4. Save using My.Settings.Save() / Properties.Settings.Default.Save();
  5. Run the program.

TestC#VB.zip

Expected behavior

The program saving the settings to the default save location, as it did in .NET 8. No crash, obviously.

Actual behavior

The program crashes with the following error:

System.Configuration.ConfigurationErrorsException: 'Failed to save settings: An error occurred loading a configuration file: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''.'

InvalidOperationException: An unexpected error occurred in 'ClientConfigurationHost::OpenStreamForWrite '' '''.

This exception was originally thrown at this call stack:
    [External Code]

Regression?

Worked in .NET 8, 6 and 5 definitively and probably 7, too. Haven't tested .NET FW.

Known Workarounds

Don't put the project at a network location, but save it on a local drive.

Configuration

  • .NET SDK:
    • Version: 9.0.102
    • Commit: cb83cd4923
    • Workload version: 9.0.100-manifests.4a54b1a6
    • MSBuild version: 17.12.18+ed8c6aec5
  • Runtime environment:
    • OS Name: Windows
    • OS Version: 10.0.19045
    • OS Platform: Windows
    • RID: win-x64
    • Base Path: C:\Program Files\dotnet\sdk\9.0.102\

Haven't tested on other configurations.

Other information

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 11, 2025
@steveharter
Copy link
Member

This should be transferred to WinForms.

I was unable to reproduce the issue. Tried v8, v9 and v10.

@steveharter
Copy link
Member

@JeremyKuhne any thoughts? Should we transfer to WinForms for evaluation?

@JeremyKuhne
Copy link
Member

@steveharter this shouldn't be specific to WinForms. You can add a Settings file (use the Settings template in add new item) to a console app with the ConfigurationManager package.

@Rsge I also was unable to repro your described behavior with your project.

@Rsge
Copy link
Author

Rsge commented Feb 12, 2025

@JeremyKuhne I figured as much, as this severe of an issue not already being listed here and also not really findable through normal search made me think I did something wrong, too. I just can't figure out what.

I tried using ConfigurationManager in a console application using the example provided on the NuGet page – this works, but also doesn't use settings.settings but App.config, so it's not comparable and I don't know how to make it use the settings file. (Tried a few things, but couldn't get it to work.)

The strange thing to me is that the only thing I change is the target framework, .NET 8 works, .NET 9 doesn't.
I made a small video showing the issue, maybe there is additional detail in there that I failed to mention.
https://github.com/user-attachments/assets/d9a97c32-941f-4f45-9951-7e726cb73117

If you need any further info, please don't hesitate to ask.
Meanwhile, I can just continue to use .NET 8.

@Rsge

This comment has been minimized.

@JeremyKuhne
Copy link
Member

@Rsge Perhaps enabling first chance exceptions will give us more of a clue. There is a lot of reflection going in System.Configuration and poking around shared locations.

@steveharter
Copy link
Member

This may be a duplicate of #28833.

@Rsge if you add any information here about first-chance exceptions and call stacks that may help.

@steveharter steveharter added the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 14, 2025
@Rsge
Copy link
Author

Rsge commented Feb 18, 2025

Sorry for the late reply, this issue occurs at work and I don't work on all normal weekdays.

I didn't know how to enable "first chance exceptions" and used Stackoverflow as a guide, I hope this is what you meant:
With all exception types set to break when thrown, it still breaks at the exact same "location".
Image
Both InvalidOperationException and ConfigurationErrorsException are definitively selected under Common Language Runtime Exceptions.


poking around shared locations.

This seems to be the issue @JeremyKuhne:
If I copy the project to my local system, it works as expected.
If I try running it on a network path (either network drive or UNC path), the error occurs.

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 18, 2025
@steveharter
Copy link
Member

Your first-chance exception settings are correct: break on exceptions + have no exceptions that are ignored.

However, can you click on "show call stack" when you get the exception and report back that information, so we get a call stack more than one level. Thanks.

@steveharter steveharter added needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner labels Feb 18, 2025
@Rsge
Copy link
Author

Rsge commented Feb 19, 2025

@steveharter
If I do just that, it still shows only [External Code] on both sides of the exception.
Image

But enabling Show External Code then did the trick I think – it at least shows much more info now.
Image

@dotnet-policy-service dotnet-policy-service bot added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Feb 19, 2025
@Rsge Rsge changed the title Failed to save settings: An error occurred loading a configuration file Crash when project lies at network location | Failed to save settings: An error occurred loading a configuration file Feb 20, 2025
@steveharter
Copy link
Member

steveharter commented Feb 27, 2025

I see the recent edits that the error occurs when saving to a UNC or network path. There was a recent issue UNC path issue fixed in 9.0 that should be in the 9.0.3 release, to be released sometime in mid-March.

So I'm going to mark this as duplicate for now. Please reply to this once 9.0.3 is released to see if it fixes your issue. If not, we can continue diagnosing.

Although I don't know the exact repro here, a somewhat common issue is that developers may be running Visual Studio as local machine admin which won't have network permissions. However, I don't think that is the case here otherwise it should also fail on previous releases.

@steveharter steveharter removed the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants