the name <...> does not exist in the namespace clr-namespace <...>

98,598

Solution 1

Every time it happend to me i just restarted visual studio, re-built the solution and it worked just fine.. can't say why

Solution 2

In addition to the "does not exist in the namespace" message, I was also getting a message from the designer that it could not display the window for x64 and ARM targets.

I have just found that switching the build to x86 mode, doing a rebuild solution, then switching back to x64 mode and then rebuilding again fixes [both] problems.

Simply rebuilding the x64 solution did nothing.

Solution 3

What I found that helped (especially if this error occurs in App.xaml) is to comment out the reference(s) that gives you trouble, rebuild, then uncomment. I think what this does is allows the entire project to actually build instead of stopping the build at the error.

From what I can gather, the app is trying to build the files in a certain order, so when App.xaml or presumably any other class file errors in a reference, the file that is causing the error hasn't been compiled correctly, hence why it doesn't find the file in that namespace.

Solution 4

This is what worked for me on Visual Studio 2012 (Update 3).

  • Restart Visual Studio
  • Add current assembly to namespace declaration xmlns:framework="clr-namespace:TimeRecorder.Framework;assembly=MyAssembly
  • Build -> Build Solution

Solution 5

Rebuild your solution (sometimes clean then build works better). Then look at your error list, scroll to the very bottom, and it will most likely indicate an error that is not allowing your assembly to compile, and the XAML compiler is most likely using a cached version of the assembly, not the new one you mean to build.

Share:
98,598
ardal
Author by

ardal

Updated on February 05, 2022

Comments

  • ardal
    ardal about 2 years

    I have a small WPF application which used to compile just fine but is not anymore. I can't really say at which point it stopped building. It just worked fine one day, and the next it's not.

    Here's the project structure:

    enter image description here

    There is no other projects or external references other than standard .net dlls.

    Here's the user control where the problem originated:

    <UserControl x:Class="TimeRecorder.HistoryUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:TimeRecorder.ViewModel"
             xmlns:framework="clr-namespace:TimeRecorder.Framework"
             mc:Ignorable="d" Height="Auto" Width="Auto" Padding="5">
    <UserControl.Resources>
        <local:HistoryViewModel x:Key="ViewModel"/>
        <framework:BoolToColorConverter x:Key="ColorConverter"/>
    </UserControl.Resources>
    <StackPanel DataContext="{StaticResource ViewModel}">
    

    And here's the error I get: http://i48.tinypic.com/5u1u8w.png

    Please note that this is not just the one file in the screenshot, but all references I add in similar fashion in xaml in all user control/window files in this project.

    So the file is there, the namespace in the file is correct, the namespace/class name in the xaml file is (to my understanding) correct. I get intellisense when I type in the xaml so it finds the files ok then but not when it compiles.

    The most common solution for this in other posts has been the .net framework version. It is currently set to .Net Framework 4 for both my main and test project. The full version not the client profile.

    Here's what I think I messed up: In the configuration manager, both projects have their Platform set to Any CPU, but at one point when trying to solve this I noticed that the main project was set to x86 and the test project was set to Any CPU. So I added Any CPU manually for the main project in the configuration manager. However I honestly don't know if I did this correctly or even if I should do it. So as an additional question, is there a way I can reset the configuration manager to its default state? Will this have anything to say for the main problem? I don't know if the main project was always set to x86 or not or if I somehow changed it to x86 and then it broke. As mentioned this project was compiling just fine for a while.