NullReferenceException in SharpMap.UI every time I drag the mouse

Topics: General Topics, SharpMap v0.9 / v1.x, WinForms Controls
Nov 29, 2007 at 9:56 AM

NullReferenceException in SharpMap.UI every time I drag the mouse

Hi everyone,

I tried to create a simple WinForms application with the great SharpMap.

But everytime I Drag the mouse (hold left mouse button and move the mouse) I get an System::NullReferenceException.
But I don't know why? Can someone help please?

!!Here the Exception text:

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at SharpMap.Forms.MapImage.MapImage_MouseMove(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseMove(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
Assembly Version: 0.9.2423.31553
Win32 Version:
CodeBase: file:///C:/Dokumente%20und%20Einstellungen/eads/Eigene%20Dateien/wrg305tool/trunk/debug/SharpMap.UI.DLL
Assembly Version: 0.9.2423.31552
Win32 Version:
CodeBase: file:///C:/Dokumente%20und%20Einstellungen/eads/Eigene%20Dateien/wrg305tool/trunk/debug/SharpMap.DLL

!!I initialize the SharpMap like this:

SharpMap::Forms::MapImage^ mapImage;

this->mapImage->ActiveTool = SharpMap::Forms::MapImage::Tools::None;
this->mapImage->Cursor = System::Windows::Forms::Cursors::Cross;
this->mapImage->Dock = System::Windows::Forms::DockStyle::Fill;
this->mapImage->Location = System::Drawing::Point(0, 0);
this->mapImage->Name = "MainMapImage";
this->mapImage->QueryLayerIndex = 0;
this->mapImage->Size = System::Drawing::Size(495, 277);
this->mapImage->TabIndex = 0;
this->mapImage->TabStop = false;
this->mapImage->MouseMove += gcnew SharpMap::Forms::MapImage::MouseEventHandler(this, &MainView::MapImage_MouseMove);
this->mapImage->MouseDrag += gcnew SharpMap::Forms::MapImage::MouseEventHandler(this, &MainView::MapImage_MouseMove);

Thanks in advance

P.S. when I click Preview in this forum and then click Compose all the Composed text is gone and I end up with a empty textbox :-(
Nov 30, 2007 at 2:04 PM
Ok I solved this.
Solution: First add at least on layer to your map.

But in the DemoWinForm application you can drag the without getting an exception.

Nevertheless SharpMap is a great piece of software.
May 12, 2009 at 12:32 PM

additional to the above solution, making the map disabled unltil you add layers also stops this