ThinkGeo.com    |     Documentation    |     Premium Support

Wpf Core: Error message when adding an overlay on the map

Hi,

We are migrating Thinkgeo to a WPF core version.
When I run our application, in the loaded event, I get an “Object reference not set to an instance of an object” error.
However this error appears randomly, sometimes the application starts, everything works well and other times the error message appears.
The error appears when adding an overlay on the map (_wpfMap.Overlays.Add (overlay))

Have you ever encountered this problem ?

Thank you.
Regards.

Steph.

Error message :

at ThinkGeo.Core.MapViewBase.gEQ=(Object sender, AddedGeoCollectionEventArgs e)
at ThinkGeo.Core.GeoCollection1.OnAdded(AddedGeoCollectionEventArgs e) at ThinkGeo.Core.GeoCollection1.Add(String key, T item)
at ThinkGeo.Core.GeoCollection1.Add(T item) at Workspaces.Cartographie.Layers.LayerService.CréerOverlayRaster(IEnumerable1 couches, IEnumerable`1 coucheCartoIds, Boolean isBaseMap) in C:\StephTFSCore\Workspaces.Cartographie\Layers\LayerService.cs:line 204

  • $exception {“Object reference not set to an instance of an object.”} System.NullReferenceException
  • Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
    HResult -2147467261 int
    HelpLink null string
  • InnerException null System.Exception
    Message “Object reference not set to an instance of an object.” string
    Source “ThinkGeo.UI.Wpf” string
    StackTrace " at ThinkGeo.Core.MapViewBase.gEQ=(Object sender, AddedGeoCollectionEventArgs e)\r\n at ThinkGeo.Core.GeoCollection1.OnAdded(AddedGeoCollectionEventArgs e)\r\n at ThinkGeo.Core.GeoCollection1.Add(String key, T item)\r\n at ThinkGeo.Core.GeoCollection1.Add(T item)\r\n at Workspaces.Cartographie.Layers.LayerService.CréerOverlayRaster(IEnumerable1 couches, IEnumerable`1 coucheCartoIds, Boolean isBaseMap) in C:\StephTFSCore\Workspaces.Cartographie\Layers\LayerService.cs:line 204" string
  • TargetSite {Void gEQ=(System.Object, ThinkGeo.Core.AddedGeoCollectionEventArgs)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
    Attributes Private | HideBySig System.Reflection.MethodAttributes
    CallingConvention Standard | HasThis System.Reflection.CallingConventions
    ContainsGenericParameters false bool
    CustomAttributes La méthode System.Reflection.MemberInfo.get_CustomAttributes ne peut pas être appelée dans ce contexte. System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData>
  • DeclaringType {Name = “MapViewBase” FullName = “ThinkGeo.Core.MapViewBase”} System.Type {System.RuntimeType}
    IsAbstract false bool
    IsAssembly false bool
    IsCollectible La méthode System.Reflection.RuntimeMethodInfo.get_IsCollectible ne peut pas être appelée dans ce contexte. bool
    IsConstructedGenericMethod La méthode System.Reflection.MethodBase.get_IsConstructedGenericMethod ne peut pas être appelée dans ce contexte. bool
    IsConstructor false bool
    IsFamily false bool
    IsFamilyAndAssembly false bool
    IsFamilyOrAssembly false bool
    IsFinal false bool
    IsGenericMethod false bool
    IsGenericMethodDefinition false bool
    IsHideBySig true bool
    IsPrivate true bool
    IsPublic false bool
    IsSecurityCritical La méthode System.Reflection.RuntimeMethodInfo.get_IsSecurityCritical ne peut pas être appelée dans ce contexte. bool
    IsSecuritySafeCritical La méthode System.Reflection.RuntimeMethodInfo.get_IsSecuritySafeCritical ne peut pas être appelée dans ce contexte. bool
    IsSecurityTransparent La méthode System.Reflection.RuntimeMethodInfo.get_IsSecurityTransparent ne peut pas être appelée dans ce contexte. bool
    IsSpecialName false bool
    IsStatic false bool
    IsVirtual false bool
    MemberType Method System.Reflection.MemberTypes
    MetadataToken 100663828 int
  • MethodHandle {System.RuntimeMethodHandle} System.RuntimeMethodHandle
    MethodImplementationFlags La méthode System.Reflection.MethodBase.get_MethodImplementationFlags ne peut pas être appelée dans ce contexte. System.Reflection.MethodImplAttributes
  • Module {ThinkGeo.UI.Wpf.dll} System.Reflection.Module {System.Reflection.RuntimeModule}
    Name “gEQ=” string
  • ReflectedType ‘((System.Reflection.RuntimeMethodInfo)($exception).TargetSite).ReflectedType’ threw an exception of type ‘System.NotSupportedException’ System.Type {System.NotSupportedException}
  • ReturnParameter {System.Void } System.Reflection.ParameterInfo
  • ReturnType {Name = “Void” FullName = “System.Void”} System.Type {System.RuntimeType}
    ReturnTypeCustomAttributes La méthode System.Reflection.RuntimeMethodInfo.get_ReturnTypeCustomAttributes ne peut pas être appelée dans ce contexte. System.Reflection.ICustomAttributeProvider

Thanks Stephanie,
We did saw this issue before. If the map component not put into the wpf container. This may happen. More detail you can check here.

If this is not your case. Could you create a simple sample to reproduce this issue. We could look into more detail.

Thanks

Frank

Hi Franck,

Thanks for your answer.

Compared to the solution provided in this post, does this mean that in core, we have to add the map to a grid, in code behind ?
Currently in our application, we are adding the map to the grid in xaml (ie below).

    <Grid x:Name="GridPrincipaleWorskpace">
            <Grid.RowDefinitions>         
                < RowDefinition Height="Auto" />
                < RowDefinition Height="Auto" />
                < RowDefinition Height="*" x:Name="RowLayer" />
                < RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <wpf:MapView x:Name="Map"
                        Background="White"
                        Grid.Row="0"
                        Grid.RowSpan="4" />
.....
            </wpfMapView>
    </Grid>

.

With core, do we have to add the map to the grid in code behind ?

Thanks.
Regards.
Steph.

Thanks Steph,
No. You don’t have to add the map to the gird in code behind. What you are doing is correct with xaml . The point in the post is we can not just initialize the map by the simple two lines.

var FirstMap = new MapView();
FirstMap.Overlays?.Add(new LayerOverlay()); // Crash here

More detail is here

Sorry for the confuse. Back to your original issue. Could you send us the LayerService.cs file to us. We could look into more detail.

Thanks

Frank