dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.06k stars 1.17k forks source link

[dotnet-sdk-9.0.100-preview.7.24352.8] WPF apps launch failed with exception 'Value cannot be null. (Parameter 'key')' #9353

Closed Junjun-zhao closed 2 months ago

Junjun-zhao commented 3 months ago

Description

When run the 3rd party application with the latest .NET 9 build "dotnet-sdk-9.0.100-preview.7.24352.8", it failed to launch with exception: 'Value cannot be null. (Parameter 'key')'.

Reproduction Steps

App Repro steps:

  1. Open C:\ReproApps\wpfui\Wpf.Ui.Gallery.runtimeconfig.json file (Please refer to the App location and repro machine info from devdiv bug).
  2. Change the "Wpf.Ui.Gallery.runtimeconfig.json" file to let the app run against with dotnet-sdk-dotnet-sdk-9.0.100-preview.7.24352.8.
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.7.24352.1"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "9.0.0-preview.7.24352.1"
      }
    ],
  3. Launch Wpf.Ui.Gallery.exe.

Expected behavior

Launch successfully.

Actual behavior

Launch failed. Open Event Viewer, we can see below detailed stack trace message:

Application: Wpf.Ui.Gallery.exe
CoreCLR Version: 9.0.24.35201
.NET Version: 9.0.0-preview.7.24352.1
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Windows.Markup.XamlParseException: Set property 'Wpf.Ui.Markup.ThemesDictionary.Theme' threw an exception.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at System.Windows.DeferredResourceReferenceList.Get(Object resourceKey)
   at System.Windows.ResourceDictionary.ClearWithoutLock()
   at System.Windows.ResourceDictionary.Clear()
   at System.Windows.ResourceDictionary.set_Source(Uri value)
   at Wpf.Ui.Markup.ThemesDictionary.SetSourceBasedOnSelectedTheme(Nullable`1 selectedApplicationTheme)
   at Wpf.Ui.Markup.ThemesDictionary.set_Theme(ApplicationTheme value)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at Wpf.Ui.Gallery.App.InitializeComponent() in C:\Users\v-gwei\Downloads\wpfui-main\wpfui-main\src\Wpf.Ui.Gallery\App.xaml:line 1
   at Wpf.Ui.Gallery.App.Main()

Regression?

Yes Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.6.24328.19: Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24352.8: Fail 3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24353.17: Fail

Known Workarounds

No response

Impact

No response

Configuration

Application Name: wpfui, Open-SD-WebUI-Launcher, Text-Grab OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.7.24352.8 App or App installer checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2114834 Github Link: https://github.com/lepoco/wpfui https://github.com/Ray-Source-X/Open-SD-WebUI-Launcher https://github.com/TheJoeFin/Text-Grab

Dotnet Info:

.NET SDK:
 Version:           9.0.100-preview.7.24352.8
 Commit:            707091200d
 Workload version:  9.0.100-manifests.82c210e1
 MSBuild version:   17.12.0-preview-24352-02+47393a047

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.100-preview.7.24352.8\

Host:
  Version:      9.0.0-preview.7.24352.1
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  9.0.100-preview.7.24352.8 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.7.24329.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.7.24352.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.7.24352.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other information

Debug Repro steps: 1.Open "C:\ReproAppSource\wpfui\Wpf.Ui.sln" with Visual Studio.

  1. Build the solution.
  2. Update bin\Debug\net8.0-windows10.0.22621.0\Wpf.Ui.Gallery.runtimeconfig.json to run against with dotnet-sdk-9.0.100-preview.7.24352.8:
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.7.24352.1"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "9.0.0-preview.7.24352.1"
      }
    ]
  3. Press F5 to start the app.

Expected Result: App launch successful in Visual Studio.

Actual Result: App launch failed with exception thrown in Visual Studio. image

Findings: 1.The issue occurs when loading resource xaml file. In below repro app, we tried remove all content in Light.xaml file and only keep below 1 StaticResource, the problem still occurs.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Color x:Key="AcrylicBackgroundFillColorDefault">#F9F9F9</Color>
    <SolidColorBrush x:Key="ToolTipBackground" Color="{StaticResource AcrylicBackgroundFillColorDefault}" />
</ResourceDictionary>
  1. We found this issue and https://github.com/dotnet/wpf/issues/9354 are all related to load Resource in WPF applications. But they have different stack trace and exception message.

@dotnet-actwx-bot @dotnet/compat

Junjun-zhao commented 2 months ago

@harshit7962 We have verified this issue with build dotnet-sdk-9.0.100-preview.7.24374.17, it has been fixed. But for Text-Grab, there is an new issue and we file a new bug [9.0.100-preview.7.24375.12] Text-Grab launch failed with exception System.Windows.Markup.XamlParseException at System.Windows.DependencyObject.EvaluateExpression . Could you please help look into it? Thanks.

harshit7962 commented 2 months ago

Will follow the reported failure in respective thread. Closing this issue as of now.

Thank you @Junjun-zhao for reporting and keeping a close eye on this.