i have c# application uses c# script interface. means application compile c# code , run it.
i using system.codedom.compiler class with.
the problem if run code below throws invalidcastexception because trying cast string int in dynamic code.
if catch exception have no indication in 'dynamic code' error occured. instance 'invalidcastexception on line 8'.
i stack trace, no line numbers.
any ideas? want present our users enough information know error is.
public class notdynamicclass { public object getvalue() { return "value"; } } class program { public static void main() { var provider = csharpcodeprovider.createprovider("c#"); var options = new compilerparameters(); options.referencedassemblies.add("dynamiccodingtest.exe"); var results = provider.compileassemblyfromsource(options, new[] { @" using dynamiccodingtest; public class dynamicclass { public static void main() { notdynamicclass @class = new notdynamicclass(); int value = (int)@class.getvalue(); } }" }); var t = results.compiledassembly.gettype("dynamicclass"); t.getmethod("main").invoke(null, null); } }
you need set includdebuginformation
true
on compilerparameters
.
update: @ bottom of msdn documentation there community remark:
for c#, if set property true need set generateinmemory false , set value of outputassembly valid file name. generate assembly , .pdb file on disk , give file , line number information in stacktraces thrown compiled code.
Comments
Post a Comment