Question

I've got an application that reads in XAML files dynamically like this:

StreamReader sr = new StreamReader(pathAndFileName);
this.Content = XamlReader.Load(sr.BaseStream);

In one of those XAML files that gets loaded in (they all have had their code behind removed), this works:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DynamicXaml123">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <TextBox Height="23" Width="100" Text="{Binding FirstName}" />
        <TextBox Height="23" Width="100" Text="{Binding LastName}" />
        <TextBox Height="23" Width="100" Text="{Binding Age}" />
        <local:FieldEmailView></local:FieldEmailView>
    </StackPanel>
</UserControl>

But this give the error "The tag 'FieldEmailView' does not exist in XML namespace 'clr-namespace:DynamicXaml123;assembly=DynamicXaml123'".

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DynamicXaml123;assembly=DynamicXaml123">
    <StackPanel Margin="10" HorizontalAlignment="Left">
        <TextBox Height="23" Width="100" Text="{Binding FirstName}" />
        <TextBox Height="23" Width="100" Text="{Binding LastName}" />
        <TextBox Height="23" Width="100" Text="{Binding Age}" />
        <local:FieldEmailView></local:FieldEmailView>
    </StackPanel>
</UserControl>

If I leave out the assembly reference then it gets the error

Message=""XmlNamespace", "Assembly" oder "ClrNamespace"

when reading in the XAML.

Why can't I include the Assembly reference here, what do I have to change/check to get this to work?

Was it helpful?

Solution

When you load this in, you need to be able to resolve the assembly references. In other words, this assembly must be available for the application to reference against - one way to do this would be to deploy DynamicXaml123 to the GAC.

OTHER TIPS

I'd suggest getting out process monitor and seeing where your app is looking for dynamicxaml123. Check the fusion log as well. I'd guess the behavior in the XamlSerializer is different if you include the namespace than when you don't, and that change is affecting where the runtime is poking around for your assembly.

Note, there may be some lag between setting up fuslogvw and when it actually starts to log.

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