.NET

.NET

Reply
Member
winnes
Posts: 5
Registered: ‎06-17-2013
Message 1 of 11 (484 Views)

Ribbon - Unhandled access violation reading 0x0000 exception

484 Views, 10 Replies
06-18-2013 02:00 AM

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?

ADN Support Specialist
augusto.goncalves
Posts: 348
Registered: ‎04-30-2009
Message 2 of 11 (460 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

06-18-2013 09:31 AM in reply to: winnes

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
Autodesk Developer Network
Member
winnes
Posts: 5
Registered: ‎06-17-2013
Message 3 of 11 (444 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

06-18-2013 03:23 PM in reply to: augusto.goncalves

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 :smileyhappy:

 

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

ADN Support Specialist
augusto.goncalves
Posts: 348
Registered: ‎04-30-2009
Message 4 of 11 (430 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

06-19-2013 06:52 AM in reply to: winnes

Don't loose it just yet :smileyhappy:

 

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
Autodesk Developer Network
Member
winnes
Posts: 5
Registered: ‎06-17-2013
Message 5 of 11 (415 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

06-21-2013 02:30 PM in reply to: augusto.goncalves

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?

 

 

 

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 6 of 11 (409 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

06-21-2013 03:37 PM in reply to: winnes

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



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 7 of 11 (407 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

06-21-2013 03:42 PM in reply to: BlackBox_

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



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Member
winnes
Posts: 5
Registered: ‎06-17-2013
Message 8 of 11 (366 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

07-01-2013 05:43 AM in reply to: winnes

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.

Distinguished Mentor
BlackBox_
Posts: 745
Registered: ‎02-25-2013
Message 9 of 11 (356 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

07-01-2013 04:00 PM in reply to: winnes

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:

 

  



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Member
winnes
Posts: 5
Registered: ‎06-17-2013
Message 10 of 11 (346 Views)

Re: Ribbon - Unhandled access violation reading 0x0000 exception

07-02-2013 12:46 AM in reply to: BlackBox_

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

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.