Visual Studio 2022: XDG0047 error – The following type was expected: „Object“ in Xaml editor

Veröffentlicht von

Strange error in WPF projects after upgrading to Visual Studio 2022.

Some weeks ago, I updated from Visual Studio 2019 to 2022. Since then, I am getting a strange error in the Xaml editor.

Error	XDG0047	The specified value cannot be assigned. The following type was expected: "Object".	

This results in the preview of the view not working and just showing „Invalid Markup“.

So far I was not able to find out what seems to be the problem. I suspect a bug in the Xaml editor, as the project compiles and runs perfectly.

8 Kommentare

  1. Same problem after enabling „IntelliSense“ at studio.
    Version is 17.1.1.
    I don’t know, how to fully disable IntelliSense for xaml 🙁
    And in project I use lib GalaSoft.MvvmLight.

    When I open VS 2019, all works perfect.

  2. I think the solution, for now, is to have the preview and not to lose the IntelliSense, so make a design DataContext on Xaml, and in the behind code, set the DataContext to the ViewModel. You won’t get the error, and the design preview works.
    XAML:
    xmlns:viewModel=“clr-namespace:CustomProject.ViewModels“
    d:DataContext=“{d:DesignInstance Type=viewModel:ViewModel, IsDesignTimeCreatable=False}“

    BehindCode

    using CustomProject.ViewModels;

    // in the Constructor
    public CustomView()
    {
    InitializeComponent();
    DataContext = new ViewModel();
    }

    I hope this comment will be helpful because I suffered from this error!

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht.