ThinkGeo.com    |     Documentation    |     Premium Support

Exception has been thrown by the target of an invocation

I get this exception when running in debug mode on the Application.Run(form) call and so can't debug my app.  It appears to occur after the Load method whenever I have a layer.  The inner exception is


"The GeoCanvas is currently not drawing.  Please call the BeginDraw method before calling this method."


and the stack trace for the inner exception is


"   at ThinkGeo.MapSuite.Core.x6d719af406ea4c2c.xbc32d22242378f5c(Boolean x1c27a8ea53684488)\r\n   at ThinkGeo.MapSuite.Core.GeoCanvas.get_CurrentWorldExtent()\r\n   at ThinkGeo.MapSuite.Core.GeoCanvas.x7f99ede452741dd6(String x8065f80416683c86)\r\n   at ThinkGeo.MapSuite.Core.GeoCanvas.x90a7e4e96ee35988()\r\n   at ThinkGeo.MapSuite.Core.GeoCanvas.EndDrawing()\r\n   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xfbd15a0e9d15f4e2(Graphics x783a718028818269, RectangleShape xb35a33b423b17f65)\r\n   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xf12dc5c7e687c240(Boolean x991dc8ddc7528b44, RectangleShape x178b193eec228e6e)\r\n   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xf12dc5c7e687c240(RectangleShape x178b193eec228e6e, Overlay x99251f66cdabc2ad, Bitmap x63b496b10c5882ad)"


I'm not sure when this started occurring as I don't see the exception unless I'm debugging.  Any ideas where this is coming from or how I can work around it?  I can't debug at the moment since this throws me out of the code.


Thanks



David, 
  
 We analyze your case very carefully!  
  
 I am wondering you are trying to debug your code in a machine which did not install correctly or uninstall the Desktop Edition package? 
  
 If even so, I think you still can debug, but the final MapControl result bitmap should be empty (only a watermark on it). 
  
 So I guess, in your App , you may use the canvas in a couple of places, one place has EndDrawing while others are still drawing, when it tried to finish drawing, it will blows up as you reported. 
  
 If you want, give us some code to review what will cause. 
  
 Any more questions just let me know. 
  
 Thanks. 
  
 Yale 


I did originally install the trial Desktop version, the uninstalled that and installed the version from the support site.  Everything seemed to install/uninstall properly.  I am not using the canvas in my code at all except to create a GeoImage from a resource.

 


 


GdiPlusGeoCanvas canvas = new GdiPlusGeoCanvas(); GeoImage aiImage = canvas.ToGeoImage(m_resources.GetObject("Trafficlights")); PointStyle intersectionPointStyle = new PointTipStyle(aiImage, new Size(14, 40)); 


 


Is there anything I should look at in the install/uninstall that could cause this? Thanks.



David,


Thanks for your post!


First please make sure the following statement in your code can get the expected image:


Image image = m_resources.GetObject("Trafficlights");
image.Save(@"C:\temp\test.bmp");
 
If so, I do not think there is any problem in your code to use the GdiPlusGeoCanvas.
 
Then, I still suspicious that there is something wrong for your current installed package. Can you find another machine to install a branch new package and then debug your app in this machine to see whether this problem still will happen?
 
Sorry for the inconvenience!
 
Any more questions just let me know.
 
Yale

Sorry for the delay.  I was getting the image correctly and that is the only place I used the GeoCanvas.  I did not directly use the Begin/EndDrawing in my code.  I am now no longer getting the exception during debugging but I have no idea what I added or removed to make it go away. 
  
 Anyway, Thanks for looking into it.  If it recurs again I will try to narrow down the cause.

David, 
  
 Thanks for your posts and sharing! 
  
 Let me know if any more questions. 
  
 Thanks. 
  
 Yale