Expression Blend: Getting error "XXX" does not exist in the namespace "XXX", but not in VS2008
Asked Answered
M

5

30

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?

Melancholy answered 30/11, 2009 at 18:25 Comment(1)
This problem exists in Blend 4, and will likely continue. There is a bug in the Blends assembly searching algorithm. Rather than looking for assemblies in the SELECTED Platform configuration, it looks for them in the DEFAULT Platform configuration. See Scott Bilas's answer for details.Forb
F
30

I had the same problem with Blend 2, on a Windows Vista 64.

I normally compile my solution in VS2008, with a "Debug - x86" target on all my projects, so that it's compatible with some other 32 bits-only projects.

It looks like Blend loves the "Debug - Any CPU" targets. I basically changed my configuration manager so that it targets Any CPU platforms instead of x86.

So...

  • Open your solution in Blend and in VS2008
  • In VS2008, choose the menu Build -> Configuration Manager
  • Ensure that your solution configuration has a "Debug - Any CPU" for all projects
  • Compile in VS2008
  • tadaaaa Your blend project should update and remove those errors... well it did for me

I did the opposite to verify if it was really that, and it seems yes... I simply reverted the solution changes back to Debug - x86, cleaned everything, and rebuilded, and I was still back with the error "Does not exist [...]"

As for the "Why?"... I don't know, but at least it works now!

Fredric answered 10/12, 2009 at 23:7 Comment(3)
Perfect! Just the presence of the Any CPU configuration is not enough. Indeed, having Visual compile the Any CPU config seems to fix Blend. Hope this gets fixed eventually...Melancholy
Thank you, thank you, thank you! This is why I love StackOverflow! My problem exactly. +1 Would upvote more if I could.Scaremonger
Thanks - what were MS devs smoking? 32bit interop on 64bit machine + Blend? You are screwed... but thanks for the info!Gastronomy
V
16

The problem is in Blend assembly search path. By default it search classes in assemblies in folder "bin\Debug"! But if you set in project configuration target x86 then your output path will be "bin\x86\Debug". So you need to change your output path in visual studio to "bin\Debug" and Blend will find all your classes!

Valrievalry answered 22/11, 2010 at 9:57 Comment(4)
This was the key to solving my problem with VS2010 and Blend 4. If you need x86 Platform, you can still specify that but have an Any CPU configuration that builds to bin\Debug.Maitund
I've had the same problem in VS 2012, changing the build folder from bin\x86\Debug to bin\Debug helped, thanks!Whitson
I had just checked out a solution and compiled it only in the Release configuration. Once I compiled the solution in the Debug configuration, it worked.Coffeepot
Problem still exists (and solution still works) in Blend 5 and VS2012.Oyer
C
13

I think that Blend uses the default config/platform defined in the project file. You should be able to fix this by editing it with a text file. If you look in your .csproj file, you should see something like this:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    ...

Change that AnyCPU to x86 and it should work the way you expect.

Cher answered 17/9, 2010 at 0:23 Comment(3)
You nailed it. The issue is that Blend erroneously reads the default Platform from the project file, not the selected Platform. Regardless of the Selected config used to compile, Blend still configures itself to look for assemblies in the default Platform folder. This can result in Blend looking for assemblies in the wrong folder.Forb
This was the correct answer for me. We had remvoed the AnyCPU targets but forgot to change the project's default platform. visual studio would build correctly, but blend choked.Dol
After making the change, switch to Release, compile, switch to Debug, compile, and the error goes away.Urease
J
1

You can also fix this "Any CPU/x86" issue by changing the output path for all your projects to bin\Debug instead of bin\x86\Debug (same for Release).

Joannjoanna answered 7/10, 2011 at 9:49 Comment(0)
O
1

I also had an error like this. But for me it helped to rebuild the project directly in Blend without using Visual Studio.

For those who don't know: You can do this in Blend in the Menu by clicking on "Project" -> "Rebuild Project". At least in Blend 4.

Offshoot answered 15/12, 2011 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.