我有以下代码:
var sd = new ServerDocument(documentPath);
应该注意的是 documentPath 是一个有效的路径,并且该文档使用了 vsto 应用程序。它可以很好地用 word 打开,我可以毫无问题地使用我的 vsto 扩展。
提到的代码行引发异常:
缺少根元素。
在 System.Xml.XmlTextReaderImpl.Throw(Exception e) 在 System.Xml.XmlTextReaderImpl.ParseDocumentContent() 在 System.Xml.XmlTextReaderImpl.Read() 在 System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)在 System.Xml.XmlDocument.Load(XmlReader reader) 在 System.Xml.XmlDocument.LoadXml(String xml) 在 Microsoft.Office.Tools.OfficeOpenXmlAppInfoDocument.ServerAppInfo.TryGetManifestInfo(PackagePart part, ManifestType& type, String& xml) 在 Microsoft.Office .Tools.OfficeOpenXmlAppInfoDocument.ServerAppInfo.EnsureMaps() 在 Microsoft.Office.Tools.OfficeOpenXmlAppInfoDocument.ServerAppInfo..ctor(Package package) 在 Microsoft.Office.Tools.OfficeOpenXmlAppInfoDocument.EnsureAppInfo()
在 Microsoft.Office.Tools.OfficeOpenXmlAppInfoDocument.Microsoft.VisualStudio.Tools.Applications.Runtime.IAppInfo.ReadItem(String type, String id) 在 Microsoft.VisualStudio.Tools.Applications.AppInfo.GetDeploymentManifestUrl(IAppInfo appInfo) 在 Microsoft.VisualStudio。 Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access, Boolean throwOnPreviousVersion) 在 Microsoft.VisualStudio.Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access) 在 Microsoft.VisualStudio .Tools.Applications.ServerDocument..ctor(String documentPath) at ConsoleApplication12.Program.Main(String[] args)
如何预防这个问题?