Getting "The name xxx does not exist in the namespace xxx" only in Blend (fine in VS2008)

Proposed Getting "The name xxx does not exist in the namespace xxx" only in Blend (fine in VS2008)

  • Monday, November 30, 2009 6:29 PM
     
     

    I am trying to use Blend 3.0 to edit a project that contains some WPF controls. This project already compiles and runs fine from Visual Studio 2008.

    In Blend however, I'm getting mysterious errors that make no sense:

    For example, I have a class that derives from Control :

        namespace Company.WPFControls.SearchTextBox
        {
            public class SearchTextBox : Control
            {
                ...
            }
        }

    And I try to use it in a resource, in the same assembly, to assign a style:

        <ResourceDictionary
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:Company.WPFControls.SearchTextBox"
       
            <Style TargetType="{x:Type local:SearchTextBox}">
                ...
            </Style>
        </ResourceDictionary>

    I get the following error in Blend:

    The name "SearchTextBox" does not exist in the namespace "clr-namespace:Company.WPFControls.SearchTextBox".

    I've tried specifying the assembly name, by adding ;assembly=Company.WPFControls but it doesn't remove the error.

    Is there any way to fix this or at least figure out where the problem comes from?

All Replies

  • Monday, November 30, 2009 9:35 PM
     
     
    Did you right click on the project that uses the SearchTextBox and add a reference to the SearchTextBox project?
  • Tuesday, December 01, 2009 1:15 AM
     
     
    No, but the SearchTextBox class is in the same assembly as the resource dictionary. And the same solution compiles and runs perfectly fine in VS2008.

    Also, this is just one example inside this assembly among many other custom controls. In fact, it looks like every single xmlns:xx that refers to a namespace that's local to that assembly gives the above error.

    I previously had another problem with this solution because my projects did not have the platform "Any CPU" (I just had "x86") and Blend could not resolve any referenced assemblies. After adding the "Any CPU" platform, that fixed the problem.
  • Tuesday, December 01, 2009 6:20 AM
     
     
    Ah, yes, thanks for bringing that up.  I get screwed by the platform type all of the time in VS.  Except that I have to set all of mine to x86.  :)
  • Tuesday, December 01, 2009 11:50 AM
     
     
    Strange...

    One thing I noticed about your naming convention is the last part of the namespace is identical to the class name. I have run into problems with this before and try no longer to use it.
    If you were to reference this class in code under your naming system it would be Company.WPFControls.SearchTextBox.SearchTextBox.

    Are you able to amend the namespace to make it completely distinct from the class name SearchTextBox?

    e.g. from
    Company.WPFControls.SearchTextBox
    to say
    Company.WPFControls.STB

    This would change the xaml in the resource dictionary
    from
    xmlns:local="clr-namespace:Company.WPFControls.SearchTextBox"
    to
    xmlns:local="clr-namespace:Company.WPFControls.STB"

    The style TargetType markup would not need to change.

    Does this help?

  • Tuesday, December 01, 2009 5:09 PM
     
     
    Wiping the project's platform configurations and recreating them from scratch seems to have fixed the problem. So I guess its another symptom of the 'Any CPU' configuration. Maybe that configuration must be first in the csproj...
  • Tuesday, December 01, 2009 5:44 PM
     
     
    Spoken too soon, the problem is back after a rebuild from Visual Studio :(

    Andrew, I tried changing the namespace names so they don't conflict with my class names, but that didn't fix the error either.
  • Tuesday, December 01, 2009 7:09 PM
     
     

    Hi Anthony,

    Are the resources within the Generic.xaml file under the themes folder? This xaml file would hold also have a reference to the namespace xmlns:local="clr-namespace:Company.WPFControls.SearchTextBox".

    You could investigate the problem in Blend by adding the resources in as a merged dictionary within the window that is using the control. Highlight the Window root, open up the resources pane, click on the window within that and then right click and select link to Resource Dictionary. This inserts the merged dictionary code within the window, eg  <Window.Resources>
      <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Themes/Generic.xaml"/>
       </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
     </Window.Resources>

    In the case above as the generic.xaml is referenced the window doesn't need this reference or a refence to the namespace even.

    I am not sure exactly how the stateless controls hook into the resource but I think that either the app.xaml or generic.xaml (more usually the latter) has to have a reference to the namespace and resources.

    I think for the resource dictionary to work the control code needs to build and yet this cannot happen unless the resource dictionary is up and running a kind of chicken or egg situation.

    If this draws a blank perhaps you can post a cut down example that reproduces the problem in blend.

    Interesting..

    regards

    Andrew

  • Tuesday, December 01, 2009 8:55 PM
     
     
    These symptoms sound very similar to something I'm dealing with on my end.  Namespace errors on particular xaml pages, while no issues at all in VS2008.  That, combined with the fact it was working fine until a day or two ago.  We cannot find the particular change that may have triggered this.  A reformat of the affected dev environment proved unfruitful.  Very curious if others have ran into this recently.

    Error message:  The name "xxx" does not exist in the namespace "clr-namespace:XXX"

    Oddly enough, a coworker loads up fine.  Could this be an issue particular to 64-bit systems?  I'm running a 64-bit Windows 7 box.
    Purkiss
  • Wednesday, December 02, 2009 7:24 PM
     
     

    I don't think this is a 64 bit issue as I have run Control/Resources code on win 7 64 bit and xp 32 bit (with the Any Cpu state) without problem.

    In terms of cleaning out a solution do you use the clean solution option in VS2008 solution explorer or do you actualy delete the contents of the bin\debug and obj folders by hand. Sometimes I also take out the x.suo file which is in the same place as the x.sln file. This may mean exiting VS2008 altogether.

    It is very strange that your coworkers setup works ok. Guess all the patches are up to date?

    Thats me out of suggestions now without knowing your exact project setup which I can understand is not practical to share. Perhaps you can pair the project down while still retaining the behaviour so something can be posted here?


    regards

    Andrew

  • Monday, July 12, 2010 2:32 PM
     
     Proposed Has Code

    Hi Anthony,

    We already had the same problem, and we solved it adding the assembly information to the clr-namespace.

    xmlns:local="clr-namespace:Company.WPFControls.SearchTextBox;assembly=Company.WPFControls"

    I hope this can be usefull.



     

    • Proposed As Answer by noise goblin Friday, February 22, 2013 3:00 PM
    •  
  • Wednesday, May 18, 2011 10:16 PM
     
     

    I am just wondering if this is being addressed as it is a problem in Blend 4 as well. 

     

    See StackOverflow for a detailed discussion on what the root cause.

    http://stackoverflow.com/questions/1821493/expression-blend-getting-error-xxx-does-not-exist-in-the-namespace-xxx-but

  • Friday, February 22, 2013 3:01 PM
     
     
    I had this problem on VS 2012 on a Windows 8 project when I moved some code into a portable class library, but actually adding the assembly info resolved the problem (actually auto-completion does it for you)

    Goblin Dice Roller for your RPG games!