Handle exception thrown by system.

V

Vitling

For no apparent reason, a NullReference exception is thrown in
system.dll
(System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback).
Since I only get a disassembly from Visual Studio, it is almost
impossible to figure out what causes this. I've tried adding:

AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler (SystemErrorHandler);

to my main method, and a handler function:

static void SystemErrorHandler(Object Sender,
UnhandledExceptionEventArgs Args)
{
Exception e = (Exception)Args.ExceptionObject;
Console.WriteLine ("Caught : " + e.Message);
}

But the handler never gets invoked. The exception just causes the
program to halt.

I think I've narrowed the cause down to some file-downloading done in
the program. I've tried both a WebClient.DownloadFile(), and a more
lowlevel WebRequest method, but they both causes this error.

Please help me find a way to, if not eliminate, at least contain the
exception.
 
N

Nicholas Paldino [.NET/C# MVP]

Vitling,

Can you show an example or give details on how to reproduce the error?
Without knowing that, it is very difficult to know what you are doing.
 
V

Vitling

I'm sorry but I can't isolate any specific component other then just
file downloading. This is done by simply using

Webclient.DownloadFile(URL,LocalPath)

This works for the most part, but then, every once in a while, the
error occurs. It can appear at almost any time during execution, even
when no file is currently beeing downloaded. But yet, if I disable the
download function the error disappears. It almost seems like this is
the result of some download-cleanup background system task failing. Im
not doing any network-related c# coding, just using the webclient
object.

Another wierd thing is that I can't seem to find any reference to
CompletionPortCallback in the source for OverlappedAsyncResult:

http://dotnet.di.unipi.it/Content/sscli/docs/doxygen/fx/bcl/__overlappedasyncresult_8cs-source.html

I've only been able to reproduce this error by running the entire
application and, im afraid, Im not allowed to post it here.
The application downloads, and processes documents using URLs gathered
from a search process. The files downloaded is therefore not the same,
every time the program runs. I've not been able to detect any
correlation between URLs and errors. Perhaps it is caused by invalid
data send by some webserver, but since it seems to be related to an
"old" network access. (error can occur even when no d.l. is
happening), I cant find any way to debug it.

I know that this is a debugging nightmare, but If there's at least a
way to discard the execption and avoid the program halt, I would be
very happy.

Thanks,
Danie




Vitling,

Can you show an example or give details on how to reproduce the error?
Without knowing that, it is very difficult to know what you are doing.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vitling said:
For no apparent reason, a NullReference exception is thrown in
system.dll
(System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback).
Since I only get a disassembly from Visual Studio, it is almost
impossible to figure out what causes this. I've tried adding:

AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler (SystemErrorHandler);

to my main method, and a handler function:

static void SystemErrorHandler(Object Sender,
UnhandledExceptionEventArgs Args)
{
Exception e = (Exception)Args.ExceptionObject;
Console.WriteLine ("Caught : " + e.Message);
}

But the handler never gets invoked. The exception just causes the
program to halt.

I think I've narrowed the cause down to some file-downloading done in
the program. I've tried both a WebClient.DownloadFile(), and a more
lowlevel WebRequest method, but they both causes this error.

Please help me find a way to, if not eliminate, at least contain the
exception.
 
A

Austin Ehlers

On Mon, 08 Dec 2003 17:48:54 GMT, mrboo@ht_u.se (Vitling) wrote:

The source code is:

private static void CompletionPortCallback(uint errorCode, uint
numBytes, NativeOverlapped* nativeOverlapped)
{
Overlapped overlapped1;
OverlappedAsyncResult result1;
bool flag1;
overlapped1 = Overlapped.Unpack(nativeOverlapped);
result1 = ((OverlappedAsyncResult) overlapped1.AsyncResult);
if (errorCode != 0)
{
flag1 = OSSOCK.WSAGetOverlappedResult(((Socket)
result1.AsyncObject).Handle, ((IntPtr)
nativeOverlapped), &(numBytes), 0,
IntPtr.Zero);
errorCode = OSSOCK.WSAGetLastError();
}
result1.ReleaseUnmanagedStructures();
result1.ErrorCode = errorCode;
result1.InvokeCallback(0, numBytes);
}
I got this by using Reflector: http://www.aisto.com/roeder/dotnet/
and it's under System.dll System.Net.Sockets.OverlappedAsyncResult

This is obviously a change from the 1.0 framework. Perhaps you could
target 1.0 and see if the error still occurs.

Austin Ehlers

<snip>
 
V

Vitling

Is there really no way to discard the exception and continue
execution. Now the program just dies :(
 
V

Vitling

I've managed to get some info from the debugger. Sorry for the poor
formatting:

- $exception {"Object reference not set to an instance of
an object." } System.NullReferenceException
- System.SystemException {"Object reference not set to an
instance of an object."} System.SystemException
- System.Exception {"Object reference not set to an
instance of an object." } System.Exception
System.Object {System.NullReferenceException} System.Object
_className null string
_COMPlusExceptionCode -532459699 int
_exceptionMethod <undefined value>
System.Reflection.MethodBase
_exceptionMethodString null string
_helpURL null string
_HResult -2147467261 int
_innerException { } System.Exception
_message "Object reference not set to an instance of an
object." string
_remoteStackIndex 0 int
_remoteStackTraceString null string
_source null string
- _stackTrace {System.Array} System.Object
[0] 0 sbyte
[1] 0 sbyte
[2] 0 sbyte
[3] 0 sbyte
[4] 0 sbyte
[5] 0 sbyte
[6] 0 sbyte
[7] 0 sbyte
[8] 40 sbyte
[9] -92 sbyte
[10] -4 sbyte
[11] 6 sbyte
[12] 79 sbyte
[13] -84 sbyte
[14] -19 sbyte
[15] 6 sbyte
[16] -96 sbyte
[17] -4 sbyte
[18] 54 sbyte
[19] 11 sbyte
[20] -40 sbyte
[21] -96 sbyte
[22] -3 sbyte
[23] 6 sbyte
_stackTraceString null string
_xcode -1073741819 int
_xptrs 188151788 int
HelpLink null string
HResult -2147467261 int
InnerException { } System.Exception
Message "Object reference not set to an instance of an
object." string
Source "System" string
StackTrace " at
System.Net.OSSOCK.WSAGetOverlappedResult(IntPtr socketHandle, IntPtr
overlapped, UInt32& bytesTransferred, Boolean wait, IntPtr
ignored)\r\n at
System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)"
string
+ TargetSite {System.Reflection.RuntimeMethodInfo}
System.Reflection.MethodBase
errorCode 64 uint
numBytes 0 uint
- nativeOverlapped 1773720
System.Threading.NativeOverlapped*
- System.ValueType {System.Threading.NativeOverlapped}
System.ValueType
System.Object {System.Threading.NativeOverlapped}
System.Object
EventHandle 0 int
InternalHigh 0 int
InternalLow -1073741299 int
OffsetHigh 0 int
OffsetLow 10054 int
- ReservedClasslib
{System.Runtime.InteropServices.GCHandle}
System.Runtime.InteropServices.GCHandle
- System.ValueType
{System.Runtime.InteropServices.GCHandle} System.ValueType
System.Object <undefined value> System.Object
__InternalTarget
{System.Net.Sockets.OverlappedAsyncResult} System.Object
IsAllocated error: cannot obtain value bool
m_handle <has no runtime value> int
Target error: cannot obtain value System.Object
ReservedCOR1 1 int
- ReservedCOR2 {System.Runtime.InteropServices.GCHandle}
System.Runtime.InteropServices.GCHandle
- System.ValueType
{System.Runtime.InteropServices.GCHandle} System.ValueType
System.Object <undefined value> System.Object
__InternalTarget
{System.Threading.IOCompletionCallback} System.Object
IsAllocated error: cannot obtain value bool
m_handle <has no runtime value> int
Target error: cannot obtain value System.Object
ReservedCOR3 1904976 int


Vitling,

Can you show an example or give details on how to reproduce the error?
Without knowing that, it is very difficult to know what you are doing.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Vitling said:
For no apparent reason, a NullReference exception is thrown in
system.dll
(System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback).
Since I only get a disassembly from Visual Studio, it is almost
impossible to figure out what causes this. I've tried adding:

AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler (SystemErrorHandler);

to my main method, and a handler function:

static void SystemErrorHandler(Object Sender,
UnhandledExceptionEventArgs Args)
{
Exception e = (Exception)Args.ExceptionObject;
Console.WriteLine ("Caught : " + e.Message);
}

But the handler never gets invoked. The exception just causes the
program to halt.

I think I've narrowed the cause down to some file-downloading done in
the program. I've tried both a WebClient.DownloadFile(), and a more
lowlevel WebRequest method, but they both causes this error.

Please help me find a way to, if not eliminate, at least contain the
exception.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top