When placing GMapControl inside UserControl and then adding UseroControl to Form - MissingMethodException

Topics: Windows Forms
Mar 20, 2012 at 7:32 PM


I am trying to build a USerControl that contains a GMapControl. When I place the GMapControl directly on the Form, then it works as expected. If I however place the GMapControl on a UserControl, and then add that UserControl to the Form, I get errors.

For example:

My UserControl, Map.cs:

public Map()

            gMapControl1.MapProvider = GMapProviders.OpenStreetMap;
            gMapControl1.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
            gMapControl1.MinZoom = 1;
            gMapControl1.MaxZoom = 24;
            gMapControl1.Zoom = 9;

            top = new GMapOverlay("1");
            objects = new GMapOverlay("objects");
            routes = new GMapOverlay("routes");
            polygons = new GMapOverlay("polygons");


            gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick);
            gMapControl1.OnPolygonClick += new PolygonClick(gMapControl1_OnPolygonClick);

Then I add this UserControl to my Form by dragging it on there. Then I get an Exception:

Failed to create component 'Map'. The error message follows:
'System.MissingMethodException: Method not found: 'Void GMap.NET.WindowsForms.GMapControl.set_MapProvider(GMap.NET, MapProviders.GMapProvider)'.
   at OpenStreetMapTest.Map..ctor()'

If I have the same code that I have in the UserControl Map inside a Form, then no errors. Also, the set_MapProvider exists and works if I don't put the GMapControl inside a UserControl.

Any ideas?


Mar 20, 2012 at 9:34 PM

hm, never tried that

Mar 20, 2012 at 10:39 PM
Edited Mar 20, 2012 at 10:39 PM

Yeah, there is some form of bug there. It works if I add this code to the constructor of the form:


Map m = new Map();
m.Dock = DockStyle.Fill;

After I did some bubbeling (see here), then it works as expected.

Mar 21, 2012 at 12:57 PM

yes, you need to initialize the map in the constructor