我不太确定该怎么处理这个。总体目标是能够接受用户脚本,并在.NET环境中执行它。我编写了大部分代码,只要不尝试加载自己的程序集,就可以正常工作。但是,为了让用户安全地访问系统的内部部分,已经创建了代理DLL。这似乎就是问题所在。
现在这个代理DLL中有一个东西,一个接口。
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.GenerateInMemory = true;
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("ScriptProxy.dll");
Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider();
CompilerResults result = provider.CompileAssemblyFromSource(options, script);
// This line here throws the error:
return result.CompiledAssembly;运行上述代码,将引发以下错误:
'file:///C:\Users...\AppData\Local\Temp\scts5w5o.dll‘:无法加载文件或程序集
或其依赖项之一。系统找不到指定的文件。
当然,我的第一个想法是,"...and scts5w5o.dll是什么?“
这是ScriptProxy.dll没有正确加载,还是ScriptProxy.dll本身试图加载某个临时文件中的依赖项?还是完全不同的东西?
我应该提到,我是从NUnit测试运行程序执行这段代码的。我不确定这会不会有什么区别。
发布于 2015-10-29 08:42:27
我不认为标记为answer的帖子真的是应答!然而,我找到了答案,here
parameters.ReferencedAssemblies.Add(typeof(<TYPE FROM DOMAIN.DLL>).Assembly.Location);这意味着,如果您试图添加第三方的dll引用(有时.net dll也提供异常),那么只需在executable folder中复制它。会很好的..。否则,您也可以在那里定义完整的路径。
https://stackoverflow.com/questions/10402863
复制相似问题