Is it possible to corrupt SolidWorks install using COM objects?

Hi there everyone,

I’m not really a developer, I learn things as I go, and I think that’s why I had to completely reinstall SolidWorks 3 times in the last 3 months. I’m using CadBooster.SolidDNA librarys to build my apps. To achive some funcionalities I have to use “Unsfe objects”. I’m also more familiar with them from the VBA macros.

Code example:
//Globals.swModel → SolidDNA model object
ModelDoc2 swModel = Globals.swModel.UnsafeObject;
IFeature swMateFeature = null;
IFeature swMateSubFeature = null;

        var swFeat = swModel.IFirstFeature();
        while (swFeat != null)
        {
            if (swFeat.Name == "Mates")
            {

                swMateFeature = swFeat;
            }
            swFeat = swFeat.IGetNextFeature();
        }

        swMateSubFeature = (IFeature)swMateFeature.GetFirstSubFeature();
        ...
        swModel = null;
        swFeat = null;
        swMateFeature = null;
        swMateSubFeature = null;

When working with unsafe object, the description clearly says to handle the disposal. From the AngelSix videos, I remember that he used Marshal.ReleaseComObject(Object), but some Google hits say that this is not required and setting the variables to null is enough.

My question is, what is the correct way of disposing of unsafe objects? and what happens if the code fails before you manage to dispose?

Has anyone else managed to stop Solidworks from working this way? Mine gets stuck on the splash screen, saying “verifying license”.

Thank you.:slight_smile:

Since it is not a .NET managed resource, you need to release it. The same thing goes for I/O streams like reading data from your disk and connections to SQL databases.

I don’t think your add-in is corrupting SOLIDWORKS. It might be some bad code that throws an unhandled exception. Run SW without add-in and your license should verify provided it is a valid one.

Hi!
I’m not an expert so I would only suggest to check @PeterBrinkhuis answer to a previous question of mine regarding SolidDNA:

I hope it helps!

1 Like

I’m with Amen on this one, it’s very unlikely that your code broke solidworks. I’ve never been able to break it in all my time developing.