Select to view content in your preferred language

Trying to used class derived from SelectionMapAction causes exception

414
1
07-28-2011 04:28 PM
BrianTrout
Emerging Contributor
When I tried to derive a class from SelectionMapAction and use it, ESRI code raises an exception.  I checked that the constructor was being called and it was.  I have tried what I can think of and I am stumped.  To make sure it wasn't something specific to my map, I duplicated this issue using the "Mobile Walkthrough (10.0)" (BasicWorkThrough_Win) sample code and a different map. 

My code changes to the sample code are below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Mobile.MapActions;

namespace WindowsFormsApplication2
{
    public class CustomSelectionMapAction : SelectionMapAction
    {
        public CustomSelectionMapAction()
            : base()
        {
        }

        public CustomSelectionMapAction(System.ComponentModel.IContainer container)
            : base(container)
        {

        }
    }
}


Then I replaced the Pan button code with:

private void Pan_Click(object sender, EventArgs e)
    {
      //map1.CurrentMapAction = panMapAction1;
        map1.CurrentMapAction = new ESRI.ArcGIS.Mobile.MapActions.SelectionMapAction();  //line 1
        map1.CurrentMapAction = new CustomSelectionMapAction();  //line 2
    }


When I click the button, line 1 using the SelectionMapAction goes through fine, but line 2 using my Custom class generates this exception in esri code:

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.Cursor..ctor(Stream stream)
       at ESRI.ArcGIS.Mobile.MapActions.SelectionMapAction.OnActiveChanging(Boolean active)
       at ESRI.ArcGIS.Mobile.MapActions.MapAction.set_Active(Boolean value)
       at ESRI.ArcGIS.Mobile.Map.set_CurrentMapActionIndex(Int32 value)
       at ESRI.ArcGIS.Mobile.Map.set_CurrentMapAction(MapAction value)
       at WindowsFormsApplication2.Form1.Pan_Click(Object sender, EventArgs e) in C:\Documents and Settings\brian.trout\Desktop\BasicWorkThrough_Win\WindowsFormsApplication2\Form1.cs:line 87
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at WindowsFormsApplication2.Program.Main() in C:\Documents and Settings\brian.trout\Desktop\BasicWorkThrough_Win\WindowsFormsApplication2\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


Am I doing something wrong?
0 Kudos
1 Reply
BrianTrout
Emerging Contributor
I just tried switching:
public class CustomSelectionMapAction : ESRI.ArcGIS.Mobile.MapActions.SelectionMapAction

to
public class CustomSelectionMapAction : ESRI.ArcGIS.Mobile.MapActions.DragRectangleMapAction


And it works without an error.  I am missing something related specifically to the SelectionMapAction class.
0 Kudos