Ribbon - Unhandled access violation reading 0x0000 exception

Ribbon - Unhandled access violation reading 0x0000 exception

winnes
Explorer Explorer
4,062 Views
11 Replies
Message 1 of 12

Ribbon - Unhandled access violation reading 0x0000 exception

winnes
Explorer
Explorer

Hi,

I have this Acad plugin (C#), where I simply create a Ribbon, Button on it that executes a Command.
Windows 7, AutoCAD 2013 all running x64.
Used the ObjectARX x64 Libraries for my references.
In my environment, everything works just fine, on my clients workstations... it shows 'Unhandled access violation reading 0x0000 exception'

Since client installed AutoCAD 2012 and then 2013, I tried a Repair, to no result.
Have verified all references, put all ObjectARX references, just to make sure, put debug lines in the code.
It crashes at first line:

Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;

All other Commands seem to run just fine.
Any clue what could be the cause, what I could try more?

0 Likes
4,063 Views
11 Replies
Replies (11)
Message 2 of 12

augusto.goncalves
Alumni
Alumni

Maybe is just a matter of timing...when is this code called? During startup?

 

Please also try with

      Autodesk.Windows.RibbonControl ribbonControl =
          Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;

 

And make sure all references are from ObjectARX folder with Copy Local equals FALSE.

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 12

winnes
Explorer
Explorer

All references are already set to CopyLocal = False

Code is called by command (so after loading of all AutoCAD stuff, no?)

 

As far as I understand, Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl is an internal API (AcRibbon.dll), which I cannot reference?

 

Visual Studio Compiler tells me a property is used as a type...

All of a sudden, I am losing it 🙂

 

Also, you mention possible timing issue?

Wonder how (my environment ok, clients not?)

 

However, I found code that puts this kind of thing in OnIdle... mmm

0 Likes
Message 4 of 12

augusto.goncalves
Alumni
Alumni

Don't loose it just yet 🙂

 

It should be under AcWindows.dll and AdWindows.dll references.

 

Are you using on the same version of AutoCAD?

 

About the timing, don't use OnIdle, but maybe something like

>>>

  public class AdskApplication : IExtensionApplication
  {
    public void Initialize()
    {
      if (Autodesk.Windows.ComponentManager.Ribbon == null)
      {
        //load the custom Ribbon on startup, but at this point
        //the Ribbon control is not available, so register for
        //an event and wait
        Autodesk.Windows.ComponentManager.ItemInitialized +=
            new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
      }
      else
      {
        //the assembly was loaded using NETLOAD, so the ribbon
        //is available and we just create the ribbon
        createRibbon();
      }
    }

    public void Terminate()
    {

    }

    void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
    {
      //now one Ribbon item is initialized, but the Ribbon control
      //may not be available yet, so check if before
      if (Autodesk.Windows.ComponentManager.Ribbon != null)
      {
        //ok, create Ribbon
        createRibbon();
        //and remove the event handler
        Autodesk.Windows.ComponentManager.ItemInitialized -=
            new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
      }
    }

  }

<<<

 

 

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 5 of 12

winnes
Explorer
Explorer

Have tried the Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl... No Exception, but nothing else happens? So the custom Ribbon does not show at all.

 

I catched both System.Exception and Autodesk.AutoCAD.Runtime.Exception, but that does not reveal anything.

 

Since I explicitly do a NETLOAD and then type my command, I am pretty sure it is no timing issue.

Am I right? However, Autodesk.Windows.ComponentManager.Ribbon remains null???

 

Any other ideas?

 

 

 

0 Likes
Message 6 of 12

BlackBox_
Advisor
Advisor

I'd highly recommend that you instead hook the Application.Idle Event in Initialize(), and then in your Idle Event handler, unregister the Event handler first, and then add your component(s) to ComponentManager.

 

Cheers


"How we think determines what we do, and what we do determines what we get."

Chris Bradley (aka BlackBox)
Managing Partner / Developer / Civil Designer
Quux Software | Sincpac C3D | Style Explorer

0 Likes
Message 7 of 12

BlackBox_
Advisor
Advisor

@BlackBox_ wrote:

I'd highly recommend that you instead hook the Application.Idle Event in Initialize(), and then in your Idle Event handler, unregister the Event handler first, and then add your component(s) to ComponentManager.

 

Cheers


For reference:

 

Add Custom RibbonTab at Startup


"How we think determines what we do, and what we do determines what we get."

Chris Bradley (aka BlackBox)
Managing Partner / Developer / Civil Designer
Quux Software | Sincpac C3D | Style Explorer

0 Likes
Message 8 of 12

winnes
Explorer
Explorer

This is very useful information, I keep it for further reference.

Nevertheless, the client works in Classic View and needs more than just buttons, so a Tool Palette is more appropriate.
That works from the very first time!

 

Thanks for all the help.

0 Likes
Message 9 of 12

BlackBox_
Advisor
Advisor

@winnes wrote:

This is very useful information, I keep it for further reference.

Nevertheless, the client works in Classic View and needs more than just buttons, so a Tool Palette is more appropriate.
That works from the very first time!

 

Thanks for all the help.


That is kind of you to say, winnes; I'm happy to help.

 

It sounds like you've got the Tool Palette under control, but if you've ever been interested in going a bit above and beyond, you might consider adding a Windows Presentation Foundation (WPF) UserControl, as Kean demonstrates here:

 

  


"How we think determines what we do, and what we do determines what we get."

Chris Bradley (aka BlackBox)
Managing Partner / Developer / Civil Designer
Quux Software | Sincpac C3D | Style Explorer

0 Likes
Message 10 of 12

winnes
Explorer
Explorer

Sometimes, one needs to go fast... like this time.

Therefore, further reference, like in a "next" project.

For Office automation tasks I am already a longtime believer of the Ribbon...

WPF on the other hand is fairly new to me...

But there again, Kean is one of THE references, and once again it will certainly serve in the next iteration of this, or another project.

I already have some ideas for future use.

Thanks for the link

0 Likes
Message 11 of 12

BlackBox_
Advisor
Advisor

You're welcome; I'm happy to help. :beer:


"How we think determines what we do, and what we do determines what we get."

Chris Bradley (aka BlackBox)
Managing Partner / Developer / Civil Designer
Quux Software | Sincpac C3D | Style Explorer

0 Likes
Message 12 of 12

Juergen_Becker
Advocate
Advocate

Hi Augusto,

 

this code saved me. He really works great. Thank you very much.

 

Greetings from Germany. Wish you a merry Christmas and a really good  next year.

 

Jürgen 

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de