wpf icon indicating copy to clipboard operation
wpf copied to clipboard

[dotnet-sdk-10.0.100-preview.4.25224.103] Fail to launch Text-Grab with error: System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception.

Open Junjun-zhao opened this issue 8 months ago • 8 comments

Description

When run the 3rd party application with the latest .NET 10 build, it failed with error: System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception.

Reproduction Steps

Debug Repro steps: The machine has dotnet-sdk-10.0.100-preview.4.25224.103 installed.

Please get the repro machine information from Devdiv bug 1.Open "C:\Users\test01\Desktop\Text-Grab\Source\Text-Grab\Text-Grab.sln" with Visual Studio. 2. Build the solution. 3. Update bin\Debug\net8.0-windows10.0.20348.0\Text-Grab.runtimeconfig to run against with dotnet-sdk-10.0.100-preview.4.25224.103:

"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "10.0.0-preview.4.25224.103"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "10.0.0-preview.4.25224.103"
      }
  1. Press F5 to start the app.

Expected behavior

App launch successful in Visual Studio.

Actual behavior

App launch failed with exception thrown in Visual Studio:

System.Windows.Markup.XamlParseException: ''Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '17' and line position '18'.'
Inner Exception 1:
InvalidOperationException: '#FF1C1C1C' is not a valid value for property 'Color'.
   at System.Windows.DependencyObject.EvaluateExpression(EntryIndex entryIndex, DependencyProperty dp, Expression expr, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry)
   at System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.DependencyObject.OnInheritanceContextChanged(EventArgs args)
   at System.Windows.DependencyObject.ProvideSelfAsInheritanceContext(DependencyObject doValue, DependencyProperty dp)
   at System.Windows.ResourceDictionary.AddInheritanceContextToValues()
   at System.Windows.ResourceDictionary.set_Source(Uri value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
   --- 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 Text_Grab.App.InitializeComponent() in C:\Users\v-shisheng\Desktop\Text-Grab\Text-Grab\App.xaml:line 1
   at Text_Grab.App.Main()

Regression?

Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.400: Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-10.0.100-preview.3.25201.16: Pass 3). Windows 10 21H2 AMD64 + dotnet-sdk-10.0.100-preview.4.25219.3: Pass 4). Windows 10 21H2 AMD64 + dotnet-sdk-10.0.100-preview.4.25224.103: Fail

Known Workarounds

No response

Impact

No response

Configuration

Application Name: Text-Grab OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-10.0.100-preview.4.25224.103 App & App Source & Repro machine checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2458623 Github Link: https://github.com/TheJoeFin/Text-Grab

Dotnet Info:

.NET SDK:
 Version:           10.0.100-preview.4.25224.103
 Commit:            64aafa881d
 Workload version:  10.0.100-manifests.d5de32d1
 MSBuild version:   17.15.0-preview-25224-103+64aafa881

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-preview.4.25224.103\

Host:
  Version:      10.0.0-preview.4.25224.103
  Architecture: x64
  Commit:       64aafa881d

.NET SDKs installed:
  10.0.100-preview.4.25224.103 [C:\Program Files\dotnet\sdk]

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

Other information

App Repro steps The machine has dotnet-sdk-10.0.100-preview.4.25224.103 installed.

  1. Change the "C:\Users\test01\Desktop\Text-Grab\App\Text-Grab.runtimeconfig.json" file to let the app run against with dotnet-sdk-10.0.100-preview.4.25224.103.
"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "10.0.0-preview.4.25224.103"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "10.0.0-preview.4.25224.103"
      }
  1. Run command: dotnet Text-Grab.dll in “C:\Users\test01\Desktop\Text-Grab\App”.

Expected Result: Launch successfully.

Actual Result: Launch failed with error:

