Unhandled exception when running console app

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The application, uses the DLR from MS that provides an interactive console. This uses quite alot of console features, as well as threading. Unfortunately, I cannot get more info on the exception. You can however download the code from the 'source code' section on http://www.codeplex.com/IronScheme. The application behaves correctly under the CLR Profiler, and runs otherwise correctly under all other condtions.

Here is some more info:

Unhandled exception at 0x00690066 in IronScheme.Console.exe: 0xC0000005: Access violation.

callstack:
> 00690066
10005c98
[Frames below may be incorrect and/or missing, no symbols loaded for RedGate.Profiler.Core2.dll]
10005c98
10018134

registers:
EAX = 00690066 EBX = 00000000 ECX = 00000006 EDX = 048C3DDC ESI = 048C3E78 EDI = 048C3DDC EIP = 00690066 ESP = 0145DEA0 EBP = 0145DEF4 EFL = 00010206

CS = 001B DS = 0023 ES = 0023 SS = 0023 FS = 003B GS = 0000

ST0 = +0.0000000000000000e+0000 ST1 = +0.0000000000000000e+0000 ST2 = +0.0000000000000000e+0000 ST3 = +0.0000000000000000e+0000 ST4 = +0.0000000000000000e+0000 ST5 = +1.7000000000000000e+0001
ST6 = +2.5000000000000000e-0001 ST7 = +4.0902119140625000e+0003 CTRL = 027F STAT = 0120 TAGS = FFFF EIP = 79E78DEE EDO = 00000000

MM0 = 0000000000000000 MM1 = 0000000000000000 MM2 = 0000000000000000 MM3 = 0000000000000000 MM4 = 0000000000000000 MM5 = 8800000000000000 MM6 = 8000000000000000 MM7 = FFA3640000000000

XMM0 = 00000108000000000145D52C0163DAE8 XMM1 = 00000000015F000079E78BB20145D540 XMM2 = 000000010145D5DCB3DAE5E779E78BD1 XMM3 = 0046000079E743900145D54800000000 XMM4 = 79E78BD1FFFFFFFF7A33F3F40145D57C
XMM5 = 000000FC00000000015F000079E78B6A XMM6 = 79E790CA0982766879E790AD0145D588 XMM7 = 00000000000000010145D5DCB3DAE52F XMM00 = +4.18504E-038 XMM01 = +3.63361E-038 XMM02 = +0.00000E+000 XMM03 = +3.7E-043#DEN
XMM10 = +3.63362E-038 XMM11 = +1.50282E+035 XMM12 = +4.09586E-038 XMM13 = +0.00000E+000 XMM20 = +1.50282E+035 XMM21 = -1.01932E-007 XMM22 = +3.63366E-038 XMM23 = +1.4E-045#DEN
XMM30 = +0.00000E+000 XMM31 = +3.63362E-038 XMM32 = +1.50099E+035 XMM33 = +6.4E-039#DEN XMM40 = +3.63364E-038 XMM41 = +2.33592E+035 XMM42 = -1.#QNANE+000 XMM43 = +1.50282E+035
XMM50 = +1.50281E+035 XMM51 = +4.09586E-038 XMM52 = +0.00000E+000 XMM53 = +3.5E-043#DEN XMM60 = +3.63364E-038 XMM61 = +1.50294E+035 XMM62 = +3.14077E-033 XMM63 = +1.50295E+035
XMM70 = -1.01931E-007 XMM71 = +3.63366E-038 XMM72 = +1.4E-045#DEN XMM73 = +0.00000E+000 MXCSR = 00001FA0

XMM0DL = +1.59184899545106E-302 XMM0DH = +5.6020688881E-312#DEN XMM1DL = +1.66954190986592E+279 XMM1DH = +1.1365059244E-316#DEN XMM2DL = -6.69548235352161E-059
XMM2DH = +2.1325460431E-314#DEN XMM3DL = +1.59188014044409E-302 XMM3DH = +2.44758205272807E-307 XMM4DL = +4.52733796445525E+280 XMM4DH = +1.66957652679707E+279
XMM5DL = +4.52049671168142E-302 XMM5DH = +5.3474293932E-312#DEN XMM6DL = +1.67092139254564E+279 XMM6DH = +1.67095280382621E+279 XMM7DL = +1.59204557753226E-302
XMM7DH = +4.9406564584E-324#DEN

OV = 0 UP = 0 EI = 1 PL = 0 ZR = 0 AC = 0 PE = 1 CY = 0

