RE: Strange behavior with dynamic code compilation and VS.NET debu

Tech-Archive recommends: Fix windows errors by optimizing your registry



So the behavior is suppose to be different??? This doesn't make any sense -
so when I compile with debugging information I get different behavior then
when I compile without it? Isn't optimization a change in performance, not
behavior? Thanks for the response, I guess what I am getting at is how does
one troubleshoot optimized code if when you debug it the problem disappears?
Maybe we should go back to using lots of write lines instead of the debugger
;)


"Richard Hale Shaw (C# MVP)" wrote:

> Try changing the following line (change "false" to "true"):
>
> compilerParameters.IncludeDebugInformation = true;
>
> And you'll get the usual exception information when the program aborts.
> Regards,
> RHS
>
>
> "Mike Miller" wrote:
>
> > When I run the following code I would suspect a null reference exception to
> > be thrown:
> >
> > param1 = null;
> > int x = param1.Length;
> >
> > However, when I compile this code dynamically into a class and method a null
> > reference exception is ONLY thrown if the debugger is attached???? Otherwise
> > no exception is thrown. Can someone please explain this? I included the
> > code below - create a console application and overwrite the existing class
> > with the code below.
> >
> > CODE TO REPRODUCE:
> >
> > using System;
> > using System.CodeDom.Compiler;
> > using System.Reflection;
> > using Microsoft.CSharp;
> >
> >
> > namespace ConsoleApplication1
> > {
> > class Program
> > {
> > static void Main(string[] args)
> > {
> > Assembly a = CreateAssembly();
> > object o = a.CreateInstance("ConsoleApplication1.TestClass");
> > MethodInfo info = o.GetType().GetMethod("RunMe");
> > info.Invoke(o, new object[] { null });
> > }
> >
> > private static Assembly CreateAssembly()
> > {
> > string src = @"
> > namespace ConsoleApplication1
> > {
> > using System;
> >
> > public class TestClass
> > {
> > public virtual void RunMe(string param1)
> > {
> > int x = param1.Length;
> > }
> > }
> > }";
> >
> > CodeDomProvider provider = new CSharpCodeProvider();
> > CompilerParameters compilerParameters = new CompilerParameters();
> > compilerParameters.GenerateInMemory = true;
> > compilerParameters.IncludeDebugInformation = false;
> > compilerParameters.GenerateExecutable = false;
> >
> > CompilerResults results =
> > provider.CompileAssemblyFromSource(compilerParameters,
> > src);
> >
> > return results.CompiledAssembly;
> > }
> > }
> > }
.



Relevant Pages

  • Re: compiler errors
    ... compile a program that I downloaded from the net and keep getting a ... What is a DBG File and how do I set up the compiler to so I won't get ... debugging information necessary to do source code step-by-step ... The debugger is just warning you that it can't find the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: AWS issue
    ... Debugger for ada is not installed, so I can run the debugger, but the only answer I get is exit code 01. ... So I compile a single file with this function and link with all that stuff. ... At a glance it seems like you are missing -gnat05 in the compile command so you get and Ada95 compiler instead of Ada compiler. ... I've got two problems on AWS, hope there is some aws 2.3 users here. ...
    (comp.lang.ada)
  • Re: Compilator Fortran
    ... To facilitate compilation for the Windowed Debugger ... REM Invoke the debugger if compile and link went ok. ... This will compile, link, and invoke the windowed debugger. ...
    (comp.lang.fortran)
  • Re: unexplainable behaviour - f90 - looking for some tools to help diagnose
    ... using a debugger can help. ... But you should compile again your code with -g option and depending on the previous option used your code can run because of different layout of the datas in memory. ... If it fails (memory fault, segmentation fault) use the where command of the debugger to see where you are in the code.... ... I'm using CVS to store successive versions of my codes, but even if I can see exactly what has changed I do not undestand why I have a memory fault! ...
    (comp.lang.fortran)