問題
EPPlus で ~1.5 MiB を超えるファイルを保存しようとするとExcelPackage.Save()
、System.IO.IsolatedStorage.IsolatedStorageException
.
説明
ライブラリを介してテーブルのコンテンツをエクスポートするためにVisual Studio 2008 9.0.30729.4462 QFE
、SSIS パッケージを作成しています。.NET Framework 3.5 SP1
SQL Server 2008 SP2 10.0.4311.0 64 bit
EPPlus 2.9.0.1
SSIS パッケージは非常にシンプルです。Execute SQL Task
テーブルの内容を読み取って変数に格納し、その後Script task
にレコードセット変数を読み取って内容を EPPlus を介してディスクに保存する です。
スクリプト タスクのコードは次のとおりです。
namespace ST_00a0b40814db4c7290b71f20a45b62c6.csproj
{
using System;
using System.AddIn;
using System.Data;
using System.Data.OleDb;
using System.IO;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
using OfficeOpenXml;
[AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : VSTARTScriptObjectModelBase
{
public void Main()
{
DataTable documentList = new DataTable();
using (OleDbDataAdapter adapter = new OleDbDataAdapter())
{
adapter.Fill(documentList, this.Dts.Variables["DocumentList"].Value);
}
if (documentList.Rows.Count > 0)
{
FileInfo fileInfo = new FileInfo(@"C:\Temp\Test.xlsx");
if (fileInfo.Exists)
{
fileInfo.Delete();
}
using (ExcelPackage package = new ExcelPackage(fileInfo))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Documents");
for (Int32 i = 0; i < documentList.Rows.Count; i++)
{
for (Int32 j = 0; j < documentList.Columns.Count; j++)
{
worksheet.Cells[i + 1, j + 1].Value = documentList.Rows[i][j];
}
}
package.Save();
}
}
Dts.TaskResult = Convert.ToInt32(DTSExecResult.Success);
}
}
}
スクリプト タスクにいくつかのレコードのみをフィードすると、パッケージは正常に実行されますが、テーブル全体に対して実行するpackage.Save();
と、例外が発生して爆発しSystem.IO.IsolatedStorage.IsolatedStorageException: Unable to determine the identity of domain
ます。
ここでは、完全なスタック トレースを確認できます。
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Error saving file C:\Temp\Test.xls ---> System.IO.IsolatedStorage.IsolatedStorageException: Unable to determine the identity of domain.
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 System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForDomain()
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.EnsureIsolatedStoreStream()
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(String value)
at System.IO.TextWriter.Write(String format, Object arg0, Object arg1)
at OfficeOpenXml.ExcelWorksheet.UpdateRowCellData(StreamWriter sw)
at OfficeOpenXml.ExcelWorksheet.SaveXml()
at OfficeOpenXml.ExcelWorksheet.Save()
at OfficeOpenXml.ExcelWorkbook.Save()
at OfficeOpenXml.ExcelPackage.Save()
--- End of inner exception stack trace ---
at OfficeOpenXml.ExcelPackage.Save()
at ST_00a0b40814db4c7290b71f20a45b62c6.csproj.ScriptMain.Main() in C:\Temp\ScriptMain.cs:line 39
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
生成されたファイルのサイズの問題を特定できました。Excel ファイルのサイズが約 1.5 MiB になると (これは多かれ少なかれ値であり、正確なサイズを見つけることができませんでした)、エラーが表示されます。
私がネット上で見つけることができた唯一の情報はブログ投稿です。ブロガーは、コードを DLL に「外部委託」し、それをサーバーの GAC にアップロードしてから、次のコードを実行するソリューションを提案しています。
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = rootPath;
setup.DisallowBindingRedirects = false;
setup.DisallowCodeDownload = true;
setup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
Evidence evidence = new Evidence();
evidence.AddHost(new Zone(SecurityZone.MyComputer));
AppDomain ad = AppDomain.CreateDomain("NewAppDomain", evidence, setup);
YourClass yourClass = (YourClass)ad.CreateInstanceAndUnwrap(typeof(YourClass).Assembly.FullName, typeof(YourClass).FullName);
yourClass.aMethod();
AppDomain.Unload(ad);
ただし、サーバーの GAC にアクセスできず、DLL をアップロードできないため、このソリューションを試すことができません。
この問題を回避する他の方法はありますか?
また、この問題に関する EPPlus の問題トラッカーでバグ レポートを開きました。
サマリー
- SSIS パッケージ
- Visual Studio 2008 9.0.30729.4462 QFE
- .NET フレームワーク 3.5 SP
- SQL Server 2008 SP2 10.0.4311.0 64 ビット
- EPプラス 2.9.0.1
- 大きな出力ファイル
- System.IO.IsolatedStorage.IsolatedStorageException: ドメインの ID を特定できません