wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Type or namespace name 'Ui' does not exist in the namespace when I set a name to a wpf-ui component in xaml

Open bryonac99 opened this issue 1 year ago • 9 comments

Describe the bug

Hi, I'm using wpf-ui on my wpf app. It's working, but when I write x:name or name to a component in the xaml it gives me the following error: The type or namespace name 'Ui' does not exist in the namespace 'Client.Wpf' (are you missing an assembly reference?) If I cancel the name or x:name the error will go away.

To Reproduce

Set name or x:name to a wpf-ui component.

Expected behavior

x:name in wpf-ui component working

Screenshots

No response

OS version

Windows 11

.NET version

8.0

WPF-UI NuGet version

3.0.4

Additional context

No response

bryonac99 avatar Jun 25 '24 08:06 bryonac99

It looks like there is something else in your project whose namespace has *.Client.Wpf.*. Try global::Wpf.Ui or consider changing some names or using's in your files.

pomianowski avatar Jun 25 '24 12:06 pomianowski

It looks like there is something else in your project whose namespace has *.Client.Wpf.*. Try global::Wpf.Ui or consider changing some names or using's in your files.

How do I set global:Wpf.Ui namespce in xaml? It's working on codebehind, but I need it in xaml for x:Name.

bryonac99 avatar Jun 26 '24 09:06 bryonac99

To understand the error, it would be best if you sent the entire code that would allow to reproduce the error.

pomianowski avatar Jun 26 '24 10:06 pomianowski

In xaml: xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
<ui:Button x:Name="addDeviceBtn" HorizontalAlignment="Left" Appearance="Success" Command="{Binding AddDeviceCommand}" Content="Add Device" Cursor="Hand" Icon="{ui:SymbolIcon Add24}" /> Error CS0234: The type or namespace name 'Ui' does not exist in the namespace 'MyApp.App.Wpf' (are you missing an assembly reference?) If I remove x:Name the error goes away

bryonac99 avatar Jun 26 '24 10:06 bryonac99

In xaml: xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" <ui:Button x:Name="addDeviceBtn" HorizontalAlignment="Left" Appearance="Success" Command="{Binding AddDeviceCommand}" Content="Add Device" Cursor="Hand" Icon="{ui:SymbolIcon Add24}" /> Error CS0234: The type or namespace name 'Ui' does not exist in the namespace 'MyApp.App.Wpf' (are you missing an assembly reference?) If I remove x:Name the error goes away

Would be better full .csproj in zip or repo

pomianowski avatar Jun 26 '24 10:06 pomianowski

In xaml: xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" <ui:Button x:Name="addDeviceBtn" HorizontalAlignment="Left" Appearance="Success" Command="{Binding AddDeviceCommand}" Content="Add Device" Cursor="Hand" Icon="{ui:SymbolIcon Add24}" /> Error CS0234: The type or namespace name 'Ui' does not exist in the namespace 'MyApp.App.Wpf' (are you missing an assembly reference?) If I remove x:Name the error goes away

Would be better full .csproj in zip or repo

Unfortunately I can't share this project..

bryonac99 avatar Jun 26 '24 10:06 bryonac99

You don't have to send the project, just the minimal code that causes the error

pomianowski avatar Jun 26 '24 16:06 pomianowski

I ran into this now, with a project being named xyz.Client.Wpf - and also xyz.Client.UI.Wpf - I renamed the project and root namespaces to xyz.Client.Windows (getting rid of the Client and Wpf parts, and it worked.

Try renaming the project so it doesn't end/have .Wpf, same for all the namespaces

nabeelio avatar Aug 09 '24 01:08 nabeelio

renaming the project so it doesn't end/have .Wpf

I was going around in circles for hours until I found this.

I had used 'Appname.Wpf' / Appname.Wpf.csproj and couldn't get a clean compile. Change to Appname.UI and problem solved!

dcog989 avatar Jul 20 '25 15:07 dcog989

Today, I ran into this bug as well. I cannot rename my projects. Is there a plan for fixing this bug?

jstavarek avatar Dec 20 '25 14:12 jstavarek

This is not WPF-UI issue, but rather how .NET works -- and I really hate partial namespace referencing.

Unfortunately it seems it is not possible to specify global:: in xaml nor in the generated .g.cs files. When I stumbled upon this issue, I just renamed my csproj to .WpfUI.

This issue should be addressed by MS WPF team rather than pomianowski.

luca-domenichini avatar Dec 20 '25 16:12 luca-domenichini

I'm guessing https://github.com/dotnet/wpf/pull/7196 would fix this on the WPF side, but I wouldn't be too optimistic they'll merge that any time soon.

(I tried to use the supplied binary, but it's incompatible with the .NET 10 SDK, and probably would only work with .NET 7. If someone else wants to try it, placing

    <PropertyGroup>
    <_PresentationBuildTasksAssembly>$(MSBuildProjectDirectory)\PresentationBuildTasks/PresentationBuildTasks.dll</_PresentationBuildTasksAssembly>
    </PropertyGroup>

in your csproj and then putting that DLL in a PresentationBuildTasks subdir in your project should do. Someone more adventurous could try building a newer version of the DLL…)

chucker avatar Dec 24 '25 12:12 chucker