xBimTeam / XbimExchange

XbimExchange contains several COBie schemas and serialisation functions as well as the Model Validation library adopted by theNBS digital toolkit.
https://xbimteam.github.io/
Other
46 stars 42 forks source link

Exception: an item with the same key already been added #15

Open mahmouds12 opened 7 years ago

mahmouds12 commented 7 years ago

Hello Xbim Team I am trying to create json file from a model but i get an exception at the following line: IfcToCOBieLiteUkExchanger ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);

Here's the exception: " at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)\r\n at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)\r\n at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value)\r\n at XbimExchanger.IfcToCOBieLiteUK.CoBieLiteUkHelper.GetTypeMaps() in C:\BuildAgent\work\f46659e6f579ee7\Xbim.Exchanger\IfcToCOBieLiteUK\COBieLiteUKHelper.cs:line 592\r\n at XbimExchanger.IfcToCOBieLiteUK.CoBieLiteUkHelper..ctor(IModel model, ProgressReporter reportProgress, OutPutFilters filter, String attributesMapsConfigurationFile, EntityIdentifierMode extId, SystemExtractionMode sysMode) in C:\BuildAgent\work\f46659e6f579ee7\Xbim.Exchanger\IfcToCOBieLiteUK\COBieLiteUKHelper.cs:line 208\r\n at XbimExchanger.IfcToCOBieLiteUK.IfcToCOBieLiteUkExchanger..ctor(IModel source, List`1 target, ReportProgressDelegate reportProgress, OutPutFilters filter, String configFile, EntityIdentifierMode extId, SystemExtractionMode sysMode) in C:\BuildAgent\work\f46659e6f579ee7\Xbim.Exchanger\IfcToCOBieLiteUK\IfcToCOBieLiteUkExchanger.cs:line 18..."

mahmouds12 commented 7 years ago

I downloaded the source project for XBIM.Exchange and traced the error the exception appears at COBieLiteUKHelper.cs at the following loop: foreach (var typeObjectToObjects in _definingTypeObjectMap) { foreach (var ifcObject in typeObjectToObjects.Value.Where(t => !(t is IIfcFeatureElement) && !assemblyParts.Contains(t))) { _objectToTypeObjectMap.Add(ifcObject, typeObjectToObjects.Key); } ReportProgress.IncrementAndUpdate(); } I solved it by adding a check inside the loop before adding if (!_objectToTypeObjectMap.ContainsKey(ifcObject)) { _objectToTypeObjectMap.Add(ifcObject, typeObjectToObjects.Key); }