AnsweredAssumed Answered

SolidWorks crashes when call AddMenuItem5 method

Question asked by Valeriya Klimenko on Jan 31, 2019

Hi there,

 

I have a problem with adding a custom menu item using .Net API.

Here is a SolidWorksPerformance.log file fragment:

<SWEXH>

<MINIDUMP> "c2eb4f51-02e6-4303-a246-e478390bc0ae" </MINIDUMP>

<EXCEPTION> "Access Violation at 00007FFAD623135D (virtual address ffffffffffffffff), attempt to read from memory"

<RESOURCE_WARNING>CMD:GDIHandles ATTR:used=698 ATTR:load=6.98 ATTR:free=9302 CMD:CommitChargeMB ATTR:used=5458 ATTR:load=16.82 ATTR:free=26995</RESOURCE_WARNING>

<AD5> auAm_c::XDispatch::Release;auAm_c::XDispatch::SetAddinCallbackInfo;auAm_c::SetAddinCallbackInfo;auAm_c::XDispatch::Frame;auAm_c::Frame;auFrame_c::XDispatch::GetSubMenus;auFrame_c::GetSubMenus;auAm_c::XDispatch::AddMenuItem5;auAm_c::AddMenuItem5;

<RAWSTACK> ucrtbase:7FFAD623135D:0002135D,mfc140u:7FFA895F2E30:00002E30,sldappu:454C786F:0027786F,sldappu:454C7687:00277687,sldworks:7FFA5B704829:7FFA5B704829,sldworks:005FF900:005FF900,sldworks:005FF880:005FF880,sldworks:00000015:00000015,sldworks:68242E90:68242E90,sldworks:00000015:00000015,sldworks:005FF814:005FF814,sldworks:005FF804:005FF804,sldworks:005FF7F4:005FF7F4,sldworks:005FF8D8:005FF8D8,sldworks:005FF900:005FF900;

<UNHANDLED>

</SWEXH>

 

Here is my code:

            string[] images = null;

            string image16path = @"C:\Program Files\AddInInstallFolder\MenuItemIcon16.png";

            if (File.Exists(image16path ))

                 images = new string[] { image16path };

 

            var subMenus = frame?.GetSubMenus((int)docType, "&File") as string[];

            if (subMenus == null)

                return;

 

            var index = 0;

            if (subMenus.Contains("Pac&k and Go..."))

                index = Array.IndexOf(subMenus, "Pac&k and Go...") + 1;

            else

                index = subMenus.Length;

 

            swApp.AddMenuItem5((int) docType, cookie, "MyMenuItem@&File", index,

                    nameof(CallBackMethod) + $"({MY_COMMAND_ID})", string.Empty, string.Empty, images);

 

On another machine, this code is working well, but I have a crash running this on my machine, right after swApp.AddMenuItem5 call (I am using Solidworks 2018).

What can be possible reasons causing Access Violation Exception?

Any help would be very appreciated.

 

Thanks!

Outcomes