Issue creating/updating features via CoreHost using ArcGIS Pro 2.5

1320
6
Jump to solution
03-25-2020 08:38 AM
LarsDomesjö
New Contributor III

Hello,

I have written a console application (in C#) which uses Core & CoreHost to update as well as create features in an GDB as well as an SDE.

This was working when I was using ArcGIS Pro 2.4, but I recently tried updating to ArcGIS Pro 2.5 and have been getting an error ever since when storing the feature.

This is what my code looks like:

using (var buildingsTable = geodatabase.OpenDataset<FeatureClass>(Constants.Building.TABLE_NAME))
{
    foreach (var building in newBuildings)
    {
        using (var rowBuffer = buildingsTable.CreateRowBuffer())
        {
                rowBuffer.FillFromBuilding(building);
                buildingsTable.CreateRow(rowBuffer).Dispose();
        }
    }
}

And this is the error which the core dll is giving me:

Klassen har inte registrerats

   vid ArcGIS.Core.Internal.IFeatureClassIOP.FeatureClass_CreateFeature(IntPtr featureClassHandle, IntPtr featureBufferHandle)
   vid ArcGIS.Core.Data.FeatureClass.CreateFeature(RowBuffer featureBuffer)
   vid ArcGIS.Core.Data.FeatureClass.CreateRow(RowBuffer featureBuffer)
   --- Slut på stackspårning för interna undantag ---
   vid ArcGIS.Core.Data.FeatureClass.CreateRow(RowBuffer featureBuffer)
   vid BALSynchronizer_v2.Services.BuildingFeatureService.UpsertBuildings(IEnumerable`1 buildings) i 

"Klassen har inte registrerats" is Swedish and translates to "The class has not been registrered"

Looks like this is some issue in the underlying COM-layer?

I've tried removing and re-installing ArcGIS Pro 2.5 without success.

Any suggestions?

Thanks in advance.

Best regards

Lars

0 Kudos
1 Solution

Accepted Solutions
LarsDomesjö
New Contributor III

Good morning Wolfgang,

Thanks for the thorough check! I was working on trying to create a working sample for my issue but was unable to reproduce it.

I then went back to my original solution and started taking things out, ultimately it was another Library which was causing the Issue with ArcGIS (GDAL).

After removing GDAL, ArcGIS started working properly again, strange that it was only appearing after upgrading to 2.5.x but guess that's some difference there 

Will switch to something other than GDAL to parse GML for the time being.

Thanks again!

BR

Lars

View solution in original post

0 Kudos
6 Replies
RichRuh
Esri Regular Contributor

Have you compiled this add-in with 2.5?

Although we recommend that editing code in a CoreHost app be wrapped with Geodatabase.ApplyEdits, I don't see anything wrong with the code.

--Rich

0 Kudos
LarsDomesjö
New Contributor III

Yes, i've recompiled with 2.5 as well as changed target framework to 4.8. I will try with an applyedits session for inserts as well (already have it for edits which are also failing)

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Lars,

 I will write a sample using your code snippet in ArcGIS Pro 2.5 and let you know what i find - sorry i ran out of time today but i'll do it first thing in the morning. Just to make sure when you compiled the project under 2.5 you did change the .Net framework to 4.8?  4.8 is a new requirement for 2.5.  https://community.esri.com/groups/arcgis-pro-sdk/blog/2020/02/07/at-pro-25-the-net-framework-is-chan...

- Wolf

0 Kudos
LarsDomesjö
New Contributor III

When you are saying compiled under 2.5, do you mean that i am referencing the 2.5 dlls? or are you refering to something else? (yes, I have the 2.5 dlls referenced).

Also had to change to .Net Framework 4.8 since the project wouldn't compile otherwise.

I tried isolating the issue to a new application which I would be able to include here, but my sample project seems to be working actually. I will try to get it to the same point which I have gotten my main application to and then I'll include it here.

Thanks!

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Lars,

 I wrote a CoreHost sample storing data in either an SDE or File Geodatabase.   i am using the RowBuffer as you do, Here is the main method writing the data:  I write a few hundred records with no problems.  But the data i am writing is static and doesn't come from another feature class or table.

private static void FeatureWrite(string gdbPath, string fcName, string writeJson)
{
  var theWriteInfoJson = System.IO.File.ReadAllText(writeJson);
  var writeIt = JsonConvert.DeserializeObject<WriteFieldInfo[]>(theWriteInfoJson);
  int count = 0;
  Host.Initialize();

  DatabaseConnectionFile dbConnection = null;
  FileGeodatabaseConnectionPath gdbConnection = null;
  if (System.IO.Path.GetExtension(gdbPath).ToLower().Equals(".sde"))
  {
    dbConnection = new DatabaseConnectionFile(new Uri(gdbPath));
  }
  else
  {
    gdbConnection = new FileGeodatabaseConnectionPath(new Uri(gdbPath));
  }
  using (Geodatabase geodatabase = dbConnection != null ? new Geodatabase(dbConnection) : new Geodatabase(gdbConnection))
  {
    using (FeatureClass writeFeatureClass = geodatabase.OpenDataset<FeatureClass>(fcName))
    {
      geodatabase.ApplyEdits(() =>
      {
        RowBuffer rowBuffer = null;
        Row row = null;
        try
        {
          FeatureClassDefinition featureDefinition = writeFeatureClass.GetDefinition();

          int lenghtIndex = featureDefinition.FindField("LENGTH");

          double baseX = 577059;
          double baseY = 3620749;
          double baseZ = 0;

          Coordinate3D coord1 = new Coordinate3D(baseX, baseY, baseZ);
          Coordinate3D coord2 = new Coordinate3D(baseX + 100, baseY + 100, baseZ);
          List<Coordinate3D> primCoords = new List<Coordinate3D>();
          primCoords.Add(coord1);
          primCoords.Add(coord2);

          PolylineBuilder primLineBuilder = new PolylineBuilder(primCoords);
          primLineBuilder.HasZ = true;

          while (count < MaxWriteRows)
          {
            using (rowBuffer = writeFeatureClass.CreateRowBuffer())
            {
              // Either the field index or the field name can be used in the indexer.
              rowBuffer[writeFeatureClass.GetDefinition().GetShapeField()] = primLineBuilder.ToGeometry();

              for (int idx = 0; idx < writeIt.Length; idx++)
              {
                var writeFieldInfo = writeIt[idx];
                if (string.IsNullOrEmpty(writeFieldInfo.stringValue))
                {
                  rowBuffer[writeFieldInfo.fieldName] = writeFieldInfo.intValue;
                }
                else
                {
                  rowBuffer[writeFieldInfo.fieldName] = writeFieldInfo.stringValue;
                }
              }
              row = writeFeatureClass.CreateRow(rowBuffer);
              count++;
            }
          }
        }
        catch (GeodatabaseException exObj)
        {
          Console.Error.WriteLine(exObj);
        }
        finally
        {
          if (row != null)
            row.Dispose();
        }
      });
    }
  }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I can see two differences: 
1) the use of geodatabase.ApplyEdits(() => {} ...

2) i don't dispose the row created with CreateRow - but as Rich Ruh pointed out to me your code looks correct in that regard.  So i changed my code to this:

using (row = writeFeatureClass.CreateRow(rowBuffer))
{
  // more work using row
}

All my tests worked fine.

LarsDomesjö
New Contributor III

Good morning Wolfgang,

Thanks for the thorough check! I was working on trying to create a working sample for my issue but was unable to reproduce it.

I then went back to my original solution and started taking things out, ultimately it was another Library which was causing the Issue with ArcGIS (GDAL).

After removing GDAL, ArcGIS started working properly again, strange that it was only appearing after upgrading to 2.5.x but guess that's some difference there 

Will switch to something other than GDAL to parse GML for the time being.

Thanks again!

BR

Lars

0 Kudos