none
IsolatedStorageException in Ms Word Addin RRS feed

  • Question

  • I've got a really big problem.

    I created a word Addin project with a ribbon, and when I want to save the document, after several modifications with OpenXml, an exception is raised.

    Dim MainXMLDoc As New XmlDocument()
    Using WordDoc As WordprocessingDocument = WordprocessingDocument.Open(DocPath, True)
    
    Dim mainPart As MainDocumentPart = WordDoc.MainDocumentPart
    If Not mainPart Is Nothing Then
    
        MainXMLDoc.Load(mainPart.GetStream())
        EXmlDocument.XMLDoc = Nothing
        EXmlDocument.XMLDoc = MainXMLDoc
        EXmlDocument.GetWordDocIds()
        ..............
    end if
    
    ........
    Dim stream As IO.Stream
    stream = mainPart.GetStream(FileMode.Create, FileAccess.Write)
    
        MainXMLDoc.Save(stream) -----> exception

    And the exception message is :

    Interception de System.IO.IsolatedStorage.IsolatedStorageException
    Message=Unable to determine the identity of domain. Source=mscorlib StackTrace: at System.IO.IsolatedStorage.IsolatedStorage._GetAccountingInfo(Evidence evidence, Type evidenceType, IsolatedStorageScope fAssmDomApp, Object& oNormalized) at System.IO.IsolatedStorage.IsolatedStorage.GetAccountingInfo(Evidence evidence, Type evidenceType, IsolatedStorageScope fAssmDomApp, String& typeName, String& instanceName) at System.IO.IsolatedStorage.IsolatedStorage._InitStore(IsolatedStorageScope scope, Evidence domainEv, Type domainEvidenceType, Evidence assemEv, Type assemblyEvidenceType, Evidence appEv, Type appEvidenceType) at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) at System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder.GetCurrentStore() at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder..ctor() at MS.Internal.IO.Packaging.PackagingUtilities.GetDefaultIsolatedStorageFile() at MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName) at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary() at MS.Internal.IO.Packaging.SparseMemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at System.IO.StreamWriter.Write(Char value) at System.Xml.XmlTextWriter.Indent(Boolean beforeEndElement) at System.Xml.XmlTextWriter.AutoComplete(Token token) at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns) at System.Xml.XmlDOMTextWriter.WriteStartElement(String prefix, String localName, String ns) at System.Xml.XmlElement.WriteStartElement(XmlWriter w) at System.Xml.XmlElement.WriteElementTo(XmlWriter writer, XmlElement e) at System.Xml.XmlElement.WriteTo(XmlWriter w) at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw) at System.Xml.XmlDocument.WriteTo(XmlWriter w) at System.Xml.XmlDocument.Save(Stream outStream) InnerException:

    This problem appears when the document size is larger than 1Mb. After several searches, the 'save' action is made with an isolated storage, and the solutions is :

    • Install with Clickonce
    • Create new domain
    • Modify registry.


    But for this project, I can't use clickonce and I can't modifiy the registry.

    So I made changes to my source code, to create a new domain.

    Imports DocumentFormat.OpenXml.Packaging
    Imports System.IO
    
    <Serializable()> Public Class ToIsolatedPackageSave
        Public Sub Save(ByRef mainPart As MainDocumentPart, ByRef xmlDocument As Xml.XmlDocument)
            Dim stream As IO.Stream
            stream = mainPart.GetStream(FileMode.Create, FileAccess.Write)
            xmlDocument.Save(stream) -----> same exception
    
        End Sub
    End Class

    And

    Dim stream As Stream
    Dim isolatedPackageSave As ToIsolatedPackageSave
    Dim isolatedAppDomain As AppDomain
    
    Try
        Dim isolatedAppDomainSetup As AppDomainSetup = New AppDomainSetup()
        isolatedAppDomainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
    
        Dim isolatedEvidence As Evidence = New Evidence(AppDomain.CurrentDomain.Evidence)
        isolatedEvidence.AddAssembly(Reflection.Assembly.GetExecutingAssembly().FullName)
        isolatedEvidence.AddHost(New Zone(Security.SecurityZone.MyComputer))
    
        isolatedAppDomain = AppDomain.CreateDomain("TrustIsolatedDomain", isolatedEvidence, isolatedAppDomainSetup)
        isolatedPackageSave = isolatedAppDomain.CreateInstanceAndUnwrap(GetType(ToIsolatedPackageSave).Assembly.FullName, GetType(ToIsolatedPackageSave).FullName)
        '(IsolatedPackageSave)isolatedAppDomainSetup.CreateInstanceAndUnwrap(GetType(ToIsolatedPackageSave).Assembly.FullName, GetType(ToIsolatedPackageSave).FullName)
        isolatedPackageSave.Save(mainPart, MainXMLDoc)
    Catch ex As Exception
    Finally
        AppDomain.Unload(isolatedAppDomain)
    End Try
    Help me this code doesn't kill my problem. Thanks for all replies.

    Monday, June 2, 2014 2:52 PM

Answers

  • Hi EurRakanoth,

    >> I created a word Addin project with a ribbon

    As Forrest mentioned, I assume you are using Shared Add-in, so I’m afraid you are not able to use click-once.

    Would it help if you make the ToIsolatedPackageSave class inherit from MarshalByRefObject Class?

    Regards,

    Jeffrey

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 4, 2014 4:31 AM
    Moderator

