Using VS2012 working on a VB.NET WPF application. I have a simple MusicPlayer tutorial app I am using to learn WPF. I am converting a C# version of the tutorial to VB.NET step by step.
It has 2 classes in the app that are both under the same namespace. I am able to reference the namespace in the XAML but when I try to reference the class object in XAML I get an error and I am not able to compile.
Strange thing is that the IntelliSense works fine with both referencing the namespace via the xmlns:c= tag and also when typing the class object using <c:
But the object is underlined and errors are generated trying to build or work in the designer.
The .vb class files are in a folder called \Controls. The Main project Root Namespace is intentionaly left blank. The class is coded like this...
Namespace MusicPlayer.Controls
Public Class UpdatingMediaElement
.... code here
End Public
End Namespace
The xaml looks like this
(namespace defined in the <Window >
tag
xmlns:c="clr-namespace:MusicPlayer.Controls"
(object defined in a <Grid>
)
<c:UpdatingMediaElement Name="MyMediaElement" />
(error displayed) The name "UpdatingMediaElement" does not exist in the namespace "clr-namespace:MusicPlayer.Controls".
Not sure what is wrong or how to fix it?
Try verifying your assembly references. If you have a yellow exclamation mark on the project references there's a problem there and you'll get all kinds of errors.
If you know the project reference is correct, check the Target framework. For instance, having a project using the 4.5 framework reference a project with 4.5.2 framework is not a good combination.
Add an empty constructor for your view model and rebuild solution. I tried so many solutions not working but this solved for me.
Adding to the pile.
Mine was the assembly name of the WPF application was the same assembly name as a referenced dll. So make sure you don't have duplicate assembly names in any of your projects.
I'm also having a lot of trouble with this one! Intellisense helps me complete the namespace and everything, but the compiler cries. I've tried everything I found in this and other threads. However in my case what helped in the end was writing something like this: xmlns:util="clr-namespace:LiveSpielTool.Utils;assembly="
Leaving the assembly name empty. No idea why. But it was mentioned here. I must add I am developing an assembly, so the assembly attribute might make sense. But entering the assembly name did not work. So weird.
I've seen this issue go away by clearing the Xaml Design Shadow Cache. I had the issue with Visual Studio 2015 Update 1.
In Visual Studio 2015 the Cache is located here:
Process:
And voila no more namespace errors.
Also try to right click on your project->properties and change Platform target to Any CPU and rebuild, it will then work. This worked for me