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

WPF for .NET Core throws first chance exceptions due to .NET Core limitations #2395

Closed
AArnott opened this issue Jan 3, 2020 · 11 comments
Closed
Assignees
Labels
issue-type-tracking-external To track dependencies with other teams or repos
Milestone

Comments

@AArnott
Copy link

AArnott commented Jan 3, 2020

  • .NET Core Version: 3.1
  • Windows version: 1909
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No

Problem description:

WPF for .NET Core throws a multiple first-chance exceptions during startup because AppSettings isn't available on .NET Core.

Actual behavior:

System.Configuration.ConfigurationErrorsException
  HResult=0x80131902
  Message=Configuration system failed to initialize
  Source=System.Configuration.ConfigurationManager
  StackTrace:
   at System.Configuration.ConfigurationManager.PrepareConfigSystem() in /_/src/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationManager.cs:line 150

  This exception was originally thrown at this call stack:
    System.Configuration.ClientConfigPaths.ClientConfigPaths(string, bool) in ClientConfigPaths.cs
    System.Configuration.ClientConfigPaths.GetPaths(string, bool) in ClientConfigPaths.cs
    System.Configuration.ClientConfigurationHost.ConfigPaths.get() in ClientConfigurationHost.cs
    System.Configuration.ClientConfigurationHost.GetStreamName(string) in ClientConfigurationHost.cs
    System.Configuration.ClientConfigurationHost.IsAppConfigHttp.get() in ClientConfigurationHost.cs
    System.Configuration.Internal.DelegatingConfigHost.IsAppConfigHttp.get() in DelegatingConfigHost.cs
    System.Configuration.ClientConfigurationSystem.ClientConfigurationSystem() in ClientConfigurationSystem.cs
    System.Configuration.ConfigurationManager.EnsureConfigurationSystem() in ConfigurationManager.cs

Inner Exception 1:
PlatformNotSupportedException: Operation is not supported on this platform.

Expected behavior:

I expect WPF for .NET Core avoids calling APIs that are known to not work on .NET Core so that these first chance exceptions aren't thrown.

@AArnott
Copy link
Author

AArnott commented Jan 3, 2020

This also appears in FrameworkCompatibilityPreferences:

@ericstj
Copy link
Member

ericstj commented Jan 6, 2020

/cc @JeremyKuhne @maryamariyan

AppSettings should be usable on .NETCore (see https://gist.github.com/ericstj/20497889f9d71ceb5d0f5fcc84cdede1), though we wouldn't recommend building new things around it. @AArnott it looks like you're hitting this:
https://github.com/dotnet/runtime/blob/4f9ae42d861fcb4be2fcd5d3d55d5f227d30e723/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigPaths.cs#L49-L56

Perhaps you're hitting this because the way you're hosting CoreCLR doesn't set EntryAssembly? That might be something to try to root cause here: I suspect other things might fallout of this.

@AArnott
Copy link
Author

AArnott commented Jan 6, 2020

Oh, quite possibly. I'll see if I can figure out how to set that EntryAssembly property. So far the only property I'm setting is APP_CONTEXT_BASE_DIRECTORY, and I'm discovering properties I need to set as I go. Is there a complete list of properties that may need setting in a custom .NET Core host?

@ericstj
Copy link
Member

ericstj commented Jan 6, 2020

Looks to be the issue discussed here: https://github.com/dotnet/corefx/issues/27091. I couldn't find any hook to set EntryAssembly. As @jkotas mentioned it's only set on the appdomain when ExecuteMainMethod is called.

@gomathip02 gomathip02 modified the milestones: 5.0, Future Jan 7, 2020
@gomathip02 gomathip02 added the issue-type-tracking-external To track dependencies with other teams or repos label Jan 7, 2020
@rladuca
Copy link
Member

rladuca commented Jan 8, 2020

Thanks @ericstj for checking into it.

@AArnott WPF isn't going to change that code in any significant fashion unless there is an overriding need to. There are significant switches that help ensure backward compatibility with .NET Framework and minimize problems with porting to .NET Core that we want to preserve. All of these are based around ConfigurationManager.

I'm going to close this as there doesn't seem like any actions for WPF here.

@ivan2007
Copy link

Hi,
I have a similar issue with a win32 app that calls a c++/cli NET Core 3.1 lib. The c++/cli lib calls a WPF NET Core 3.1 lib.
The exceptions are:
'System.PlatformNotSupportedException' in System.Configuration.ConfigurationManager.dll
'System.Configuration.ConfigurationErrorsException' in System.Configuration.ConfigurationManager.dll
You can find more details here

@ryalanms
Copy link
Member

Hi, @ivan2007. Can you attach your information to this dotnet/runtime#25027? This is a runtime issue. Thanks.

@ivan2007
Copy link

Hi @ryalanms, I can't attach my information because the issue dotnet/runtime#25027 is locked

@SamBent
Copy link
Contributor

SamBent commented Feb 17, 2021

@ivan2007 Then open a new issue in dotnet/runtime. It looks like the problem was fixed in .NET 5.0, but you need the fix in 3.1. WPF cannot help you - it's a runtime issue.

@ericstj
Copy link
Member

ericstj commented Feb 17, 2021

Even with that exception, I suspect it is caught and handled. If you aren't trying to use an app.exe.config file you're likely fine and not impacted by the config-system's failure to locate the config file. Those are just first chance exceptions that clutter the debug output.

@SamBent / @ryalanms WPF could eliminate it's use of ConfigurationManager. Of course that would be something to consider in a future version.

@ivan2007
Copy link

@SamBent I opened a new issue in dotnet/runtime
I confirm that the issue is not present with NET 5.0 but for now I can't migrate so it would be nice to have a fix for NET Core

@ghost ghost locked as resolved and limited conversation to collaborators Apr 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue-type-tracking-external To track dependencies with other teams or repos
Projects
None yet
Development

No branches or pull requests

7 participants