是否可以使用WPF DocumentViewer在.NET 3.5中查看XPS文档?

是否可以使用WPF DocumentViewer在.NET 3.5中查看XPS文档?,wpf,.net-3.5,xps,typeloadexception,Wpf,.net 3.5,Xps,Typeloadexception,我想在ElementHost中使用WPF DocumentViewer组件在WinForms应用程序中显示XPS文档 我已键入正确的行以将XPS文件加载到Documentviewer中: XpsDocument xpsDoc = new XpsDocument(xpsfile, System.IO.FileAccess.Read); xpsView.Document = xpsDoc.GetFixedDocumentSequence(); 问题是我得到了以下异常和调用堆栈: A first c

我想在ElementHost中使用WPF DocumentViewer组件在WinForms应用程序中显示XPS文档

我已键入正确的行以将XPS文件加载到Documentviewer中:

XpsDocument xpsDoc = new XpsDocument(xpsfile, System.IO.FileAccess.Read);
xpsView.Document = xpsDoc.GetFixedDocumentSequence();
问题是我得到了以下异常和调用堆栈:

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重新查询有关吗?我需要为这个项目设定目标3.5。XPS ReachFramework自3.0开始提供,但我不知道在哪里查找


提前感谢。

更清楚一点:这是在Fx还是Fx3.5项目中发生的?它似乎缺少2.0/3.5的组装。您安装了什么?“System.Runtime.Versioning.TargetFrameworkAttribute”来自dot net 4.0。因此,有人试图加载此类型。您是否尝试过使用从3.5生成的XPS文件?@AresAvatar如果我从.net 4.0编写XPS,生成器是否应将net4.0类型合并到XPS中?我不知道XPS文件是如何形成的。Hernan,XPS是Xaml,然后被打包。将XPS重命名为.zip,然后可以作为zip文件打开,并读取包含Xml的文件树中的Xaml内容。他们可能做了一个更改,意外地将一个4.0类型潜入其中,您可以使用此方法进行检查。