tags:

views:

80

answers:

0

I have the following code that produces an IOException upon the second call to Console.WriteLine (but not the first).... This is following some calls to a DLL, but as far as I can tell, the functions returned just fine.

Console.WriteLine("Finding Cameras"); //Works
uint camera_count = 0;
CamDLL.Camera[] cameras = new CamDLL.Camera[100];
CamDLL.LoadDriver();
CamDLL.Error error = CamDLL.ListCameras(cameras,ref camera_count);
// At this point camera_count, cameras, and error all have sane values
Console.WriteLine("Found cameras"); // produces IOException!

I suspect my DLL is crap, but I need it to work, help!

Edit: I should add that the IOException is: The handle is invalid

Edit2: I used P/Invoke on the managed version of the DLL, and get the same result when calling Console.WriteLine after calling CamDLL.LoadDriver()

Update: I only get this exception thrown in a GUI project (WPF). If I use the same DLL from a ConsoleApplication, the same code block runs fine without ever throwing any exceptions. Does that help in diagnosing? Should I not be using Console.WriteLine from a GUI application? Thanks.