Unhandled exception. System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
 ---> System.InvalidOperationException: '#FF1C1C1C' is not a valid value for property 'Color'.
   at System.Windows.DependencyObject.EvaluateExpression(EntryIndex entryIndex, DependencyProperty dp, Expression expr, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry)
   at System.Windows.DependencyObject.EvaluateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, OperationType operationType)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.DependencyObject.OnInheritanceContextChanged(EventArgs args)
   at System.Windows.DependencyObject.ProvideSelfAsInheritanceContext(DependencyObject doValue, DependencyProperty dp)
   at System.Windows.ResourceDictionary.AddInheritanceContextToValues()
   at System.Windows.ResourceDictionary.set_Source(Uri value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
   --- 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 Text_Grab.App.InitializeComponent() in C:\Users\v-shisheng\Desktop\Text-Grab\Text-Grab\App.xaml:line 1
   at Text_Grab.App.Main()

Findings:

  1. We reported a bug with same error message on .NET 9 Preview 7 before: [9.0.100-preview.7.24375.12] Text-Grab launch failed with exception System.Windows.Markup.XamlParseException at System.Windows.DependencyObject.EvaluateExpression · Issue #9475 · dotnet/wpf And we use the opt-out switch for DynamicResource optimization on .NET 9 RC1 build that mentioned in this bug to let the Text-Grab launch successfully.
  2. Start on 10.0.100-preview.4.25215.17 and before version, no matter we use the opt-out switch for DynamicResource optimization or not, the app also can launch successfully. It seems the opt-out switch for DynamicResource optimization on .NET 9 RC1 is not required in .NET 10 build.
  3. But start from 10.0.100-preview.4.25224.103, no matter we use opt-out switch for DynamicResource optimization or not, the app launch failed with the same error message that in Findings#1.

@dotnet-actwx-bot @dotnet/compat

Junjun-zhao avatar Apr 29 '25 01:04 Junjun-zhao

@harshit7962 Could you please take a look at this issue? Thanks.

Junjun-zhao avatar Apr 29 '25 02:04 Junjun-zhao

@Junjun-zhao from the looks of it https://github.com/dotnet/wpf/issues/9475 seems to be the same, and as mentioned in the comment there, it is due to the incorrect usage of a resource. Can you please confirm if this is the case?

harshit7962 avatar Apr 29 '25 06:04 harshit7962

@harshit7962 The error is same as https://github.com/dotnet/wpf/issues/9475 which is filed in .NET 9. At that time, the issue was gone when set the switch.

Here are our findings:

  • Start on 10.0.100-preview.4.25215.17 and before version, no matter we use the opt-out switch for DynamicResource optimization or not, the app also can launch successfully. It seems the opt-out switch for DynamicResource optimization on .NET 9 RC1 is not required in .NET 10 build.
  • But start from 10.0.100-preview.4.25224.103, no matter we use opt-out switch for DynamicResource optimization or not, the app launch failed with the same error message that in Findings#1.

Is there any change on .NET 10 build recently?

Junjun-zhao avatar Apr 29 '25 07:04 Junjun-zhao

Yes this is an expected change.

  • So for .NET 10, we have had made the optimizations as opt-in by default, which aligns with the first finding.
  • There has been a recent progress, where a different approach was adopted for the optimization. To get maximum hit on the new code path, we had disabled the safeguard of the switch that was used, and hence no matter what the value of switch is, the optimized code would be executed. This aligns with the second finding.

Please let me know if any more information is needed on this.

PS: This does not mean that the failing applications should not be reported. This is the only case among the previous cases that we have seen which is an exception.

harshit7962 avatar Apr 29 '25 07:04 harshit7962

Understand. So, for this case, the application owner needs to update on their side due to incorrect resource usage. Is that correct?

Will this be documented as a breaking change? Also, is there a standard or guidance which help users optimize the resource usage?

CC: @PriyaPurkayastha @marklio for awareness.

Junjun-zhao avatar Apr 29 '25 08:04 Junjun-zhao

Also, is there a standard or guidance which help users optimize the resource usage?

A generic guideline about resources is available here: https://learn.microsoft.com/en-us/dotnet/desktop/wpf/systems/xaml-resources-overview?view=netdesktop-9.0

Will this be documented as a breaking change?

The feature as a whole would be part of release-notes for .NET 10, where we will mention about this scenario.

harshit7962 avatar Apr 29 '25 09:04 harshit7962

Thanks @harshit7962. We have filed a bug to notify the application owner about this issue.

Junjun-zhao avatar Apr 30 '25 01:04 Junjun-zhao

@Junjun-zhao are we good to close this then?

harshit7962 avatar Apr 30 '25 05:04 harshit7962

@harshit7962 this needs to be documented as a breaking change: There has been a recent progress, where a different approach was adopted for the optimization. To get maximum hit on the new code path, we had disabled the safeguard of the switch that was used, and hence no matter what the value of switch is, the optimized code would be executed. This aligns with the second finding.

PriyaPurkayastha avatar Apr 30 '25 18:04 PriyaPurkayastha

@Junjun-zhao and @PriyaPurkayastha Thank you for the confirmation. We’ve documented this as a breaking change and informed the relevant team accordingly. If there are no further requirements, can we get this closed?

harshit7962 avatar May 15 '25 06:05 harshit7962

@harshit7962 Thank you for this update. Yes, please go ahead.

Junjun-zhao avatar May 15 '25 07:05 Junjun-zhao