Question

I have a project in VS2010 that uses XAML and now I need to load it into Expression Blend 4. The project builds and runs in VS2010 and this is the first time it has been loaded into Blend. It DOES build and run in Blend even though the members are not recognized.

Why is the Scale property not recognized and why does it show up as an error when it functionally works?

EDIT Although this builds and runs, the XAML is not displayed graphically in Blend and so cannot be modified by a non-technical user.

In a number of the .xaml files that contain references to usercontrols there is an attribute that is not recognized by Blend with the error:

The member "XXXX" is not recognized or is not accessible

The property exists in the .cs code behind file and in each case the error message is the same.

I've looked at a lot of possible answers to this on the internet but none of them is a solution. The referenced items are not read-only. The various classes and properties are Public. I've also added the following WPF reference into the .csproj file, which was missing.

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

In the following code, the Scale attribute is not recognized even though it exists as a property in the user control.

Here is the UserControl in MyLogo.xaml:

<UserControl x:Class="NamespaceX.NamespaceY.UI.Shapes.MyLogo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="132" Width="105">
<Canvas>
    <Canvas.LayoutTransform>
        <ScaleTransform x:Name="st" CenterX="0" CenterY="0" />
    </Canvas.LayoutTransform>
    <Image Source="/Client;component/Images/MyLogo.png"/>
</Canvas>

Here is the code behind in MyLogo.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NamespaceX.NamespaceY.UI.Shapes
{
/// <summary>
/// Interaction logic for MyLogo.xaml
/// </summary>
public partial class MyLogo : UserControl
{
    public double Scale
    {
        get
        {
            return st.ScaleX;
        }
        set
        {
            st.ScaleX = value;
            st.ScaleY = value;
        }
    }

    public MyLogo()
    {
        InitializeComponent();
    }
}
}

In my Navigation.xaml file I have this:

<UserControl x:Class="NamespaceX.NamespaceY.UI.UserControls.Navigation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shape="clr-namespace:NamespaceX.NamespaceY.UI.Shapes"    
Height="185" Width="1280" Loaded="UserControl_Loaded">
<FrameworkElement.Resources>
    <ResourceDictionary Source="../Resources/Main.xaml" />
</FrameworkElement.Resources>
<Canvas>
    <shape:MyLogo Scale="1.2" Height="181.483" Canvas.Left="38" Canvas.Top="4" Width="188" />
    <StackPanel Canvas.Left="205" Canvas.Top="-2" Width="1062">

    </StackPanel>
</Canvas>

Was it helpful?

Solution

Here's the solution. In the application's .csproj file, change this:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>

to this:

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

Do not be fooled by the fact that Visual Studio reports that you are running in AnyCPU more in the configuration manager. You must hand-edit the .csproj file.

OTHER TIPS

They are related in the fact that changing the platform changes the cached assemblies. The accepted answer is not acceptable.

This is what I recommend:

  1. Close all files
  2. Clean the solution
  3. Rebuild the solution

The affected XAML should now be clear of build errors.

This works for me, your results may vary.

Changing the build properties of the project to 'Any CPU' solved the problem for me. I still can't understand how that is related to the problem. But of course it did the magic.

As others have said, changing the target from x64 to AnyCPU fixes the errors in the designer, bizarre as this seems.

I found the following on the Visual Studio Forum:

(Q) Design view is unavailable for x64 and ARM target platforms when the document contains custom elements (XAML with a user control, for example).

(A) Starting with Visual Studio 2015, we have enabled you to design/author your XAML even when you target anything but x86. Visual Studio 2015 Update 2 should bring together several fixes and changes to have this experience work even better.

However, it is worth noting that we will not be able to execute any code you might have written in the designer when the project is targeting anything but x86. This is because of the restriction that an x86 process (which the XAML designer is) cannot run ARM or x64 code. You should be able to view and edit all of the XAML on the page, with any custom types replaced with replacements to preserve the WYSIWYG experience as much as possible (and switch to x86 when you really care about running the code in the designer).

I had the same problem on Silverlight turns out it was the namespace I had on my user control was too long, I just made it shorter and it works. Hope it helps!

I was able to reproduce / fix this problem consistently with a vb.net project in VS2012. In Project ... Properties ... Compile ... Target CPU is set to AnyCPU (default). Everything works fine.

Change the Target CPU to x64, Save and Build

Close and reopen the solution.

You now get the "The member "XXXX" is not recognized or is not accessible" error

Change the Target CPU back to Any CPU, Save and Build

The window now displays properly.

I had also the same exception. My problem was, that the Type of the property was in an assembly, which was not referenced in the Project, where I use the UserControl.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top