After I upgrade Visual Studio 2022 from 17.11 preview 7 to 17.12 just now, my WPF project not functioning properly

Smith Tom 65 Reputation points
2024-08-15T07:41:54.2266667+00:00

It stuck at the the following code:

public partial class MainWindow : Window
{
    public static MainWindow? Current { get; private set; }
    public MainWindowViewModel ViewModel { get; private set; }
    public MainWindow()
    {
        InitializeComponent(); //The Exception throw at this line
        ViewModel = new MainWindowViewModel(this);
        DataContext = ViewModel;
        Current = this;
        Width = SystemProfile.MainWindowWidth;
        Height = SystemProfile.MainWindowHeight;
    }
}

The following is the exception message:


System.Windows.Markup.XamlParseException
  HResult=0x80131501
  Message=“在“System.Windows.StaticResourceExtension”上提供值时引发了异常。”,行号为“31”,行位置为“52”。
  Source=PresentationFramework
  StackTrace:
   在 System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   在 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   在 System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   在 System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   在 System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   在 XFEToolBox.Views.Windows.MainWindow.InitializeComponent() 在 C:\Users\XFEstudio\Desktop\work\C#\GitHub\XFEstudio\XFEToolBox\XFEToolBox\Views\Windows\MainWindow.xaml 中: 第 1 行
  此异常最初是在此调用堆栈中引发的: 
    [外部代码]
内部异常 1:
IndexOutOfRangeException: Index was outside the bounds of the array.

And I believe that i did nothing before and after I upgrade my Visual Studio.

Thanks for your reading.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,191 questions
{count} vote

Accepted answer
  1. Hongrui Yu-MSFT 2,465 Reputation points Microsoft Vendor
    2024-08-19T07:00:35.6066667+00:00

    Hi,@Smith Tom.

    This happened because of regression of Setter.Value ContentProperty change.It appears that these changes have been reverted for inclusion in the RC1 build and will be reflected in RC1.

     

    There are two workarounds for now:

    1.Use global.json and pin the dotnet sdk version to 8. Something like below:

    
    {
    
      "sdk": {
    
        "version": "8.0.300"
    
      },
    
    }
    
    

    2.Use RC1 nightly builds - The builds which have the reverted changes included.

    Related links are as follows:

    https://github.com/dotnet/wpf/issues/9582


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.