00690066 = 00

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi leppie,

    I'd love to debug Profiler against this, but I can't get it to compile. One of the pre-build actions fails trying to run a program called gppg.exe. It returns 9009. Unfortunately there is nothing to tell me what 9009 means and what I should do about it. Any suggestions?
  • Unfortunately, I have never seen that error :( I quick search thru the source finding no matches, seems to indicate a windows error code, if so:

    // DNS server not authoritative for zone.
    //
    #define DNS_ERROR_RCODE_NOTAUTH 9009L

    Can you maybe check the prebuild event for invalid file paths in the IronScheme project?
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Did that... and also copied and pasted the command from the error message into a command window and tried to run it with the same result. The file paths all seem to be valid...
  • Very interesting...

    The only other error I have seen with gppg.exe itself was when the output-file (which you should not have) was set as read-only.

    If no joy, send me a direct email, so I can forward you the 2 generated files.

    Thanks
  • Just to add, it seems DEP is kicking.
  • Just tested it on my work PC (XP, home one is Vista), same result.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Can you email me a build of the console application executable? You can send it to support@red-gate.com.
  • Ha!

    I got it figured out :wink:

    As I was preparing to package it up, I just did a test run without ANTS. All good. Then I tried ANTS, it didnt crash! Then I saw what was causing it. Obviously the DLR creates assemblies with Reflection.Emit, and the ANTS run was the 2nd pass and didnt crash because the assemblies were already compiled.

    Funny enough, it exactly that compilation bit I want timing for :shock:

    I will send you a build that does not save assemblies, hence they should crash ANTS everytime.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi leppie,

    Indeed and thanks for sending the compiled project. I did debug ANTS Profiler and found that it does stop at some obscure bit of assembly code (not my forte) so I was going to continue trying to find the exact cause tomorrow. But one of the possible reasons that came from the developer right off the bat is the possibility that your program emits IL. This process can conflict with the code profiler while it's instrumenting the IL.

    Hopefully, with this information we can see if there is a workaround for this case. I'll let you know tomorrow. Thanks again!
  • Any joy yet?
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi Leppie,

    I'm not sure, but I think Windbg is telling me that there is a missing attribute on the module that you're emitting in your code.
    0397ff68 10014447 00000003 0397ff98 00000000 kernel32!WaitForMultipleObjects+0x18
    0397ff80 7c810acd 0397ffec 02973bae ffffffff RedGate_Profiler_Core2!APITakeSnapshot+0x137
    0397ffb4 7c80b683 02973bae 0140fa54 7c810acd kernel32!GetFileSize+0x56
    0397ffc0 7c810acd 02973bae 7ffdd000 8a3b7600 kernel32!GetModuleFileNameA+0x1b4
    0397ffc4 02973bae 7ffdd000 8a3b7600 0397ffc0 kernel32!GetFileSize+0x56
    0397ffc8 7ffdd000 8a3b7600 0397ffc0 897d6ed8 0x2973bae
    0397ffcc 8a3b7600 0397ffc0 897d6ed8 ffffffff 0x7ffdd000
    0397ffd0 0397ffc0 897d6ed8 ffffffff 7c839aa8 0x8a3b7600
    0397ffd4 897d6ed8 ffffffff 7c839aa8 7c80b690 0x397ffc0
    0397ffd8 ffffffff 7c839aa8 7c80b690 00000000 0x897d6ed8
    0397ffdc 7c839aa8 7c80b690 00000000 00000000 0xffffffff
    0397ffe0 7c80b690 00000000 00000000 00000000 kernel32!ValidateLocale+0x2b0
    0397ffe4 00000000 00000000 00000000 100145d0 kernel32!GetModuleFileNameA+0x1c1
    I have done a reproduction of this by modifying http://msdn2.microsoft.com/en-us/library/ms228971(VS.80).aspx, changing the following:
    string[] typeParameterNames = { "TInput", "TOutput" };
    Changed to:
    string[] typeParameterNames = { "", "" };
    
    This code will run outside of Profiler but crashes much the same way as your projects when being profiled, I suspect because ANTS Profiler is assuming some information exists about the emitted module that isn't strictly mandatory.

    Do you think you can locate a bit of the IronScheme code that performs a similar function to the one above?
  • Unfortunately I am not in control of any of that :(

    I did a search thru the source and I cannot find a place where generic could be used. I dont use it. And it doesnt appear in any stub code in the generated assemblies either.

    I did however notice when calling a DynamicMethod created at runtime seems to have a different signature the 'saved' version. It seems to prepend a parameter of type object[]. I also find some confusion about the assembly binding in this scenario. Maybe this has something to do with it. I am at a loss. :?
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi Leppie,
    I did eventually get the project to compile by removing the pre-build actions. I think they need to run once to generate the .y.cs file and then subsequent runs generate an error.

    ...anyway...

    I'm looking into the issue possibly being Microsoft.Scripting. The Visual Studio IDE messages indicate that the last thing to happen was that init.scm file had been run. Commenting out some of the lines of this file prevent ANTS Profiler from crashing, although they also prevent the console from initializing successfully.

    What I'm thinking is that Microsoft.Scripting does some emmitting of IL that doesn't agree with Profiler's core components.
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    I've fixed it!!!!

    Open the IronScheme project, then Runtime->Control.cs. Go to line 126 and change
    return meth.CallReflected(context, CallType.None, args);
    
    to read
    if (meth !=null) return meth.CallReflected(context, CallType.None, args);
          throw new ArgumentException(String.Format("Invalid parameter: argument count {0}", args.Length));
    
    There may be knock-on effects from this change, but I'm not qualified to say what they would be. At any rate this code change allows you to get the IronScheme.Console working with ANTS Profiler.
  • That condition can only occur if binding failed, which does not seem to ever happen.

    I did however did do something the other day that caused that line again, and funnily enough VS.NET started doing weird UI stuff. I will try recreate the code and see why that happens.

    Unfortunately the trial has expired now, I dunno if you can extend it somehow :(
  • If you email sales@red-gate.com they will be able to extend your trial for you,

    James
    James Moore
    Head of DBA Tools
    Red Gate Software Ltd
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    James,
    I've already taken the liberty of sending leppie an extension code via private message. :-)
  • Thanks :)

    It seems to run now, but for some reason I am hitting a null ref exception.

    That code the Brian pointed has some extra nastiness that could cause it to fail worse than it should. That said, the code should never fail there either, but for some reason it is.

    I will investigate some more.
Sign In or Register to comment.