Reputation: 11
I have a Word VSTO addin which saves a document into a secured network share. The save process is done via impersonating an Active Directory account which has access to the secured share. Part of it is copying the document over to the network share and removing the customisation (other parts include updating the database - irrelevant to the issue at hand).
SwitchIdentity()
File.Copy(localPath, remotePath, True)
If ServerDocument.IsCustomized(remotePath) Then
ServerDocument.RemoveCustomization(remotePath)
End If
SwitchBackIdentity()
ServerDocument class methods are thowing exceptions (even trying only .RemoveCustomization is not working on a document which have the customisation).
The exceptions thrown are:
The type initializer for 'MS.Utility.EventTrace' threw an exception.. Source: WindowsBase. StackTrace:
at MS.Utility.EventTrace.EasyTraceEvent(Keyword keywords, Event eventID)
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess)
at Microsoft.Office.Tools.OfficeOpenXmlAppInfoDocument.Microsoft.VisualStudio.Tools.Applications.Runtime.IAppInfoDocument.SetDocument(String fileName, Byte[] data, FileAccess fileAccess)
at Microsoft.VisualStudio.Tools.Applications.AppInfoDocumentFactory.GetAppInfoDocument(String documentPath, Byte[] bytes, FileAccess access)
at Microsoft.VisualStudio.Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access, Boolean throwOnPreviousVersion)
at Microsoft.VisualStudio.Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access)
at Microsoft.VisualStudio.Tools.Applications.ServerDocument..ctor(String documentPath, FileAccess access)
at Microsoft.VisualStudio.Tools.Applications.ServerDocument.IsCustomized(String documentPath)
at DMS.ActiveDocument.SaveActiveDocument(). InnerException Message: Requested registry access is not allowed.. InnerException Source: mscorlib
and the other exception is:
Failed to save remotely (ID=123).
The type initializer for 'MS.Utility.EventTrace' threw an exception..
Source: ADDINNAME. StackTrace: at ADDINNAME.CLASSNAME.METHODNAME()
These happen successively.
This is happening on a Windows 10 Office 2016 or a Windows 7 Office 2007. The add-in itself had been developed originally with VS 2008 VSTO 3 for Windows 7 Office 2007 environment and has been migrated with VS 2017 to use VSTO 4 (automated process).
The "Warmpup" registry key seems to be OK while the error is thrown (the add-in is loading properly all the time). We investigated the if this was linked to a DNS issue but this seems to be happening on PCs with or without any conflicts in in their IPs. We have also tried to reinstall VSTO 4 on the affected PCs with no luck.
The issue seems to be happening suddenly and may disappear after few days.
Any help is appreciated. Also note that we have a small user based on around 1000 per day using the application - this happens only to few users once in a while.
Upvotes: 1
Views: 210
Reputation: 11
We think we have found a work-around for this. Some people are suggesting to put this code to resolve a similar issue (please read until the end):
which seems to be working for us.
Upvotes: 0
Reputation: 49395
There are two different versions of the ServerDocument
class in the Visual Studio 2010 Tools for Office Runtime. The version you should use depends on the target .NET Framework of the application in which you want to use the class:
Microsoft.VisualStudio.Tools.Applications.ServerDocument
class in the Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll
assembly. Microsoft.VisualStudio.Tools.Applications.ServerDocument
class in the Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll
assembly. For more information, see Managing Documents on a Server by Using the ServerDocument Class.
Upvotes: 1