Hi everyone,
when upgrading to .NET 6 and Esri.ArcGISRuntime 100.14.1 I am currently getting
a System.NullReferenceException by instantiating a KmlLayer with a KmlDataset (line 4).
Uri kmlUri = new Uri("someFile.kml", UriKind.RelativeOrAbsolute);
KmlDataset dataset = new KmlDataset(kmlUri);
await dataset.LoadAsync();
KmlLayer kmlLayer = new KmlLayer(dataset);
I had no problems with .NET Framework 4.8 and Esri.ArcGISRuntime 100.9.0 before.
When instantiating the KmlLayer with an Uri it works fine.
Would anyone of you have any advice as to what could be causing this?
Thanks in advance.
Solved! Go to Solution.
I was able to reproduce the problem! The error can only happen if a KmlLayer is created from a loaded KmlDataset. This is a relatively recent regression that happens when a constructor invokes the "loaded" callback before it's done initializing all the necessary fields.
The problem should be fixed in the next version of Runtime. For now, you can avoid the error by NOT loading the dataset before creating a layer, or by using a different KmlLayer constructor that takes a Uri or a PortalItem.
Thank you for taking the time to report this bug!
Hello Rob! I would be glad to look into this. Are you able to share a stack trace for this exception, or perhaps share a copy of the KML file that you are loading?
Hello,
sorry for the late reply. This exception occurs with every kml file. I copied the details below:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Esri.ArcGISRuntime
StackTrace:
at Esri.ArcGISRuntime.Mapping.KmlLayer.OnLayerLoaded()
at Esri.ArcGISRuntime.Mapping.Layer..ctor(CoreLayer layer)
at Esri.ArcGISRuntime.Mapping.KmlLayer..ctor(CoreKMLLayer coreLayer, KmlDataset dataset)
I was able to reproduce the problem! The error can only happen if a KmlLayer is created from a loaded KmlDataset. This is a relatively recent regression that happens when a constructor invokes the "loaded" callback before it's done initializing all the necessary fields.
The problem should be fixed in the next version of Runtime. For now, you can avoid the error by NOT loading the dataset before creating a layer, or by using a different KmlLayer constructor that takes a Uri or a PortalItem.
Thank you for taking the time to report this bug!
Thank you very much for your help.