我不太確定該怎麼做。總體目標是能夠獲取用戶腳本,並在.NET環境中執行它。我有大部分的代碼編寫和東西工作提供我不會嘗試加載我自己的程序集。但是,爲了安全地讓用戶訪問系統的內部部分,已經創建了代理DLL。這是問題出現的地方。使用CompileAssemblyFromSource加載自定義程序集
現在這個代理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;
運行上面的代碼,它引發以下錯誤:
System.IO.FileNotFoundException : Could not load file or assembly 'file:///C:\Users...\AppData\Local\Temp\scts5w5o.dll' or one of its dependencies. The system cannot find the file specified.
當然,我首先想到的是,「......什麼是scts5w5o.dll?」
這是ScriptProxy.dll
加載不正常,還是ScriptProxy.dll本身試圖加載依賴項,它們在某個臨時文件中?或者是完全不同的東西?
我應該提到,我從NUnit測試運行器執行此代碼。我不確定這是否有所作爲。
這將是有道理的。我現在就試試看。 –
我打算把這個標記爲答案,因爲它雖然沒有解決每個問題的問題,但它確實幫助我獲得了真正的錯誤信息,這幾乎同樣有幫助! –
那麼你如何解決實際問題! – Moumit