locked
Unable to determine the identity of domain." exception when saving larger XLSX file RRS feed

  • Question

  •  Hi all,

    I am having an issue saving a large XLSX file. Smaller XLSX files seem fine, but this larger one I'm trying to generate keeps failing with the above error.

    For research around, many solution mention using Application domain. I tried but it not working. This is my sample code

               AppDomainSetup setup = new AppDomainSetup();
                setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory.ToString();
                setup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                setup.LoaderOptimization = LoaderOptimization.MultiDomainHost;
                setup.PrivateBinPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;


                Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
                evidence.AddAssembly(Assembly.GetExecutingAssembly().FullName);
                evidence.AddHost(new Zone(SecurityZone.MyComputer));

                AppDomain ad = AppDomain.CreateDomain("HoGoExcelAddIn", evidence, setup);           
                StreamWriterXMLUtil StreamWriterXML = (StreamWriterXMLUtil)ad.CreateInstanceAndUnwrap(typeof(StreamWriterXMLUtil).Assembly.FullName, typeof(StreamWriterXMLUtil).FullName);
                
                try
                {
                    Stream StreamXMLpart = customXMLPart.GetStream(FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    StreamWriterXML.WriteCustomXMLContent(StreamXMLpart, customXMLContent);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    AppDomain.Unload(ad);
                }

    StreamWriterXMLUtil  class

     [Serializable]
        public class StreamWriterXMLUtil : MarshalByRefObject
        {

            public void WriteCustomXMLContent(Stream customXMLPart, string customXMLContent)
            {
               
                using (StreamWriter xmlStreamWriter = new StreamWriter(customXMLPart))
                {
                    xmlStreamWriter.Write(customXMLContent); //=> "exception here, unable to determine the identity of domain." 

                    xmlStreamWriter.Flush();
                    xmlStreamWriter.Close();
                }
            }
        }

    Anyone can help could be appreciated.

    Thank you,

    Johnny



    • Edited by Johnny-Le Wednesday, July 30, 2014 3:07 AM
    • Moved by George Hua Wednesday, July 30, 2014 9:06 AM .NET framework related
    Tuesday, July 29, 2014 6:50 PM

Answers

  • Hi Johnny,

    Please see how to write huge xml data to file from http://stackoverflow.com/questions/2673116/best-approach-to-write-huge-xml-data-to-file.

    Please let me know the result.

    Regards,


    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. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, August 4, 2014 5:54 AM

All replies

  • Hi Johnny,

    Since you are not using Excel Object Model and the issue is more related to .NET framework class libraries, I have moved this thread to .NET framework class libraries forum for more effective responses.

    Thanks for your understanding.


    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, July 30, 2014 9:08 AM
  • Hi George Hua,

    This application, i'm developing in Office Plugin (2010, 2013) (Application Level) for Excel and Word.

    Best regards

    Johnny

    1 hour 25 minutes ago
    Wednesday, July 30, 2014 10:56 AM
  • Hi Johnny,

    Please see how to write huge xml data to file from http://stackoverflow.com/questions/2673116/best-approach-to-write-huge-xml-data-to-file.

    Please let me know the result.

    Regards,


    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. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, August 4, 2014 5:54 AM