15 Replies Latest reply on Aug 30, 2018 2:15 PM by Keith Rice

    Embed Interop Types?

    Taus Moller

      I was looking at Artem Taturevich's nifty tool for creating addins(SwEx.AddIn ). At the very start of the introduction video it is mentioned that it is recommended to set Embed interop types to false. In our development we have it set to true, but only because that is how the Solidworks' own template is set up. So i tried googling a bit and found that it was recommended several places like here and here. I am interested to know why this is recommended. Additionally i couldn't find any official word on it. so i was wondering if there if we should bother changing it. One of the links claims that it is needed to target CLR4. However we seem to be able to do that anyway. The other talks about being able to do "edit and continue" which would indeed be pretty cool, however i strongly suspect there are other issues with this as we also link som c++ libraries and some other stuff.

       

      Unfortunately it seems that it is not entirely free to make the switch as we would have to go through the our addin and do a whole bunch extra type casting. Therefore i would really like to hear peoples recommendation/opinion and reasoning on this. Are we ok to just keep embed interop types set, or should bite the bullet and change it?

        • Re: Embed Interop Types?
          Artem Taturevych

          When you embed your interops it basically means that the interface definitions are getting copied directly  to you assembly. So this is how full name looks like for SOLIDWORKS type when interop embedded:

          And this is when it is not embedded:

          The issues I have seen relates to casting (especially for some sort of handlers, i.e. property manager page, triad manipulator, callout) so InvalidCastException is thrown as SOLIDWORKS cannot 'recognise' that the COM type implements required interface.

           

          I have also seen Property Manager Pages displayed incorrectly when interops are embeded. This is something which I cannot constantly reproduce. But everytime the add-in/stand-alone behaves 'weirdly', this is usually fixed by Embed Interop Types. For example here is a recent case: https://forum.solidworks.com/message/884188#comment-884188

           

          Currently I do not have any example demonstrating the issue neither I found any solid proof or API reference for the possible issue, but I definitely seen strange behaviour with this before and I never seen this with interops embeded so I always have this option set to False and recommend to have it set to false.

          • Re: Embed Interop Types?
            Keith Rice

            My company has written hundreds of .NET programs for customers over the past several years and I have only found one instance where Embed Interop Types = True was causing a problem. In this case we weren't getting an exception, it was just causing dropdown menus to look and work incorrectly. But like Artem said, SolidWorks is obviously failing to execute certain calls.

             

            Since problems like I just shared seem to be the exception and not the norm, my company uses Embed Interop Types = True because simplifying the number and size of the binaries is a nice (albeit non-essential) benefit, in my opinion. If you want to be as safe as possible, though, I can understand why you would want to set it to False.

             

            Keith

            SolidWorks API Training and Services

              • Re: Embed Interop Types?
                Oleg Bezyaev

                "because simplifying the number and size of the binaries is a nice" - that's all? It's like using ILMerege just to make the user happy. The main thing is not correct code, not any not obvious "ComException" or "ThreadException" or great thing like RPC_DISCONNECT, just make it's smaller!!! I think Artem, who have tens of years of experience, was (and will) right.

                  • Re: Embed Interop Types?
                    Keith Rice
                    1. We wouldn't ship code that is throwing exceptions, though. You seem to miss the point that some developers always set the property to False so they don't have to worry about it ever causing problems, not because setting it to False is inherently superior. If you always set it to false, regardless of whether it was necessary, then you miss out on your binaries being as simple as possible, not to mention that there's no need to remember to modify the property's value (unless NuGet or a template is used).
                    2. Scott Stanley, the head of SolidWorks API development at SolidWorks Corp, recommended using it (or was at least enthusiastic about its use) when I asked him in person.
                    3. Hans Passant, the 5th highest ranked user on StackOverflow, wrote this about the property: "Never [set Embed Interop Types = False], it is a very awesome feature that solves irksome deployment details." (source) Of course, he's not a SolidWorks API developer and therefore hasn't encountered some of the problems we have, but the point remains that its benefits aren't trivial.

                     

                    Keith

                    SolidWorks API Training and Services