All replies

  • Hi Open xml world,

    I've got a really big problem.

    I created a word Addin project with a ribbon, and when I want to save the document, after several modifications with OpenXml, an exception is raised.

    Dim MainXMLDoc As New XmlDocument()
    Using WordDoc As WordprocessingDocument = WordprocessingDocument.Open(DocPath, True)
    
    Dim mainPart As MainDocumentPart = WordDoc.MainDocumentPart
    If Not mainPart Is Nothing Then
    
        MainXMLDoc.Load(mainPart.GetStream())
        EXmlDocument.XMLDoc = Nothing
        EXmlDocument.XMLDoc = MainXMLDoc
        EXmlDocument.GetWordDocIds()
        ..............
    end if
    
    ........
    Dim stream As IO.Stream
    stream = mainPart.GetStream(FileMode.Create, FileAccess.Write)
    
        MainXMLDoc.Save(stream) -----> exception

    And the exception message is :

    Interception de System.IO.IsolatedStorage.IsolatedStorageException
    Message=Unable to determine the identity of domain. Source=mscorlib StackTrace: at System.IO.IsolatedStorage.IsolatedStorage._GetAccountingInfo(Evidence evidence, Type evidenceType, IsolatedStorageScope fAssmDomApp, Object& oNormalized) at System.IO.IsolatedStorage.IsolatedStorage.GetAccountingInfo(Evidence evidence, Type evidenceType, IsolatedStorageScope fAssmDomApp, String& typeName, String& instanceName) at System.IO.IsolatedStorage.IsolatedStorage._InitStore(IsolatedStorageScope scope, Evidence domainEv, Type domainEvidenceType, Evidence assemEv, Type assemblyEvidenceType, Evidence appEv, Type appEvidenceType) at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) at System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType) at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder.GetCurrentStore() at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder..ctor() at MS.Internal.IO.Packaging.PackagingUtilities.GetDefaultIsolatedStorageFile() at MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName) at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary() at MS.Internal.IO.Packaging.SparseMemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at System.IO.StreamWriter.Write(Char value) at System.Xml.XmlTextWriter.Indent(Boolean beforeEndElement) at System.Xml.XmlTextWriter.AutoComplete(Token token) at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns) at System.Xml.XmlDOMTextWriter.WriteStartElement(String prefix, String localName, String ns) at System.Xml.XmlElement.WriteStartElement(XmlWriter w) at System.Xml.XmlElement.WriteElementTo(XmlWriter writer, XmlElement e) at System.Xml.XmlElement.WriteTo(XmlWriter w) at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw) at System.Xml.XmlDocument.WriteTo(XmlWriter w) at System.Xml.XmlDocument.Save(Stream outStream) InnerException:

    This problem appears when the document size is larger than 1 Mb. After several searches, the 'save' action is made with an isolated storage, and the solutions is :

    • Install with Clickonce
    • Create new domain
    • Modify registry.

    But for this project, I can't use clickonce and I can't modifiy the registry.

    So I made changes to my source code, to create a new domain.

    Imports DocumentFormat.OpenXml.Packaging
    Imports System.IO
    
    <Serializable()> Public Class ToIsolatedPackageSave
        Public Sub Save(ByRef mainPart As MainDocumentPart, ByRef xmlDocument As Xml.XmlDocument)
            Dim stream As IO.Stream
            stream = mainPart.GetStream(FileMode.Create, FileAccess.Write)
            xmlDocument.Save(stream) -----> same exception
    
        End Sub
    End Class

    And

    Dim stream As Stream
    Dim isolatedPackageSave As ToIsolatedPackageSave
    Dim isolatedAppDomain As AppDomain
    
    Try
        Dim isolatedAppDomainSetup As AppDomainSetup = New AppDomainSetup()
        isolatedAppDomainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
    
        Dim isolatedEvidence As Evidence = New Evidence(AppDomain.CurrentDomain.Evidence)
        isolatedEvidence.AddAssembly(Reflection.Assembly.GetExecutingAssembly().FullName)
        isolatedEvidence.AddHost(New Zone(Security.SecurityZone.MyComputer))
    
        isolatedAppDomain = AppDomain.CreateDomain("TrustIsolatedDomain", isolatedEvidence, isolatedAppDomainSetup)
        isolatedPackageSave = isolatedAppDomain.CreateInstanceAndUnwrap(GetType(ToIsolatedPackageSave).Assembly.FullName, GetType(ToIsolatedPackageSave).FullName)
        '(IsolatedPackageSave)isolatedAppDomainSetup.CreateInstanceAndUnwrap(GetType(ToIsolatedPackageSave).Assembly.FullName, GetType(ToIsolatedPackageSave).FullName)
        isolatedPackageSave.Save(mainPart, MainXMLDoc)
    Catch ex As Exception
    Finally
        AppDomain.Unload(isolatedAppDomain)
    End Try

    Help me this code doesn't kill my problem. Thanks for all replies.


    Monday, June 2, 2014 3:51 PM
  • To clarify, your addin is a shared addin, not  VSTO addin, right? VSTO addin can be deployed in Clickonce. A few searches indicates the permission matters, think about how you specify the save destination, grant necessary permission to it. 


    Remember to mark reply as answer if it answers the question. <br/> <a href="http://www.appsrequest.net">Apps Request</a>

    Tuesday, June 3, 2014 6:33 AM
    Moderator
  • Hi EurRakanoth,

    >> I created a word Addin project with a ribbon

    As Forrest mentioned, I assume you are using Shared Add-in, so I’m afraid you are not able to use click-once.

    Would it help if you make the ToIsolatedPackageSave class inherit from MarshalByRefObject Class?

    Regards,

    Jeffrey

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 4, 2014 4:31 AM
    Moderator
  • Hi EurRakanoth,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel to reopen it or submit a new question.

    Thanks for your understanding.

    Best regards

    Fei 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 10, 2014 1:20 AM
    Moderator