xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
485 stars 172 forks source link

IO access exception saving store #495

Open theebow opened 1 year ago

theebow commented 1 year ago

Hi team I had problem with this following code on V5.1.341 :

IfcStore::SaveAs is throwing a system.io.exception (can't access process, the process is already in use....)

            var myCredentials = new XbimEditorCredentials
            {
                ApplicationDevelopersName = "T",
                ApplicationFullName = "xBIM Toolkit",
                ApplicationIdentifier = "xTBIMKIT",
                ApplicationVersion = "1.0",
                EditorsFamilyName = "R",
                EditorsGivenName = "M",
                EditorsOrganisationName = "TSI"
            };

            try
            {
                IfcStore store = IfcStore.Create(filepath, myCredentials, XbimSchemaVersion.Ifc4);

                using (var txn = store.BeginTransaction("Create Project"))
                {
                    IfcProject myProject = store.Instances.New<IfcProject>();
                    myProject.GlobalId = new Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId(System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 23));
                    myProject.Initialize(ProjectUnits.SIUnitsUK);
                    myProject.UnitsInContext.SetSiLengthUnits(IfcSIUnitName.METRE, IfcSIPrefix.MILLI);
                    myProject.Name = "Debug export";

                    txn.Commit();
                }

                **store.SaveAs(filepath);**
            }
            catch (Exception ex)
            {
            }

after investigation, this one works :


            try
            {
                IfcStore store = IfcStore.Create(myCredentials, XbimSchemaVersion.Ifc4, Xbim.IO.XbimStoreType.InMemoryModel);

                using (var txn = store.BeginTransaction("Create Project"))
                {
                    IfcProject myProject = store.Instances.New<IfcProject>();
                    myProject.GlobalId = new Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId(System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 23));
                    myProject.Initialize(ProjectUnits.SIUnitsUK);
                    myProject.UnitsInContext.SetSiLengthUnits(IfcSIUnitName.METRE, IfcSIPrefix.MILLI);
                    myProject.Name = "Debug export";

                    txn.Commit();
                }
                store.SaveAs(filepath, Xbim.IO.StorageType.Ifc);

            }
            catch (Exception ex)
            {
            }

For information the first code is an upgrade from one used with an older Xbim version Hope this will help you

best regards

andyward commented 1 year ago

Thanks - will see if we can repro and get a fix in. Sounds like an EsentModel issue