Select to view content in your preferred language

AddBookmark problem using new Silverlight API v2.2.0.629

715
8
09-26-2011 05:51 AM
KeithCollins
New Contributor
Has anybody else experienced problems using the Addbookmark method of the ESRI.ArcGIS.Client.Toolkit.Bookmark in the version 2.2 (2.2.0.629) of the Silverlight API? Since upgrading, I now get an "Object reference not set to an instance of an object" exception in VB.  Rolling the Client & Toolkit reference back to v2.1 (2.1.0.446) solves problem and works perfectly. I even tried using the bookmark code from the interactive samples on the ESRI site and this gives same error.  There are no documented changes to the Toolkit DLL listed on the site between V2.1 and V2.2.
0 Kudos
8 Replies
DominiqueBroux
Esri Frequent Contributor
I can't reproduce the issue with the interactive sample.

Could you give more infos on how to reproduce the issue?

You can also try to reset the application storage for this site :
   - right click on the map
   - silverlight dialog box
   - application storage tab
   - remove http://help.arcgis.com
0 Kudos
KeithCollins
New Contributor
Hi Dominique, thanks for replying.
This is a very simple Silverlight project (Visual Web Developer 2010) to illustrate.
If Client & Client Toolkit v2.1.0.446 is used then it works fine, if v2.2.0.629 is used then I get NullReferenceException on the gblBookMarks.AddBookmark statement.

XML<UserControl x:Class="SilverlightApplication5.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
<!-- Map Control -->
<esri:Map x:Name="Map" Background="White" Loaded="Map_Loaded" IsLogoVisible="False" ZoomDuration="0:00:02" PanDuration="0:00:02"
Canvas.Left="0" Canvas.Top="0" Height="600" Width="800" Cursor="Arrow">

<esri:Map.Extent>
<esri:Envelope XMin="-20037507.2295943" XMax="20037507.2295943" YMin="-19971868.8804086" YMax="19971868.8804086">
<esri:Envelope.SpatialReference>
<esri:SpatialReference WKID="102100"/>
</esri:Envelope.SpatialReference>
</esri:Envelope>
</esri:Map.Extent>

<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="BaseLayer"
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" Opacity="60" />
</esri:Map.Layers>
</esri:Map>
</Grid>
</UserControl>

VB
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports System.Windows.Controls
Imports System.Windows.Media
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry
Imports ESRI.ArcGIS.Client.Symbols

Public Class MainPage
Inherits UserControl
Public Shared gblBookMarks As New ESRI.ArcGIS.Client.Toolkit.Bookmark

Public Sub New()
InitializeComponent()
End Sub
Private Sub Map_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Map.Loaded
Map.Focus()
AddBookMark("TEST", -234635, 7787628, -228574, 7791485)

End Sub

Private Sub AddBookMark(ByVal Name As String, ByVal XMin As Double, ByVal YMin As Double, ByVal XMax As Double, ByVal YMax As Double)
Dim bmextent As New ESRI.ArcGIS.Client.Geometry.Envelope
bmextent.XMin = XMin : bmextent.YMin = YMin
bmextent.XMax = XMax : bmextent.YMax = YMax
'bmextent.SpatialReference = _Map.SpatialReference
gblBookMarks.AddBookmark(Name, bmextent)

End Sub
End Class
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I don't see in your code when and how is initialized 'gblBookMarks', so it's difficult to analyze why it's null.

Nevertheless it seems you are relying on the load order i.e. the bookmark is loaded before the map.

Why not add your first bookmark when the bookmark is loaded instead of the map?
0 Kudos
KeithCollins
New Contributor
Dominique,
gblBookmarks is declared as public in the declarations section of the Main page VB Code:

Public Shared gblBookMarks As New ESRI.ArcGIS.Client.Toolkit.Bookmark

I missed a line out of the previous sample, in the Map_Loaded event (fired when map loads) there should be an additional line before adding the first bookmark (the bookmark is not added until map is loaded as far as I can understand):

gblBookMarks.Map = Map

This associates the bookmark object with the map.

