问题描述
我对动态编译C#代码有一些问题。我的课堂上有一些提供者财产:
static CSharpCodeProvider provider = new CSharpCodeProvider(new Dictionary<string,string>() { { "CompilerVersion","v4.0" } });
var compile = provider.CompileAssemblyFromFile(compilerParameters,sourceFile);
大多数拒绝此代码只是编译我的代码。但是在一台计算机上,当应用程序作为Windows服务运行时,此方法将返回异常:
at System.IO.__Error.WinIOError(Int32 errorCode,String maybeFullPath)
at System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share,Int32 bufferSize,FileOptions options,Security_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy,Boolean useLongPath,Boolean checkHost)
at System.IO.FileStream..ctor(String path,Boolean checkHost)
at System.IO.File.InternalReadAllBytes(String path,Boolean checkHost)
at System.IO.File.ReadAllBytes(String path)
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options,String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromFileBatch(CompilerParameters options,String[] fileNames)
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerParameters options,String[] fileNames)
我要调试CompileAssemblyFromFile。该项目具有.net 4.6 targer,所以我在这里https://referencesource.microsoft.com/download.html下载源表单。接下来,我检查Debug-> Options-> General-> Enable .NET Framework源代码步进,并在模块加载时禁止JIT优化(仅受管理),然后在Debug-> Options-> Symbols-> Microsoft Symbol Server中进行检查,然后单击Load All符号,然后重新启动VS。
当我调试代码和点击F11时,转到
再次单击F10
当我想查看在立即窗口中键入的编译器变量时
下一步,当从CodeDOMProvider.cs中退出F10调试类型时,调用CompileAssemblyFromFile。我想调试所有CompileAssemblyFromFile。
如何调试此代码?看起来像来自MS Symbol Server的pdb不匹配。你能帮助我吗?感谢您的宝贵时间。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)