Rhino Common : Access Violation Exception

Hi ,Team I am working with Rhino Plugin ,
I have a one file which Has 1300 around Block Instance
I have created a Plugin which Exports a step file for each Block.
But when only 200 to 300 file Exported .Then Rhino Common Throws AccessVoilation Exception
One More observation is If we try this again on same files with some of previously Exported Files it works.
Is there any specific mistake am ,I doing here

[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
        public ElementGeometry CreateBRepElement(string stepFolderPath, RhinoObject subObject, Transform xform)
        {
            Metrics.StartTracking("CreateBRepElement:CreateBRepGeometry");
            ElementGeometry bRepGeomet = null;
            RhinoDoc doc;
            GeometryBase geometry;

            CreateStepFileFromRhinoObject.TransformGeometry(subObject, xform, out doc, out geometry);

            if (geometry.IsValid)
            {
                doc.Objects.Add(geometry, subObject.Attributes);
                string stepFilePath = System.IO.Path.Combine(stepFolderPath, subObject.Id + ".stp");
                try
                {
                    **FileStp.Write(stepFilePath, doc, new FileStpWriteOptions());**
                    bRepGeomet = CreateBRepGeometry(stepFilePath, subObject);
                }
                catch (AccessViolationException ave)
                {
                    
                    StartUploadingExchange.CounterForInvalidObjects++;
                    ReadWriteExchangeData.GetInstance().GlobalStopWatchTimeStamp.CreateTimeStamp("[EXCE]: (Write)From CreateBRepElement Function: AccessViolationException - " + ave.Message, TimeSpan.Zero, false);
                }
                catch (Exception e)
                {
                    StartUploadingExchange.CounterForInvalidObjects++;
                    ReadWriteExchangeData.GetInstance().GlobalStopWatchTimeStamp.CreateTimeStamp("[EXCE]: (Write)From CreateBRepElement Function: " + e.Message, TimeSpan.Zero, false);
                }
               
            }

File.Write operation Throws Exception

is there a file you can share with us?

Hi Sushant,

I’m happy to help here but I need to be able to repeat what you’re doing in a debugger so I can see why the exception is being thrown.

So, like Travis mentioned, a file would be handy. Is this something you’re calling from grasshopper? We need the whole picture to drill down on it.

Tim

Have you added logging to make certain you are not getting duplicate filenames and running into File AccessViolations if you are doing this in a fast loop.

Also are you disposing of the geometry object, I believe GeometryBase implements IDisposable, so you should be disposing of the object before you exit any loop (IMHO).

public abstract class GeometryBase : CommonObject
public abstract class CommonObject : IDisposable, ISerializable