Search code examples
c#wpfxamlresourcedictionary

The name ... does not exist in the namespace


This problem is pretty much the same as this one. However my problem is that I get this error but it does compile run and find it find.

My XAML with the error is a resource dictionary (in a different project) and it is trying to use an enum called MainViewMode in a style. I have inherited the code from a previous team so I do not know why it was originally written like this but the xaml consists of all the path data for icons (using the <geometry> tag) as well as all of the Styles. I don't think this is relevant to the problem but just thought I would highlight it anyway.

As I said, when the program runs it does work fine however the designer mode is not working on one of the forms I need to modify and it is making it really annoying.

xmlns:cenum="clr-namespace:ABC;assembly=DEF"
...
  <Style x:Key="MainViewToggleButtonStyle" TargetType="ToggleButton">
     <Setter Property="SnapsToDevicePixels" Value="true" />
     <Setter Property="OverridesDefaultStyle" Value="true" />
     <Setter Property="CommandParameter" Value="{x:Static cenum:MainViewMode.Overview}" />
...
</style>

I have a resource dictionary, it calls an enum in a different project and says that it can't find it. It does however find it at runtime and work fine. The main issue is that the designer doesn't load for any forms using this resource dictionary.


Solution

  • I believe your problem is that your namespace is incorrect. Take a look at the top answer in the question you linked to and notice how they have the example namespace. Since you're getting the enum from a different project you will also want to add that project as a reference.

    To get the namespace right find the folder that the enum class is in, or if it's not in a folder just the project name. The namespace will be like one of the following,

    If it's in a folder try something like this

     ProjectName.FolderName;assembly=ProjectName
    

    If not try something like this

    ProjectName;assembly=ProjectName