AccessViolation while setting src property

Started by borisu, December 28, 2008, 08:50:06 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visio Guy

So as a test (using the SDK's Office Plan sample), I added another Visio control and a button to the form. When I click the button, it loads a hard-coded Visio file into the new control.

This works fine, so I guess that the event sinks are causing problems with the Office Plan's Visio control.

However, when I close the application, I get a LoaderLock error, and the application doesn't shut down properly.

"LoaderLock Detected:

Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang."

I get this error regardless of whether I do anything with the new control, and it is still there when I remove the new button and new Visio control. So I wonder if the LoaderLock problem was there before I started messing around.

By the way, I've seen the LoaderLock problem before, and was able to get rid of it by unchecking something under Tools > Options > Debugging, but I don't remember what it was, or whether it was a good idea to uncheck it.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

borisu

try the following in SDK sample

private void setAddAdvise() {

         // The Sink and TargetArgs values aren't needed.
         const string sink = "";
         const string targetArgs = "";

         Event newEvent = null;
return; // << ---------- THIS WILL WORK (YOU WILL BE ABLE TO LOAD FILE)

         EventList applicationEvents = eventApplication.EventList;
         EventList documentEvents = eventDocument.EventList;

            return; // <--- THIS WON'T WORK (YOU WON'T BE ABLE TO LOAD FILE)

}

It seems like only referencing to EventList breaks the visio. It does seem like "suppress JIT optimizarion" problem but it doesn't help. :(

borisu


borisu

 ;D ;D ;D

Good news!!!!

GC.Collect();
GC.WaitForPendingFinalizers();

before putting SRC property solves the problem !!!

Visio Guy

Nice job, borisu!

I had a feeling that the visControl was somehow half dead, half alive, but I didn't know enough technical nitty-gritty to do anything about it (you won't find me looking at MSIL code or anything...)
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

borisu

Hope this will be useful for somebody.
Thanks a lot for the help. This is truly great resource for visio guys.

borisu

BTW I think it is only part of much bigger problem. Seems like Viiso C# API is not built well for situations where destructing objects takes part in different thread and in undetermined time. It is not only SRC which caused problems but other API's also (Close for example).

IRDC

Hi, we encountered a similar problem: Our application won't start on Windows XP (runs fine on Vista) and crashes on the second Visio command (or the third, if we comment out the second):
1. _axVisioDrawingControl.HostID = VisioHostId;
2. _axVisioDrawingControl.Window.Application.Settings.EnableAutoConnect = false;
3. _axVisioDrawingControl.Window.Application.Settings.ZoomOnRoll = true;
with an Access Violation Exception (System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.)
Invoking the Garbage Collector didn't help. Any ideas?  :-\

kg_amat

I have run into the same problem with this control. I was able to get around it by opening and re-saving the document in Visio 2007. Good luck.