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
494 stars 173 forks source link

NullReferenceException thrown on Xbim's IFCStore BeginTransaction method #572

Closed EnzoLefrancois closed 3 months ago

EnzoLefrancois commented 3 months ago

When trying to begin a second transaction on a IFCStore, a NullReferenceException is thrown. My goal is to separate the classic IFC initialization (credentials, project, building) from the real "design" (adding beams, ...). To achieve this, I need to create separate transactions on the IFCStore I'm using.

  1. I create a transaction to add the project and building informations and commit

  2. I create a second transaction to add various elements. When creating this transaction, it fails. No details are given and I can't debug it further than my code. See sample code.

Assemblies and versions affected:

Xbim.Essentials 6.0.445

Steps (or code) to reproduce the issue:

public IFCHelper()
{
    var credentials = CreateCredentials();

    LocalIFCModel = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4, XbimStoreType.InMemoryModel);
    using (LocalIFCModel)
    {
        using (var txn = LocalIFCModel.BeginTransaction("Creating IFC"))
        {
            LocalIFCProject = InitializeProject(LocalIFCModel, "PROJECT : TEST");
            LocalIFCBuilding = CreateBuilding(LocalIFCModel, LocalIFCProject, "BUILDING : TEST");
            txn.Commit();
        }
    }

    using (LocalIFCModel)
    {
        using (var txn = LocalIFCModel.BeginTransaction("Do something else")) // HERE !
        {
            // Do something else
            txn.Commit();
        }
    }
}

Expected behavior:

I guess I should be able to create a second transaction without any problems, as the first one has been commited.

Actual behavior or exception details:

NullReferenceException is thrown on second BeginTransaction method call (see "HERE !" comment in sample code). I do not have any more details nor can I debug the code further than mine.

EnzoLefrancois commented 3 months ago

Nevermind, I was just using the "using" keyword wrong. Sorry for the inconvenience !