Hi all,
I am having an issue saving a large XLSX file. SmallerXLSX 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