The given XAML file content not parsed properly

375 views Asked by At

I am trying to Parse a XML file using the XamlReader which has the following contents

    <Canvas xmlns:seic="clr-namespace:NameSpace1;assembly=Assembly1" 
    xmlns:seidm="clr-namespace:NameSpace2;assembly=Assembly2" 
    xmlns:seogptpi="clr-namespace:NameSpace3;assembly=Assembly3" 
    xmlns:seogdc="clr-NameSpace4;assembly=Assembly4" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Name="_99abfc59e3ad417d98db31591a6f9dd7" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    Canvas.Left="0" Canvas.Top="0" Tag="TemplatePart" Width="800" Height="600"  
    seogdc:FrameworkElementExtensions.Id="Canvas" 
    seogdc:FrameworkElementExtensions.ShowRotateCue="False" 
    seogdc:FrameworkElementExtensions.ShowPositionCue="False" 
    seogdc:FrameworkElementExtensions.IsSizeSerializable="False" 
    seogdc:FrameworkElementExtensions.IsTargetDimensions="False">
<Canvas x:Name="Canvas1" 
      Canvas.Left="0"    
      Canvas.Top="0" 
      Tag="TemplatePart" 
      Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type Canvas}}, Path=Width}" 
      Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type Canvas}}, Path=Height}" 
      Background="{x:Static Brushes.Black}"
      seogdc:FrameworkElementExtensions.Id="Canvas" 
      seogdc:FrameworkElementExtensions.ShowRotateCue="False" 
      seogdc:FrameworkElementExtensions.ShowPositionCue="False" 
      seogdc:FrameworkElementExtensions.IsTargetDimensions="False" 
      seogptpi:TemplateManager.IsMainPart="True"
      seogptpi:TemplateManager.TemplateName="Canvas">
<seic:DomainParameter.DomainModel>
  <seidm:StatelessDomainModel>
    <seidm:StatelessDomainModel.DomainFeatures>
      <seidm:ColorFeature LabelFillTransparency="0">
        <seidm:ColorFeature.FontBlinkSetting>
          <seidm:ColorTransparancy Transparancy="0" />
        </seidm:ColorFeature.FontBlinkSetting>
        <seidm:ColorFeature.LineBlinkSetting>
          <seidm:ColorTransparancy Transparancy="0" />
        </seidm:ColorFeature.LineBlinkSetting>
        <seidm:ColorFeature.FillBlinkSetting>
          <seidm:ColorTransparancy Transparancy="0" />
        </seidm:ColorFeature.FillBlinkSetting>
      </seidm:ColorFeature>
    </seidm:StatelessDomainModel.DomainFeatures>
  </seidm:StatelessDomainModel>
</seic:DomainParameter.DomainModel>
  </Canvas>
</Canvas>

But it simply throws an XamlParseException('Cannot set unknown member 'Namespace2.ColorFeature.LabelFillTransparency'.' Line number '13' and line position '31'.) all the time. I have added references to the 4 assemblies mentioned above. For privacy purposes i have chosen not to provide the exact assembly names. Can someone tell me what might be happening?

Thanks in advance.

1

There are 1 answers

5
Martin Liversage On BEST ANSWER

You need to provide a custom ParserContext to the XamlReader.Parse method. You should assign the ParserContext.XamlTypeMapper property to enable XamlParser to locate the types referenced in your XAML. Something along these lines:

var context = new ParserContext();
context.XamlTypeMapper = new XamlTypeMapper(
  new[] {
    Assembly.GetExecutingAssembly().GetName().Name,
    "Assembly1",
    "Assembly2",
    "Assembly3",
    "Assembly4",
  }
);
var element = (FrameworkElement) XamlReader.Parse(xaml, context);