4 Replies Latest reply on Dec 15, 2014 11:29 AM by Dmitry Zamoshnikov

    Solidworks Add-in c# no longer working

    Dmitry Zamoshnikov

      This is strange to me.  I built an add-in.  Took the DLL and ported it to another computer to test it.  It worked fine.  I revised the code to include an xml configuration file.  I unregistered the old version and registered the new version.  The new version no longer works.  I ran depends.exe to see if I'm missing a dependency and it shows the dll as x86, when I compiled it on an x64 machine.

       

      The first version has the same configuration settings and ran just fine.  The revision is now giving me an error because it's x86 (in depends)...That's not all.

       

      So the addin registers just fine with microsoft.net/framework64/regasm.  All of the [Comvisible] classes show up in the reg table.  The add-in shows up in the solidworks reg table.  The add-in even shows up in solidworks (tools->addins).  But when I set the add-in to active it decides not to load it at all.

       

      I changed the configuration settings in visual studio 2012 to x64.  Registered it, and ran it on the other machine.  Solidworks recognizes it, but doesn't load it.  I removed the configuration file support.  Solidworks recognizes it, but doesn't load it.

       

      How can I add support in my add-in for different machines?  It works perfectly on my machine but I can't seem to make it work on other machines.  Do you have any thoughts?  Any articles I can read?  Any posts I can read to help me port the add-in to another machine?

        • Re: Solidworks Add-in c# no longer working
          Oleg Bezyaev

          Why you don't use AnyCPU configuration while build the assembly?

           

          And use this command lines (*.BAT file) to register assembly on any target machines:

          if %processor_architecture%==AMD64 goto x64
          rem Run x32 installer
          C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe YOUR_DLL_NAME.dll /codebase
          @pause
          :x64
          rem Run x64 installer
          C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe YOUR_DLL_NAME.dll /codebase
          @pause
          
          1 person found this helpful
            • Re: Solidworks Add-in c# no longer working
              Dmitry Zamoshnikov

              No good.  I decided to create a new project and now the blank addin won't load.  The addin shows up inside solidworks.  It just won't activate.  Works just fine on my system.

               

              It seems to be a problem with my install.bat:

               

              C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm SwAddin.Taskpane.dll \codebase

               

              I type in "\codebase" instead of "/codebase"

               

              it works perfectly.

               

              Thanks for your batch file post Oleg.  It helped me notice my command was wrong.

               

              Question:  When I set "anycpu" in the configuration, will the dll be registerable on either x86 or x64?  Does windows make the dll automatically compatible in either architecture?

                • Re: Solidworks Add-in c# no longer working
                  Oleg Bezyaev

                  About AnuCPU

                  .net - What does the Visual Studio "Any CPU" target mean? - Stack Overflow

                   

                   

                  If you are creating Task Pane don't forget this: launch DisplayWindowFromHandlex64 for 64 bit os and DisplayWindowFromHandle for 32 bit os.

                  Add this code to your SwAddin class:

                  public bool Running64Bit
                  {
                      get
                        {
                          if (Marshal.SizeOf(typeof(IntPtr)) == 8)
                          return true;
                          else
                          return false;
                        }
                  }
                  

                   

                  And add Task Pane like this:

                  public void WinFormInTaskPane()
                          {
                                ITaskpaneView pTaskPanView;
                                pTaskPanView = iSwApp.CreateTaskpaneView2("", "C# .NET Control");
                                TaskPanWinFormControl = new Form1();
                                if (Runninng64Bit)
                                {
                                  pTaskPanView.DisplayWindowFromHandlex64(TaskPanWinFormControl.Handle.ToInt64());
                                }
                                else
                                {
                                pTaskPanView.DisplayWindowFromHandle(TaskPanWinFormControl.Handle.ToInt32());
                                }
                                TaskPanUserControl = (UserControl1)pTaskPanView.GetControl();
                          }
                  

                   

                  Or like this:

                  pTaskPanView.DisplayWindowFromHandlex64(swAddin.Running64Bit
                                      ? TaskPanWinFormControl.Handle.ToInt64()
                                      : TaskPanWinFormControl.Handle.ToInt32());
                  
                  1 person found this helpful