运行时编译的 DotNET 代码中抛出的异常的行号
与此线程不太一样,但非常接近。
我的程序允许人们输入一些 VB 或 C# 代码,这些代码在运行时被编译、加载和执行。我的 CompilerParams 是:
CompilerParameters params = new CompilerParameters();
params.GenerateExecutable = false;
params.GenerateInMemory = true;
params.IncludeDebugInformation = false;
params.TreatWarningsAsErrors = false;
params.WarningLevel = 4;
当此代码引发异常时,我希望能够显示一个消息框来帮助用户调试其代码。异常消息很简单,但行号是我陷入困境的地方。
我怀疑为了获取行号,我可能需要大幅更改 CompilerParameters,甚至可能需要更改这些 dll 的存储/加载方式。
有谁知道要使其发挥作用所需的最少步骤?
Not quite the same as this thread, but pretty close.
My program allows people to enter some VB or C# code which gets compiled, loaded and executed at runtime. My CompilerParams are:
CompilerParameters params = new CompilerParameters();
params.GenerateExecutable = false;
params.GenerateInMemory = true;
params.IncludeDebugInformation = false;
params.TreatWarningsAsErrors = false;
params.WarningLevel = 4;
When this code throws an exception I'd like to be able to display a message box that helps users debug their code. The exception message is easy, but the line-number is where I got stuck.
I suspect that in order to get at the line number, I may need to drastically change the CompilerParameters and perhaps even the way these dlls get stored/loaded.
Does anyone know the least steps needed to get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 OutputAssembly 设置为临时文件,设置GenerateInMemory = false, IncludeDebugInformation = true
这应该会生成符号并允许您获得带有代码行的完整堆栈跟踪
set OutputAssembly to a temp file, set GenerateInMemory = false, IncludeDebugInformation = true
That should generate symbols and allow you to get a full stack trace with code lines