3

In my WP7 solution I have a PhoneClassLibrary1 assembly. In its AssemblyInfo.cs I have

[assembly: XmlnsPrefix("FooNamespace", "cl")]
[assembly: XmlnsDefinition("FooNamespace", "PhoneClassLibrary1")]

I have a trivial control in PhoneClassLibrary1

using System.Windows.Controls;

namespace PhoneClassLibrary1
{
    public class Class1 : Control {}
}

PhoneApp1 project in the same solution has main page of

<phone:PhoneApplicationPage 
    x:Class="PhoneApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:cl="FooNamespace">

    <cl:Class1/>

</phone:PhoneApplicationPage>

That compiles just fine. But when run, I get XamlParseException

{"The type 'Class1' was not found because 'FooNamespace' is an unknown namespace. [Line: 8 Position: 6]"}

I try to assign name to a control <cl:Class1 x:Name="foo"/> to have Class1 referenced in generated code. Same XamlParseException.

I modify AppManifest.xml in PhoneApp1. Please note that AssemblyPart tag.

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Deployment.Parts>
    <AssemblyPart x:Name="PhoneClassLibrary1" Source="PhoneClassLibrary1.dll" />
  </Deployment.Parts>
</Deployment>

After that application launches successfully.


If I inspect PhoneApp1.xap (which is a deployment package) I can see following generated AppManifest.xml

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="PhoneApp1" EntryPointType="PhoneApp1.App" RuntimeVersion="4.7.50308.0">
  <Deployment.Parts>
    <AssemblyPart x:Name="PhoneApp1" Source="PhoneApp1.dll" />
    <AssemblyPart x:Name="PhoneClassLibrary1" Source="PhoneClassLibrary1.dll" />
    <AssemblyPart x:Name="PhoneClassLibrary1" Source="PhoneClassLibrary1.dll" />
  </Deployment.Parts>
</Deployment>

That is not a typo. Application is able to run only if <AssemblyPart x:Name="PhoneClassLibrary1" is specified TWICE in generated AppManifest.xml


Am I doing something wrong? I work on a control project which is reused in multiple solutions and would not like to modify AppManifset.xml in all those numerous projects.

Is XmlnsDefinition able to work without AppManifset.xml modification?

kza
  • 1,590
  • 13
  • 32
  • I've asked same question at http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/1a47600c-0dcd-42fa-81ef-3b00bde55402 – kza Jan 18 '13 at 06:44

1 Answers1

0

My assumption of the XmlnsPrefixAttribute is that this provides a hint to the tools of what to use in preference and is optional. The valid xmlns definition in your XAML is:- xmlns:cl="clr-namespace:FooNamespace;Assembly=PhoneClassLibrary1"

The clr-namespace prefix is used to make a valid Uri containing the namespace and assembly containing the required type.

Peter Foot
  • 76
  • 2