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

前端 未结 25 1016
名媛妹妹
名媛妹妹 2020-11-28 04:59

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 t

相关标签:
25条回答
  • 2020-11-28 05:45

    Just run code analysis from Build menu

    0 讨论(0)
  • 2020-11-28 05:46

    I found that running the command "Run Code Analysis" re-builds everything and almost always fixes the problem (right click project > Analyze > Run Code Analysis). This also generally re-builds the resource files also so that strings, etc. can be found.

    0 讨论(0)
  • 2020-11-28 05:49

    Here's a weird example of a similar thing:

    <UserControl x:Class="Gtl.Ui.Controls.WaitControl"
             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:controls="clr-namespace:Gtl.Ui.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="120" d:DesignWidth="120"             
             Background="Transparent">
    ...
    </UserControl>
    

    will compile (VS2013).

    <UserControl x:Class="Gtl.Ui.Controls.WaitControl"
             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:controls="clr-namespace:Gtl.Ui.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="120" d:DesignWidth="120"             
             Background="Transparent"
             IsVisibleChanged=onIsVisibleChanged>
    ...
    </UserControl>
    

    produces the error "type Ui not found in Gtl.Ui.Gtl" (and I assure you the handler method exists in the code-behind). The work-around is to add the handler in the class constructor, but c'mon Microsoft, wtf is going on?

    0 讨论(0)
  • 2020-11-28 05:49

    This error usually occurs when project was not build successfully during the last build.

    Step-1) First remove all the error causing code from the XAML or .cs file and build & start the project by pressing F5.

    Step-2) Add add your error causing code in XAML one by one.

    0 讨论(0)
  • 2020-11-28 05:50

    Tried all solutions on this thread but none worked. It turned out to be cause by the solution configuration. My WPF app was set to build for X64 because of some native dependencies that require it but the solution configuration was still set to AnyCPU for the project. Creating a new X64 configuration for the project in the solution configuration manager allowed the XAML designer to finally recognize my type and namespace.

    0 讨论(0)
  • 2020-11-28 05:52

    None of the solutions worked for me. I fixed it this way:

    • Remove the dll of the library from the References
    • Download the source code of the library (instead of just the dll file)
    • Build the library's project to get a new dll file
    • Add the new dll file to the References of the main project
    0 讨论(0)
提交回复
热议问题