views:

30

answers:

1

I am using the CodeDOM to generate and compile an assembly. I have found that if the generated code does not compile, the CompileAssemblyFromDom method generates line numbers that are different than what visual studio would generate.

So for example, if I call GenerateCodeFromCompileUnit on the code provider, take the generated code into visual studio and try to compile it, the line numbers on each error directly correlate to the line of code, but the line numbers returned in the CompilerResults object from the CompileAssemblyFromDom method do not directly correlate to the same line of the generated code.

It's proving to be an issue for me, because I am dynamically compiling the code, and if there are errors, I want to display the code and highlight the line in question for the user. Has anyone come across this same issue?

Edit: I think it's because entire lines that are comments, don't count as a line when reporting line numbers by the CodeDom provider, but they do with visual studio. any way to change the line number calculation by the CodeDom provider to include commented lines?

A: 

Do you have to use CompileAssemblyFromDom()? I've used CompileAssemblyFromSource() and not noticed any problems with line numbers.

Don Kirkby
I'm creating some of the code by using the Dom so I don't think I can use CompileAssemblyFromSource
Jeremy
@Jeremy, I used templates to wrap user scripts, so I had to translate the compiler result line numbers from wrapped script line numbers back to user script line numbers. You might be able to do something similar.
Don Kirkby