Application error that is sporadic

This is a weird error that I have found a workaround. If anyone knows why this might be happening I would be greatly appreciated.

I have a VB application that calls a VB.Net DLL (Imports). The VB DLL calls an unmanaged C++ DLL and the C++ dll loads and unloads other DLL on the fly as needed.

In the VB application I create a new instance to the VB DLL object. When I set theinstantiatedobject to nothing an exception is thrown ( not all the time)

"The instruction at A referenced memory at A that could not be "read"

for Index as integer = 1 to 100
dim objI as new vbObject

objI = nothing < - causes the exception
next

[896 byte] By [Johnrambo] at [2007-12-17]
# 1
Can you post the exception thrown?
dimkaz at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

The first error screen is has the message

Application Error
the instruction at "0x35cb817" referenced memory at "0x35cb3817" The memory could not be "read". Click the CANCEL to debug the program.
When the cancel is clicked another screen comes up saying
Just-In-Time Debugging
An exception 'Unhandled Win32 Exception' has occured
However, a debugger that cannot hahndle the exception type is already attachehd to the program.

When the OK is clicked another screen comes up saying

JIT Debugging
JIT Dibugging is disabled
To enable JIT Debugging, from Visual Studio .NET go to tools/Options/Debugging/JIT settings

When I do that all of the program types are already checked
Common Language Runtime
Native
Script

Johnrambo at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
I had a similar problem Rambo (nice name).

I was using the AxWebBrowser in a VB.Net App. When the browser was navigated to a SharePoint site and then disposed, the error would occur.

I didn't find a solution. I just upgraded the App to VB2005 which now has a managed WebBrowser control.

Regards,

Grant.

GrantCarthew at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

since the object is declared in the loop, there really is no need to set it to nothing. GC will collect it at some point. There may be an issue with this approach as explained in "Garbage Collection: Unmanaged to Managed" (http://winfx.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_fxdebug/html/103eb3a3-1cf0-4406-8a9a-a7798fdc22d1.asp)

it says:
An application running unmanaged user components (such as COM or PInvoke) generates a non-deterministic access violation in runtime code.

If an application runs unmanaged user components, those components can corrupt the GC heap. This causes the runtime to generate an access violation when the garbage collector attempt to traverse the object graph. Enabling this probe reduces the time between the unmanaged component's corruption of the GC heap and the access violation by forcing a garbage collection to occur before every managed transition.

in the config file,

<gcUnmanagedToManaged enable="false">

stand__sure at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...