显然XamlWriter在WinForms应用程序中无法正常工作。
XamlWriter使用MarkupWriter.GetMarkupObjectFor(object obj)。我认为确定要序列化的完整属性列表存在问题。
var ar = new AssemblyReference(AppDomain.CurrentDomain.GetAssemblies()。First()); var str = XamlWriter.Save(ar);
运行ASP.NET或WPF应用程序我得到了这个结果:
<AssemblyReference AssemblyName="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
HintPath="file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll"
SpecificVersion="False" xmlns="clr-namespace:Ivolutia.TypeModel;assembly=ivoTypeModel" />
但是在WinForms应用程序中运行相同的代码我得到了这个:
<AssemblyReference xmlns="clr-namespace:Ivolutia.TypeModel;assembly=ivoTypeModel" />
这是类定义:
public class AssemblyReference : DependencyObject
{
public string AssemblyName { get; set; }
public string HintPath { get; set; }
public bool SpecificVersion { get; set; }
public AssemblyReference() { }
public AssemblyReference(Assembly assembly)
{
AssemblyName = assembly.FullName;
HintPath = assembly.CodeBase;
}
public override string ToString()
{
return AssemblyName;
}
}
答案 0 :(得分:0)
&lt; AssemblyReference AssemblyName =“mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089”HintPath =“file:/// C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib。 dll“SpecificVersion =”False“xmlns =”clr-namespace:XamlWriterTester; assembly = XamlWriterTester“/&gt;
编辑: 顺便说一下,有没有理由说明普通的XML序列化对你不起作用?