1

in a C# application i load another application via

Assembly assembly = Assembly.LoadFrom("tool.dll");

and then run it via

Type typeGame = assembly.GetType("com.Program");
object instanceOfMyType = Activator.CreateInstance(typeGame);
typeGame.InvokeMember("Run", BindingFlags.InvokeMethod, null, instanceOfMyType, null);

this loaded application loads files from its current working directory, which works fine when run alone.

but when it is loaded into another application like above it gives FileNotFoundExceptions, even though the working directory is correct and the file is there.

also if i output the working directory via

Console.WriteLine(Directory.GetCurrentDirectory());

it tells me the correct directory where the file resides.

4

1 回答 1

0

您最好使用AppDomain.CurrentDomain.GetAssemblies方法并检查您是否已将其加载到您的域中。通常,bin文件夹(执行文件夹)中的所有dll都加载到域程序集列表中。至少对于 asp.net Web 应用程序是这样。

于 2012-10-18T08:49:23.290 回答