Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML cannot find reference in local namespace

I created a new Metro Split App in C++ using VS2012 on Win8 (both RC). Everything compiled and worked out of the box. I then changed went through and changed the generated namespaces to my own. After some trials and tribulations, I got everything to compile with no warnings, errors, nor messages. The app (as it comes in the project template) runs fine.

However, if I try to edit either of the generated xaml files (ItemsPage.xaml or SplitPage.xaml) I get a "Markup error" on the first line:

The name "LayoutAwarePage" does not exist in the namespace "using:A.B.Product.Client.Common".

The definition of the class is:

namespace A{ namespace B { namespace Product { namespace Client { namespace Common

The code compiles fine, and runs fine. This only happens in design mode.

UPDATE: I added a new xaml file and (after fixing up the namespaces again) everything worked.

Please let me know if any additional information is needed.

like image 894
basilard99 Avatar asked Jun 12 '12 21:06

basilard99


2 Answers

The name of the WinMD file produced by your project must be some prefix of the namespaces in which the public WinRT types are defined. Given that your type is in the A.B.Product.Client.Common namespace , the WinMD file must have one of the following names:

A.winmd
A.B.winmd
A.B.Product.winmd
A.B.Product.Client.winmd
A.B.Product.Client.Common.winmd

The public types must also be defined in the WinMD file with the longest prefix that matches the namespace. So, if you have both A.winmd and A.B.winmd, the type A.B.MyClass must be defined in A.B.winmd.

So, why does your code work at runtime but not in the designer? The naming rules for public types only apply to types defined in Windows Runtime components (for C++, DLL files), not for applications (EXEs).

However, to be able to instantiate your user-defined types (including LayoutAwarePage), the designer will load your project's EXE as a DLL, so the naming rules must be followed.

like image 50
James McNellis Avatar answered Sep 25 '22 13:09

James McNellis


I had a similar bug, but then I closed VS, deleted the .suo, and reloaded the project and everything worked just fine.

like image 44
Jules G.M. Avatar answered Sep 22 '22 13:09

Jules G.M.