15

While porting a WPF project from .NET Framework to .NET Core I ran into a problem with the XAML-Designer in VS2019 v16.3.10. It keeps throwing XDG0062 errors when I try to use EventSetter in styles. The code compiles and runs fine, but the errors cause the concerned elements in the designer to be replaced by a red circle with an X, making designing a UI rather hard. The same XAML works fine in a .NET framework 4.7.2. project.

To track down the problem I made a VS minimal project (WPF .NET Core) from scratch and the problem occurs here as well (see errors and code below). It seems to be caused by the use of EventSetter in styles - unfortunately I have no clue why. Google yielded one mention of the problem without a solution, Stack Overflow has one topic on this error code, however, the solution suggested there (deleting VS cache) didn´t help. Deleting the EventSetter line removes both error messages.

Does anyone have a suggestion to solve this?

Full error messages:

Line 9: XDG0062 Non-NULL value required for "EventSetter.Handler"

Line 12: XDG0062 Value cannot be null. (Parameter 'typeDescriptorContext')

XAML:

<Window x:Class="XDG0062_test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:XDG0062_test"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <Style TargetType="TextBox">
            <Setter Property="Height" Value="30"></Setter>
            <Setter Property="Width" Value="130"></Setter>
            <EventSetter Event="GotFocus" Handler="TextBox_GotFocus"/>
        </Style>
    </Window.Resources>
    <Grid>
        <TextBox HorizontalAlignment="Left" Margin="70,100,0,0"
                 Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top"/>
    </Grid>
</Window>

C#:

using System.Windows;
namespace XDG0062_test
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Beep");
        }
    }
}
Toni
  • 1,555
  • 4
  • 15
  • 23
BBockisch
  • 175
  • 1
  • 1
  • 3
  • I can reproduce this error message and it can build and run, but the 'Handler="TextBox_GotFocus"' doesn't work. I try to find some documents to analysis this. But, unfortunately, I cann't find an appropriate way to solve this error message. So , I suggest you can go to the [Developer Community NET/Visual Studio](https://developercommunity.visualstudio.com/spaces/61/index.html) and report your issue. – Yohann Nov 27 '19 at 03:06
  • Thank you. I followed your advice and reported it, the issue wil be fixed: _A fix for this issue has been internally implemented and is being prepared for release_ I´ll update when it´s released. – BBockisch Dec 05 '19 at 07:23
  • @BBokisch do you have a link to the issue? It is stiil there in VS16.8.5 – RudolfJan Feb 16 '21 at 12:03
  • https://stackoverflow.com/questions/52606565/wpf-designer-issues-xdg0008-the-name-numerictextboxconvertor-does-not-exist The solution in this topic worked for me. – RudolfJan Feb 16 '21 at 12:07

2 Answers2

16

I solved this in VS2019 by deleting the folder .vs/$(SolutionName)/DesignTimeBuild, so I can keep VS configuration/explorer/tabs, which are lost when deleting the whole .vs.

The design build is somehow corrupted and needed to be updated. This forces Visual studio to have a fresh design build.

Soleil
  • 6,404
  • 5
  • 41
  • 61
  • did not understand why, but it worked for me. – surpavan Apr 08 '21 at 10:02
  • 2
    @surpavan because the design build is somehow corrupted and needed to be updated. This forces to have a fresh design build. – Soleil Apr 08 '21 at 12:12
  • 3
    Did not work on `VS 2022 17.0 Preview 4.1`. – Toni Sep 22 '21 at 16:39
  • Try closing and opening VS before deletion, for it seemed to reset the design surface anyway. That worked for me on a different but similar xaml (XDG0045) error on VS2022 .Net 6. – ΩmegaMan Nov 06 '21 at 15:29
  • Didn't work on VS 2022 17.0.2 Professional, .Net 4.8.04084, This error doesn't happen under VS 2019, but another, less informative error does. But occasionally the error does disappear, but we have no idea why. – Owen Godfrey Dec 10 '21 at 00:51
0

Microsoft have released the fix mentioned in comments. I can confirm that my issue is indeed resolved as of VS 2019 16.5.0

BBockisch
  • 175
  • 1
  • 1
  • 3
  • 3
    I have VS 2019 16.6.1 and still got this error. But I have Community version. Maybe they fixed for Enterprise or Professional editions. – Petr Havlát Jun 09 '20 at 14:14
  • I just started having this issue on 16.6.2. I hadn't had this issue before. I'm using VS Professional. – pfthroaway Jun 19 '20 at 03:10
  • Can confirm that my original issue is still fixed as of 16.6.2 (Community). – BBockisch Jun 22 '20 at 07:10
  • I've got 16.6.5 Community, and I see this error in `DataTemplate` > `DataTrigger` elements. I'm also using the "plus" (+) syntax to reference enums, so perhaps that has something to do with it. `` – skst Jul 22 '20 at 21:02
  • 1
    Using 16.7.0 - still have this error message on occasion. This is valid XAML code: `` which produces the error message. If I take out the "{x:Static...}" part the message vanishes: `` Overall, I have to say that the XAML editor in VS2019 is a piece of software from Microsoft with the most errors – okieh Aug 07 '20 at 07:40
  • I even get this error in something simple like `Window Style="{StaticResource windowMain}"` which was no problem in .NET Framework but now throws the error in .NET 5. The App compiles and runs fine though. And before someone asks, the style `windowMain` is targeted to `Window`... VS Community 16.8.3. – Daap Dec 14 '20 at 00:16
  • Get this error message in Visual Studio 16.8.5 using .Net 3.1 the code runs fine, so no idea what the issue is. – RudolfJan Feb 16 '21 at 12:01