dotnet / dotnet/wpf

Misleading error message in .NET Core WPF

Open
#1,991 7 comments 3 reactions 0 assignees View on GitHub
Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

When you compile a WPF (on .NET Core 3) app with the following XAML, I get the error message

> Unknown build error, 'Could not find assembly ‘Extension, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’. Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.

```

```

It’s normal that I get a build error (the XAML is wrong; in particular, the binding should read “{RelativeSource FindAncestor, …”), but this build error is not helping me to figure out what’s wrong. In fact, my first thought was not that I did something wrong but that Visual Studio’s build chain somehow got broken.

Note that you get a better error message if you add a space in `RelativeSource ,` (notice the extra space). In this case, I get the error:

> ’ , AncestorType={x:Type Window}}’ is not valid. Markup extensions require only spaces between the markup extension name and the first parameter. Cannot have comma or equals sign before the first parameter.

That’s a good error description.

Also note that the code in the example above produces a better error description on WPF for the full .NET Framework. In this case, I get the error

> The character “,” is unexpected at this position.

which is an excellent description of the problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.