私は3つのdll ProjBL.dll、ProjDL.dllおよびProjMC.dllを持っています。Assembly.Load()メソッドを使用するために、依存するアセンブリをメモリにロードする方法
ProjBL.dllは、ビジネス・オブジェクトのdll
ProjDL.dllは、データアクセス層方式のDLL
ProjMC.dllであるマスタークラスのdllがProjDL.dllがProjMC.dllに依存プロパティ
が含まれているとProjDL.dllはProjDL.dllに依存します
私は、指定されたフォルダを持つD:ドライブのフォルダからAssembly.Load()メソッドを使用してメモリにProjBL.dllをロードしています。
現在は使用された方法
を「依存アセンブリの一が見つからない」というエラーが発生します
DirectoryInfo dllDirectory = new DirectoryInfo(folderPath);
FileInfo[] dllFiles = dllDirectory.GetFiles("*.dll");
int dllCount = dllFiles.Length;
FileStream fs = null;
if (dllCount > 0)
{
long streamLength = 0;
for (int fileCount = 0; fileCount < dllCount; fileCount++)
{
fs = new FileStream(dllFiles[fileCount].FullName, FileMode.Open);
streamLength += fs.Length;
fs.Close();
}
byte[] memory = new byte[streamLength];
byte[] memory1 = null;
byte[] memory2 = null;
byte[] memory3 = null;
fs = new FileStream(dllFiles[0].FullName, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
memory1 = br.ReadBytes(Convert.ToInt32(fs.Length)); // Loads ProjMC.dll
fs = new FileStream(dllFiles[1].FullName, FileMode.Open);
br = new BinaryReader(fs);
memory2 = br.ReadBytes(Convert.ToInt32(fs.Length)); // Loads ProjDA.dll
fs = new FileStream(dllFiles[2].FullName, FileMode.Open);
br = new BinaryReader(fs);
memory3 = br.ReadBytes(Convert.ToInt32(fs.Length)); // Loads ProjBL.dll
fs.Close();
br.Close();
memory1.CopyTo(memory, 0);
memory2.CopyTo(memory, memory1.Length);
memory3.CopyTo(memory, (memory1.Length + memory2.Length));
assemblyUsed = Assembly.Load(memory);
}
return assemblyUsed;