C# addin not loading

I am trying to make a C# addin but having some trouble getting started. I can get the addin to show up in the list of available addins in Solidworks however when I hover over the Addin name it shows a popup with the Title and Description but the location of the dll is blank (all the other addins have the loaction of the dll listed). This makes me think that the registration process has failed somehow.... I have checked the "Make assembly Com Visable", "Register for COM" and target x64 platform options in Visual Studio.

I have tried to manually register the dll using the x64 version of regasm with the /codebase flag but still not working.

I am also getting a bunch of "Processing COM reference "SldWorks" from path ...." errors when I build the project.

I am using a win7 x64 machine with SW2013x64 (not SW2014x64 is also installed on this machine).

below is the declaration for the class:

    [Guid("91f0f2c3-c6a0-41a8-8a50-35188dd8a573"), ComVisible(true)]

    [SwAddin(Description = "New Description Here", Title = "Title", LoadAtStartup = true)]

    public class myAddinClass: SwAddin

    {

        public bool ConnectToSW(object ThisSW, int Cookie)

        {

            iSwApp = (ISldWorks) ThisSW;

            iSwApp.SendMsgToUser2("Addin Connected to SW",(int) swMessageBoxIcon_e.swMbInformation, (int) swMessageBoxBtn_e.swMbOk);

            return true;

        }

        public bool DisconnectFromSW()

        {

            iSwApp = null;

            GC.Collect();

            return true;

        }

        [ComRegisterFunctionAttribute]

        public static void RegisterFunction(Type t)

        {

            // Add the registry key that tell SW about the addin

            Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine;

            Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser;

            string keyname = "SOFTWARE\\\\Solidworks\\\\Addins\\\\{ " + t.GUID.ToString() + "}";

            Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname);

            addinkey.SetValue(null,0);

            addinkey.SetValue("Description", "Sample Addin");

            addinkey.SetValue("Title","Addin Title");

            keyname = "Software\\\\SolidWorks\\\\AddinsStartup\\\\{" + t.GUID.ToString() + "}";

            addinkey = hkcu.CreateSubKey(keyname);

            addinkey.SetValue(null,1);

        }

        [ComUnregisterFunctionAttribute]

        public static void UnregisterFunction(Type t)

        {

            // Remove the registry keys that tell SW about the Addin

            Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine;

            Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser;

            string keyname = "SOFTWARE\\\\Solidworks\\\\Addins\\\\{" + t.GUID.ToString() + "}";

            hklm.DeleteSubKey(keyname);

            keyname = "Software\\\\Solidowrks\\\\AddinsStartup\\\\{" + t.GUID.ToString() + "}";

            hkcu.DeleteSubKey(keyname);

        }

    }

Any hints will be greatly appreciated.

Cheers

Brett

SolidworksApi macros
Answers 2
AT
AT 2013-11-20 Best Answer

You should call REGASM with /codebase switch to properly register .NET add-in.

BM
BM 2013-11-20

Tried that....

I suspect the problem is related to the guid's I have used. VS automatically assigns one to the project assembly and I am also a signing one to the class in the code as per the example I am following. I am not sure how these are used but I suspect there could be an issue there. I did try using the same guid in both places but that didnt help.

I could also have a registry full of corrupt entries for all the testing of this and that..

Brett