I
Iain
I've an application I've been working on for some time which has a Windows
Forms User interface, a set of 'business object' classes and interacts with
a SQL Server database and some Legacy COM Objects.
All was working well until I added some Logging code.
The Logging code raises an Event from one of the buisiness objects to the
main form of the (MDI) Windows UI. This adds a row to a DataSet which is
the source for a DataGrid on a MDI Child window.
The problem is that with the Logging event active some VERY bizzare things
are happening. If this was C++ I would be looking for stack corruption, but
in c#?
Tracing is difficult. I do not necessarily get the same symptoms on each
run and where the code gets to depends on the data and exactly where these
logging events are raised.
In each case I get
n unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an object
Appearing at the Application.Run.
The stack frame has
UnsafeNativeMethods.DispatchMessageW
At its top.
If I trace through I might find that some Controls on one of the Windows
Forms (not the one which manages the log!) seem to be invalid with
'error:cannot obtain value' appearing when viewed in the watch window (as a
first pass it would appear that all references or properties cannot be
found, but value variables can).
If I modify my OnLog handler to NOT raise the event then these problems do
NOT occur and the program works fine.
I have commented out the code which creates and process the COM Object and
the same sort of things happen.
I don't know where to start, really, can anyone give some hints?
Thanks
Iain
Forms User interface, a set of 'business object' classes and interacts with
a SQL Server database and some Legacy COM Objects.
All was working well until I added some Logging code.
The Logging code raises an Event from one of the buisiness objects to the
main form of the (MDI) Windows UI. This adds a row to a DataSet which is
the source for a DataGrid on a MDI Child window.
The problem is that with the Logging event active some VERY bizzare things
are happening. If this was C++ I would be looking for stack corruption, but
in c#?
Tracing is difficult. I do not necessarily get the same symptoms on each
run and where the code gets to depends on the data and exactly where these
logging events are raised.
In each case I get
n unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an object
Appearing at the Application.Run.
The stack frame has
UnsafeNativeMethods.DispatchMessageW
At its top.
If I trace through I might find that some Controls on one of the Windows
Forms (not the one which manages the log!) seem to be invalid with
'error:cannot obtain value' appearing when viewed in the watch window (as a
first pass it would appear that all references or properties cannot be
found, but value variables can).
If I modify my OnLog handler to NOT raise the event then these problems do
NOT occur and the program works fine.
I have commented out the code which creates and process the COM Object and
the same sort of things happen.
I don't know where to start, really, can anyone give some hints?
Thanks
Iain