Author Topic: AccessViolation while setting src property  (Read 21518 times)

0 Members and 1 Guest are viewing this topic.

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: AccessViolation while setting src property
« Reply #15 on: December 29, 2008, 05:37:19 PM »
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

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #16 on: December 30, 2008, 05:11:34 AM »
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

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #17 on: December 30, 2008, 06:02:47 AM »
May be you meant disabling LeaderLock exception like explained here.

http://www.tech-archive.net/Archive/Visio/microsoft.public.visio.developer/2006-07/msg00038.html

Still doesn't help

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #18 on: December 30, 2008, 06:08:54 AM »
 ;D ;D ;D

Good news!!!!

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

before putting SRC property solves the problem !!!

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: AccessViolation while setting src property
« Reply #19 on: December 30, 2008, 11:26:20 AM »
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

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #20 on: December 30, 2008, 01:32:03 PM »
Hope this will be useful for somebody.
Thanks a lot for the help. This is truly great resource for visio guys.

borisu

  • Jr. Member
  • **
  • Posts: 13
Re: AccessViolation while setting src property
« Reply #21 on: December 30, 2008, 02:02:32 PM »
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

  • Jr. Member
  • **
  • Posts: 49
Re: AccessViolation while setting src property
« Reply #22 on: February 09, 2009, 05:11:01 AM »
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

  • Newbie
  • *
  • Posts: 2
Re: AccessViolation while setting src property
« Reply #23 on: October 20, 2014, 11:02:09 AM »
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.