To be clear, I am not using the standard bookmark control as provided - I am setting up my own bookmark object and populating it with bookmarks - these bookmarks are shown in a custom dialog, and I have code to handle when one is selected which zooms the map to the appropriate extent.

The ESRI.ArcGIS.Client.Toolkit.Bookmark.Addbookmark method has the same parameters as previous DLL version (Public Sub AddBookmark(ByVal name As String, ByVal extent As ESRI.ArcGIS.Client.Geometry.Envelope). As far as I can see, I am correctly setting up an Envelope object to pass to the Addbookmark method, and the Name is also defined correctly as a string, so I cannot see what can possibly be null, and the same code worked perfectly in the previous version of the API.

Thanks for you assistance again.
0 Kudos
KeithCollins
New Contributor
Michelle,
I decided to have another look after getting your post, as it was driving me nuts.

Yesterday I downloaded the very latest Silverlight API (2.3.0.774) in the hope that the problem had been fixed, or to see if my previous installation had been corrupt in some way.  The same problem exists with the new version.

I have come to the conclusion that the error is not related to the parameters being passed (Name and Extent), but is being triggered by something else that happens inside the DLL when the AddBookmark method is called.

I tried without success to set as many of the Bookmarks class properties as I could, to see if the null reference was down to them.

I eventually experimented by adding a physical bookmark control back in to the XAML (previously I had just created a new Bookmarks class object in code - which used to work with version 2.1).  After adding the object to the XAML, and using its name as the reference instead, I can get the code to work again.  I tried to set the visibility property of this object to collapsed (to hide it) - but this re-introduces the error condition.  This leads me to think that the API is trying to do something to a physical bookmark control, even if it is not there!

I then tried to set the width and height of the physical bookmark control to 10,10.  This also causes error, as I think the bookmark list is not visible.  Eventually, this code will now work - notice that the height has to be large enough to encompass the list region:

XAML

<esri:Bookmark HorizontalAlignment="Left" Margin="0,0,0,0" Name="gblBookmarks"
                 VerticalAlignment="Top" Width="0" Height="100" Visibility="Visible"
                 Map="{Binding ElementName=Map1}" UseIsolatedStorage="False"/>


VB

Private Sub AddBookMark(ByVal Name As String, ByVal XMin As Double, ByVal YMin As Double, ByVal XMax As Double, ByVal YMax As Double)
        Dim extent As New ESRI.ArcGIS.Client.Geometry.Envelope
        extent.XMin = XMin : extent.YMin = YMin
        extent.XMax = XMax : extent.YMax = YMax
        gblBookmarks.AddBookmark(Name, extent)

End Sub


Hope this helps, not an ideal solution I know, but at least I can now start using the other new features in the latest API version.
0 Kudos
KeithCollins
New Contributor
Interestingly, further to the last post, I forgot to mention that I found the solution partly by experimenting with a couple of examples in the ESRI API Reference on the ArcGIS API For Silverlight Site.

There are a couple of examples in the ESRI.Client.Toolkit.Bookmark section.

The example included in Methods/AddBookMark ("Four Corners Kiosk") when copied exactly as provided, fails with the same error message when run.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...


The second example provided at the main Bookmark class level (the one with Map of India) does work as provided.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...
0 Kudos
JohnGravois
Frequent Contributor
This issue was logged as [#NIM076787  Adding a bookmark during the Bookmark::Loaded event using the Bookmark::AddBookmark method returns a Null Reference error.  ].  A fix is currently in QA.

In the meantime, it is necessary to create a Bookmark.MapBookmark object and add it to the bookmarks collection.

//workaround using ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark()
Bookmark.MapBookmark mbitem= new Bookmark.MapBookmark();
mbitem.Extent = myExtent;
mbitem.Name = "Test";
myBookMarks.bookmarks.Add(mbitem);

API reference for Bookmark.MapBookmark class:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...
0 Kudos
ChristopherHill
Occasional Contributor
I was able to reproduce this bug it will be fixed in our next up comming release.
0 Kudos