dotnet / dotnet/wpf

Problem with loading component in WPF project

Open
#1,688 5 comments 0 reactions 0 assignees View on GitHub
.NET Framework Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

@ds1709 commented on [Wed Aug 14 2019](https://github.com/dotnet/core/issues/3189)

# Issue Title

Problem with loading component in WPF project by calling `Application.LoadComponent(Uri)`.

# General

Version: .NET Core 3.0.0 Preview 8.
OS: Windows 10.
Visual Studio: 2019 16.2.1.
Project Sdk: Microsoft.NET.Sdk.WindowsDesktop.

In the next scenario `Application.LoadComponent(Uri)` throws exception.
Created a simple WPF application with classe `App` and `MainWindow`.
```xml


WinExe
net472
true
1.2.3.54

```
```xml



```
```csharp
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var uri = new Uri("/WpfApp1;component/mainwindow.xaml", UriKind.Relative);
var window = LoadComponent(uri); // Exception: Cannot register duplicate Name 'Foo' in this scope.
}
}
```
Key points here are `` in csproj file and named element in MainWindow xaml file. When it's declared, the window code generator creates code like `System.Uri resourceLocater = new System.Uri("/WpfApp1;V1.2.3.54;component/mainwindow.xaml", System.UriKind.Relative);`. As you can see, there's version element in URI. But when `` is not declared, or version is declared in code ([assembly:AssemblyVersion("...")]), then version is missing in generated URI, and exception is not throwing. Same for UserControls.

---

@carlossanlop commented on [Wed Aug 14 2019](https://github.com/dotnet/core/issues/3189#issuecomment-521354854)

> `// Exception: Cannot register duplicate Name 'Foo' in this scope.`

@ds1709 thank you for the details.

@grubioe can you help with this issue? Feel free to transfer it to the dotnet/wpf repo if necessary.

---

@grubioe commented on [Wed Aug 14 2019](https://github.com/dotnet/core/issues/3189#issuecomment-521366474)

@diverdan92 - this might be more related with VS, maybe in the project system, the code generator. Can you route to the right team?

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.