AccessViolationException with C# Ping class

I have a "watchdog" program, c# console application, coded with VS 2005.

Program runs every 3 minutes. And one part of program checks pings to ~20 ip's. I'll give that function code:

static private bool ping(ref String ip) {

bool success = false;

Ping pingSender = new Ping();

if (pingSender.Send(ip).Status.Equals(IPStatus.Success)) {

success = true;

}

else

{

success = false;

}

return success;

}

Usually this works.. but sometimes (once a day on the average) it throws an exception and program crashes: Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

I checked the event log also. It says: Faulting application watchdog.exe, version 1.0.2361.14786, stamp 44964064, faulting module msvcr80.dll, version 8.0.50727.42, stamp 4333a455, debug 0, fault address 0x00014e08.

Any idea what makes this exception



Answer this question

AccessViolationException with C# Ping class

  • BCNO

    nobugz wrote:
    msvcr80.dll is the VS2005 "C" runtime library. A C# program wouldn't be using it. I would guess that your program uses some DLL that was developped in C++ and its that DLL that causes the crash. Use Dependency Walker if you're not sure what DLL that might be.

    The program isn't using any external dll's. System, System.Data and System.XML are all references.

    I run dependency walker, but I didn't find that dll from the dependencies.

    Anyway, I think you are near the solution. My guess is, that there is another program (coded with C++), that uses msvcr80.dll. And that program somehow causes the exception.

    There is some other programs that are also running regularly, and some of them are coded with C++.

    What do you think, could it be possible


  • dragoncells

    The program has already been running 7 days, and hadn't crashed yet.

    So, it seems to work when I run it under the debugger, weird.


  • BlackCatBone

    Hmm, your exception clearly shows that it is watchdog.exe that is crashing. Not seeing msvcr80.dll as a dependency is pretty bizarre of course. Make sure you use the Profile option in Dependency Walker, it may be loaded after startup.



  • fields098

    nobugz wrote:
    Hmm, your exception clearly shows that it is watchdog.exe that is crashing. Not seeing msvcr80.dll as a dependency is pretty bizarre of course. Make sure you use the Profile option in Dependency Walker, it may be loaded after startup.

    Isn't it possible, that if the program tries to use some memory area that belongs to another program, OS forces program to crash or something :)


  • ALahiri

    Once you have the Debugging tools for windows installed that nobugz mentioned above, you can just run the app under windbg.exe (with GUI interface) or cdb.exe (command line).  Either of these debuggers will stop when the Access violation (AV) occurs.  Once it has broken into the debugger, type the following commands in this order to get the stack trace where the AV is happening.  Make sure to include the leading period or exclamation mark ("." or "!") in these commands.  Remove the quotes...

    1) ".loadby sos mscorwks"

    2) "!clrsack"

    That will give you the managed stack where the problem is occuring.  Please post the output from that last command to this thread. 



  • CTheSoup

    msvcr80.dll is the VS2005 "C" runtime library. A C# program wouldn't be using it. I would guess that your program uses some DLL that was developped in C++ and its that DLL that causes the crash. Use Dependency Walker if you're not sure what DLL that might be.


  • bikerchick

    it's the next line, that throws the exception:

    PingReply reply = pingSender.Send(ip);

    computer that runs the program, doesn't have VS2005. Is it possible to use the debugger without it And what's the debugger program file, that I could use


  • Leed3

    msasn1.dll is an optional support DLL, your system apparently doesn't have it. The CLR just tries to load it but deals with it if it isn't there. Seeing exceptions while a .NET program runs is normal, the CLR deals with them.



  • Vince P

    Program hasn't crashed yet, but the debugger throws some exceptions every time it is starting program.

    It would be interesting to know what does those exceptions mean And does those exceptions mean something important fails when program is starting..

    some pieces of debugger output:

    Microsoft (R) Windows Debugger  Version 6.6.0003.5
    Copyright (c) Microsoft Corporation. All rights reserved.

    CommandLine: watchdog.exe
    The call to LoadLibrary(ext) failed, Win32 error 127
        "The specified procedure could not be found."
    Please check your debugger configuration and/or network access.

    ModLoad: 77430000 77440000   C:\WINNT\system32\MSASN1.DLL
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    ModLoad: 5e380000 5e409000   C:\WINNT\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    (1130.13c4): CLR exception - code e0434f4d (first chance)
    (1130.13c4): CLR exception - code e0434f4d (first chance)

    ..And there's also another exception..

    ModLoad: 673f0000 67496000   C:\WINNT\assembly\NativeImages_v2.0.50727_32\System.EnterpriseSe#\4ee8b0e72adcbe4a8d3148165dc6f146\System.EnterpriseServices.ni.dll

    (1130.7e4): C++ EH exception - code e06d7363 (first chance)
    (1130.7e4): CLR exception - code e0434f4d (first chance)


  • Programm3r

    Yes, I'm sure.

    The code is already in try/catch statements, I just took them away from that example (to make it seem more simple. yes, not very good idea).

    However, those try/catch statements doesn't catch that exception, program just crashes, I dont know why. (believe me, I have tested it quite many times, in fact now I have 3 try/catch statements, that should catch the exception: 1 in function, 1 in function call, and 1 in main program)

    I have added Console.WriteLine() 's to see what makes the exception, and It's the next row:

    if (pingSender.Send(ip).Status.Equals(IPStatus.Success))

    ip variable wasn't a ref one at first, but I've tried everything to solve this problem.

     


  • Aaron.W

    This seems very suspicious to me. Are you sure this is the part that throws the excaption Ping should not throw access violation exception.

    Can you put your code in try/catch statements, catch the exception and get more details about the error message, etc.

    A minor thing I notciced: why is your ip variable a ref one You are not changing it, are you

    Mariya


  • woon pun

    The program is now running under the debugger.. I'll post the output, when it crashes.
  • Davids Learning

    The first thing I would do now that you have narrowed the problem down to a single line of code is to simplify the line of code so that you can see what part of that line of code is causing the problem. You currently have:

    if (pingSender.Send(ip).Status.Equals(IPStatus.Success))

    Try splitting it up a little:

    PingReply reply = pingSender.Send(ip);
    if(reply == null)
    Console.WriteLine("REPLY IS NULL");
    if(reply.Status == IPStatus.Success)
    blah;

    Also, can you catch the exception in a debugger There is a way to run the app under a debugger every time that it starts by setting a registry key. For example: If I wanted to always launch notepad.exe under the windbg.exe debugger I would do the following:

    1) Create the following registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Notepad.exe"

    2) add a string value under that key named "debugger" and set the value of that value to "c:\debuggers\windbg.exe -G -g" (assuming that windbg lives at the specified path). Note that the "-G -g" paramaters to windbg just tell it to skip the initial process startup and exit break points. This should allow you to run you app every three minutes without you having to manually attach the debugger every time. Once you have successfully caught the exception in the debugger, then you can figure out exactly where the problem is.



  • Walter30140

    No, not these days. Your next (grim) option is to resort to Debugging Tools for Windows.



  • AccessViolationException with C# Ping class