11 Replies Latest reply on Dec 31, 2015 5:45 PM by Checkcheck Master

    SW2015 C# add in

    Checkcheck Master

      Hi there,


      I'm trying to register and run the C# add in from the template.

      When I'm running Visual Studio 2015 I get some errors and warnings, see picture.


      What could be wrong ?

      I've installed the SDK, the zipped file swcharpaddin with the template is on the right location, what else ?


      Btw: I'm just a beginner in C#.

      My SW2015 installation is crashing due some bugs in the VBA editor while I'm running my VBA(swp) macro's.

      For me it's still unknown what triggers the 'Serious error occurred' message while running the macro's, sadly my complete work flow is based on the use of that macro's for years now, don't know what Solidworks has changed that the crashes increase that much.

      In my memory the problem occurs after the SW2015 SP2 update or something.

      The only thing Solidworks offers is to open the macro in an earlier SW version, compile and save and try again with your SW2015.

      However it's not my problem that I can't start the macro after a crash, with minimal 10+ crashes a day it's getting pretty annoying I can tell you.


      That's the reason to study C# and try to recreate the macro's in C#.

      Is C# the right choice while compared to .NET or maybe C++ ?

      What should be considered when choosing a language?


      Also, regarding my not working C# add in problem, I've studied 'Creating a Solidworks Add-in from scratch' from 'Angelsix', can't get it to work in Visual Studio 2010, I was suggesting it was because of obsolete code and decide to give t a try with Visual Studio 2015...


      Thanks for reading, appreciate you help very much, thanks in advance.



        • Re: SW2015 C# add in
          Simon Turner

          To answer the question in the title of your post, the reason it won't register is that your project is targeting the .net framework 2 (or 3.5). SW2015 uses .Net 4.0

          So, change your project settings to target .Net 4.0


          C# is definitely preferable to C++ unless you are an expert programmer. VB.Net is an option. You can pretty much copy and paste your VBA code into a VB.Net project.

            • Re: SW2015 C# add in
              Checkcheck Master

              Thanks Simon for your reaction !


              I'm going to find out where to change the project settings, can you point me in the right direction ?

              If you have any tips for a tutorial, please let me know.


              Between C# and VB.Net, what should you advise me ?


              About registering in the registry, what is the right place ?


              HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\SolidWorks 2015\Addins


              Greetings !

                • Re: SW2015 C# add in
                  Amen Allah Jlili

                  For SW 2015:


                  0. Run VS with admin privileges
                  1. Change the framework:



                  2. Click on Assembly Information and check Make Assembly COM-Visible

                  3. We need to tell VS to use the right version of regasm and to do that go to Build and change the following settings:

                  Now simply build you project, run sw and your add-in should appear in the add-in manager!



                  If you use the first registry path, the addin will be available to all SolidWorks versions installed on the local machine.
                  The second means it will only be available for SolidWorks 2015.




                  As Simon Turner said, C# is preferable over C++ for many reasons one of which is C# provides you with a built-in garbage collector that manages your memory for you. In C++, you manage memory by yourself to avoid memory leaks.

                    • Re: SW2015 C# add in
                      Checkcheck Master

                      Thanks a lot Amen!

                      I'm gonna study when I'm back home.


                      Clear what about C# vs C++, what about C# vs VB.NET?



                        • Re: SW2015 C# add in
                          Simon Turner

                          C# and VB.Net are virtually interchangeable. There are tools that will convert a C# project to VB.Net and vice versa.

                          So it's really down to what you are comfortable with.

                          If you have been using VBA up to now, then VB.Net might be the best choice.

                          • Re: SW2015 C# add in
                            Amen Allah Jlili

                            There is nothing C# accomplishes that VB.Net can't (This goes against the common belief that C# is more "powerful" than VB.net). At the end of the day, all the C# and VB.net code is processed into intermediary language called the MSIL (Microsoft Intermediate language) which independent of the CPU before it gets complied into native code (machine readable binary which is CPU specific). So, not much of a major difference.


                            C# is "Cish" language like (C, C++, Java, objective C) so its syntax is close to C. It has advantages and shortcomings much like any other language in software development.


                            So when it comes to down to developing add-ins for SolidWorks, it's merely a preference of the person. Choose which ever you're comfortable using. Obviously, as Simon Turner, VB.net would be a good start if you're familiar with VBA (the little brother of VB.Net as I like to call it).

                            VB.net continues to be supported by Microsoft (Latest version is VB14) and you're good to go. Microsoft itself says there isn't a difference. I invite you to read this. Hopefully, it will help you make an informed choice.



                              • Re: SW2015 C# add in
                                Checkcheck Master

                                Thanks all of you guys for your support and advises !

                                I've read the white paper regarding the differences between C# and VB.Net, clear story, looks like I'm better off with VB.Net for now, changed my plan.


                                Are you familiar with the bug(s) in VBA(swp) which triggers the fatal error and will crash SW ?

                                How about VB.Net regarding bugs and errors, is it more stable than VBA or what ?

                                Should I expect the same trouble with crashing macro's/code or ?


                                A part of my macro is to scan all the dimensions names from the sketches, when a right combination is found a custom property 'Size' is created.

                                For example, when the macro found a combination 'OD' and 'L' in the dimension names the custom property 'Size' is created and the value 'OD x L' is placed on the drawing corner/BOM so you have always the accurate size of a part or assembly on your corner/BOM, when the user didn't give specified names to the dimensions the macro is calculating the 'Box Size' from a part or assembly and place it on the corner/BOM.

                                How would you accomplice this in VB.Net ?

                                Simon stated, 'You can pretty much copy and paste your VBA code into a VB.Net project.', of course that's where I'm going to start however, any suggestion are more then welcome.


                                Also a project based file handling system is integrated into my macro, it recognizes the project number, increase part/assembly numbers, save drawings also as PDF and if needed as DWG etc.

                                For now some recent project data like recent project number etc. is placed in a text file by the macro and read the next time the macro runs.

                                Is there a better option for this technique when using VB.Net ?


                                Thanks again for reading, as said, any suggestion are welcome.