Nathan Wong
Nathan Wong

Reputation: 327

Debugging dynamically compiled code with Roslyn

I'm using Roslyn to dynamically compile arbitrary *.cs files. I am able to generate the DLLs and PDBs and execute methods within the loaded assemblies via reflection, but when attaching the VS debugger from System.Diagnostics.Debugger.Launch(), I'm getting 'source not available' errors. The 'Modules' windows in VS shows that the symbols have been loaded successfully. The source in question lives in a project under the same solution, but is not compiled until runtime.

Has anyone successfully gotten this working? Thanks!

reproduction: https://gist.github.com/toraora/a9d4eb8679383fe659da04d3be5c2d6e (I'll put up the actual solution when I finish setting up SSH keys on this machine)

Upvotes: 9

Views: 2077

Answers (1)

Nathan Wong
Nathan Wong

Reputation: 327

Ah, so the solution was to have:

CSharpSyntaxTree.ParseText(File.ReadAllText(srcfile), path: srcfile, encoding: System.Text.Encoding.UTF8)

Thanks @hvd!

Upvotes: 9

Related Questions