実行時に動的アセンブリをコンパイルしています。別のDLLを参照する必要があります。 CompilerParametersでOutputAssemblyを設定する限り、すべて正常に機能します。しかし、私がGenerateInMemory = trueを設定するとすぐに。それは失敗します:実行時にクラスをコンパイルすると、CompilerParameters.GenerateInMemory == trueの場合に失敗します。
var compilerParameters = new CompilerParameters();
if(compileInMemory)
compilerParameters.GenerateInMemory = true;
else
compilerParameters.OutputAssembly = "<my_dynamic_dll_path>";
compilerParameters.ReferencedAssemblies.Add("<other_dll_path>");
var compilerResults = new CSharpCodeProvider().CompileAssemblyFromDom(compilerParameters, codeCompileUnit);
// Here: compilerResults.Errors.HasErrors == false
foreach(var type in compilerResults.CompiledAssembly.GetTypes())
{
// Exception:
// Unable to load one or more of the requested types.
// Retrieve the LoaderExceptions property for more information.
}
LoaderExceptionsは "other_dll"が見つかりませんでした。メモリ内でコンパイルしない限り動作するのはなぜですか?また、メモリ内でコンパイルするにはどうすればいいですか?
また、other.dllへのパスをハードコードするとしますか? –
申し訳ありませんが、パスはすでにハードコードされています - 私の投稿を編集して明確にします – tanascius