Property not recognized or not accessible error when loading VS2010 project into Expression Blend
Asked Answered
H

7

9

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>

Hubby answered 13/4, 2012 at 18:23 Comment(0)
H
18

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.

Hubby answered 13/4, 2012 at 21:2 Comment(11)
This setting has nothing to do with the error above. My project has AnyCPU by default in the .csproj file, and I still face this error :)Counterchange
Yeah what does this have to do with anything?Donets
This answer is seemingly unrelated to the question.Autoerotism
It worked perfectly fine although I can not see anything related :)Schizogony
so i cleared solution and rebuild solution and my problem went awayVibes
I agree that it seems silly at first but I will confirm it fixing the same problem when I had it. I didn't realize at first that the problem appeared on files that hadn't been changed RIGHT AFTER I had been working on the build for x86, x64, AllCPU. But sure enough, Visual Studio shows everything as AllCPU but the .cproj file shows x64 in a couple places. I closed the solution, fixed the cproj and reopened/cleaned/built and everything was restored to property accessibility. All I can say is "Heck of a find detective Brian Lemming"Globigerina
I thought it was unrelated also and looking at my project it appeared that it was set correctly as described above. However changing the project from x64 (which in my case was required) to AnyCPU, compiling and then changing back resolved the problem.Filipino
In my case it was other way around (I had AnyCPU and changed it to x86). I suppose it has something to the with the fact that the property in question has type from the C++/CLI assembly which is x86 only.Phagy
In my case it was already on 'AnyCPU'. Switching to either 'x86' or 'x64' fixed it, but I could not get it to correct itself on the 'AnyCPU' setting with any combination of closing, cleaning, rebuilding, etc.Stricker
Changing from x64 to AnyCPU (or x86) did eliminate the design-time error and I can see the form view in the form editor. BUT, now it fails at runtime! System.Windows.Markup.XamlParseException: ''The invocation of the constructor on type ... that matches the specified binding constraints threw an exception.' Line number '6' and line position '9'.'Kamala
... then after trying a bunch of stuff (cleaning, building, deleting, changing settings...) it started working in both design and run time. Don't know exactly did the trick.Kamala
V
10

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.

Vibes answered 25/6, 2014 at 2:57 Comment(0)
F
1

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.

Fencible answered 17/6, 2015 at 13:1 Comment(0)
K
1

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).

Kilah answered 25/2, 2016 at 14:59 Comment(0)
L
0

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!

Lindo answered 1/12, 2012 at 1:40 Comment(0)
C
0

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.

Confidence answered 7/5, 2014 at 16:51 Comment(0)
H
0

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.

Hacker answered 9/3, 2015 at 16:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.