Forum Discussion
WPF: Project doesn't find its own Classes ("tag not found in namespace")
Hi there,
I've got a problem that's driving me crazy:
c# WPF Custom Controls Project (NET 7), Base Namespace "UserControls". All the controls, styles and Converters existing in the project are in that namespace (I tripple checked, it's the only namespace used). All the controls and Converters are public classes.
In the project, there is a Class named "EqualityToBooleanConverter.cs"
Additionally, there is a Style file called Button.xaml. I need to use the aforementioned converter here, so I am referencing it like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UserControls;assembly=UserControls">
<local:EqualityToBooleanConverter
x:Key="ETBConverter" />
Intellisense does find the Namespace "UserControls", in fact, the namespace declaration AND the ressource declaration was done using intellisense.
BUT as soon as I compile the project, the following error pops up:
MC3074 - type "EqualityToBooleanConverter" does not exist in "clr-namespace:UserControls;assembly=UserControls"
I just don't get it, as I said, all the files are in the same project, and they are - as of now - all using the root namespace "UserControls". Everything is fine until I start compiling.
What I have tried so far:
- removing the "assembly"-part of the namespace-declaration
- changing the compile target from AnyCPU to x86 and back
- cleaning the solution
- creating a new solution, and re-adding all the files to it
Also noteworthy: The same problem occurs when I try using one of the Usercontrols in that project WITHIN the project itself (like: creating a Window.xaml, defining the local-namespace, and trying to add the control leads to the same error as soon as I compile).
I don't know what else could cause this...does anyone have any idea?
5 Replies
- plasmana1967Copper Contributor
Sneets , open up the project file and change the <RootNamespace> tag to hardcode the namespace instead of letting the IDE calculate the value.
- fizzplepopCopper ContributorGENUINELY thank you so much i was at my wit's end with this nonsense. I can now go to sleep thanks to you. I don't know who you are but you are genuinely my hero and saviour wherever you are in the world god bless you.
- PHenry9999Copper Contributor
Sneets FRUSTRATINGLY I'm running SMACK head first into this too. WORST thing about it is, I'm TRYING to learn how to use a new custom converter I WANT to create....and BOOM, SMACK into it. It really ticks me off to do everything exactly right...only to have it blow up in my face like this. Just when I think I'm learning, I waste HOURS on something that not only isn't my fault...but there is NO solution to! HUGELY FRUSTRATING.
- Diane445Copper Contributor
This is still an issue in .net8. What is strange is that intellisense offers the custom control as an option in autocompletion.
Our current workaround is to place the custom controls in their own project.
ETA : Microsoft knows since 2021 at least and won't fix : https://developercommunity.visualstudio.com/t/Custom-controls-no-longer-recognized/1418789?ref=native&refTime=1705074293151&refUserId=8f9b338b-f7b0-476b-85ce-3ae765e2ddd6
- AlchemyBlinkerCopper ContributorMan, I am sad to see this here with no replies so far... you have perfectly described the problem I am having as well. Only difference is that I am using .NET 6, not 7. I have also tried the things you have tried, and everything I could Google, but nothing has solved this problem for me. I guess I will go without custom components for now.