我想使用ElementHost中的WPF DocumentViewer组件在WinForms应用程序中显示XPS文档。
我输入了正确的行来将XPS文件加载到Documentviewer中:
XpsDocument xpsDoc = new XpsDocument(xpsfile, System.IO.FileAccess.Read);
xpsView.Document = xpsDoc.GetFixedDocumentSequence();
问题是我得到以下异常和callstack:
A first chance exception of type 'System.TypeLoadException' occurred in mscorlib.dll
Additional information: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
mscorlib.dll!System.ModuleHandle.ResolveTypeHandle(int typeToken, System.RuntimeTypeHandle[] typeInstantiationContext, System.RuntimeTypeHandle[] methodInstantiationContext) + 0x94 bytes
mscorlib.dll!System.Reflection.Module.ResolveType(int metadataToken = 16777295, System.Type[] genericTypeArguments, System.Type[] genericMethodArguments) + 0xcc bytes
mscorlib.dll!System.Reflection.CustomAttribute.FilterCustomAttributeRecord(System.Reflection.CustomAttributeRecord caRecord, System.Reflection.MetadataImport scope, ref System.Reflection.Assembly lastAptcaOkAssembly = null, System.Reflection.Module decoratedModule = {System.Reflection.Module}, System.Reflection.MetadataToken decoratedToken = {System.Reflection.MetadataToken}, System.RuntimeType attributeFilterType = {Name = "XmlnsDefinitionAttribute" FullName = "System.Windows.Markup.XmlnsDefinitionAttribute"}, bool mustBeInheritable = false, object[] attributes = {System.Windows.Markup.XmlnsDefinitionAttribute[15]}, System.Collections.IList derivedAttributes = null, out System.RuntimeType attributeType = null, out System.RuntimeMethodHandle ctor = {System.RuntimeMethodHandle}, out bool ctorHasParameters = false, out bool isVarArg = false) + 0x86 bytes
...
...
...
PresentationFramework.dll!System.Windows.Markup.XamlParser.Parse() Line 218 + 0x8 bytes C#
PresentationFramework.dll!System.Windows.Markup.XamlTreeBuilder.ParseFragment() Line 134 + 0xa bytes C#
PresentationFramework.dll!System.Windows.Markup.TreeBuilder.Parse() Line 70 + 0x7 bytes C#
PresentationFramework.dll!System.Windows.Markup.XamlReader.XmlTreeBuildDefault(System.Windows.Markup.ParserContext pc, System.IO.Stream stream, System.Windows.Markup.XamlParseMode parseMode, bool etwTracingEnabled) Line 806 + 0x7 bytes C#
PresentationFramework.dll!System.Windows.Markup.XamlReader.Load(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext) Line 297 + 0x3b bytes C#
ReachFramework.dll!System.Windows.Xps.Packaging.XpsDocument.GetFixedDocumentSequence() + 0xdf bytes
这可能与Net 4.0 requeriment相关吗?我需要为此项目定位3.5。 XPS ReachFramework从3.0开始提供,但我不知道在哪里看。
提前谢谢。