0
我在運行時正在嘗試動態類創建,但當我在最後一行運行我的程序時出現以下錯誤。有誰知道如何解決這個問題?我試着在網上搜索類似的問題,但沒有任何解決方案對我有幫助。預先感謝您的幫助動態類創建 - FileNotFound異常
無法加載文件或程序集'file:/// C:\ Users \ xxxx \ AppData \ Local \ Temp \ jelsfwqz.dll'或其某個依賴項。該系統找不到指定的文件。
string code2 = "using System;" +
"using System.Collections.Generic;" +
"using System.Linq;" +
"using System.Text;" +
"" +
" public sealed class CustomClass" +
" {" +
" }"
;
// Compiler and CompilerParameters
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CompilerParameters compParameters = new CompilerParameters();
CodeDomProvider compiler = CSharpCodeProvider.CreateProvider("CSharp");
// Compile the code
CompilerResults res = codeProvider.CompileAssemblyFromSource(compParameters, code2);
// Create a new instance of the class 'CustomClass'
object myClass = res.CompiledAssembly.CreateInstance("CustomClass");
不要忽視CompilerResults.Errors –
謝謝。我會將其添加到我的代碼中。 – sjs