Cannot create an instance of "MapControl"

Aug 28, 2013 at 8:15 AM
Edited Aug 28, 2013 at 8:16 AM
Hello everyone!

I am using a NuGet package of Mapsui. When I`m trying to add a MapControl I get an error:

Cannot create an instance of "MapControl".

Here is the XAML code:
        xmlns:Windows="clr-namespace:Mapsui.Windows;assembly=Mapsui.Windows" x:Class="TileMapWPF.MainWindow"
        d:DesignWidth="1164" d:DesignHeight="345"
        Title="MainWindow" >
    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Windows:MapControl x:Name="mapControl" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />  <!-- *-->
  • Here I got this message:
"Could not load file or assembly 'System, Version=, Culture=nuetral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file spcified."

I`m using VS2012 Express. Framework ver. 4.5

Why does this happen and what I should do to resolve this problem?
Thank you!
Sep 2, 2013 at 7:13 AM
PLease, help somebody, I really need this map control for my app!
Sep 2, 2013 at 7:26 AM
Edited Sep 2, 2013 at 9:33 AM
Oh, It`s ok now, forgot to add a WpfRendering reference.
Oct 2, 2013 at 1:46 PM
Edited Oct 2, 2013 at 1:53 PM
This error appears only when I`m trying to use a NuGet version of Mapsui.

Here is the screenshot:


Can you explain how to use a NuGet version of Mapsui for example to implement a simple MapControl? Or it is an error?
Oct 3, 2013 at 8:19 AM
Edited Oct 3, 2013 at 8:22 AM
I could not reproduce this. I just created a WPF project with .net 4.5. Added Mapsui with Package Manager Console:
PM> Install-Package Mapsui
Then added a MapControl to the main form:
     <windows:MapControl x:Name="FuuunkyMapControl"></windows:MapControl>
Then added a layer in code behind:
FuuunkyMapControl.Map.Layers.Add(new TileLayer(new OsmTileSource()));
Running this shows a full window map.

What happens if you do it exactly like this? What did you do differently?
Oct 3, 2013 at 12:37 PM
Edited Oct 3, 2013 at 12:38 PM
Mostly the same: I create a new WPF proj with .Net 4.5, add the Nuget Package via manager console... the only thing is mapsui:MapControl instead of windows:MapControl. Here is my XAML code (like in wpf sample):
<Window x:Class="ETLtoMap.MainWindow"
        Title="ETLtoMap" d:DesignWidth="1120" d:DesignHeight="345" >
        <mapsui:MapControl x:Name="myMapControl"></mapsui:MapControl> 

And get this error:

"Could not load file or assembly 'System, Version=, Culture=nuetral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified."

Still don`t understand why does this happen...
Oct 3, 2013 at 1:07 PM
oh, maybe there is something wrong with the namespace. This is my full xaml:
<Window x:Class="Fuuunky.MainWindow"
        Title="MainWindow" Height="350" Width="525">
        <windows:MapControl x:Name="FuuunkyMapControl"></windows:MapControl>
Oct 3, 2013 at 1:08 PM
I have another version of Mapsui.Windows.dll ( and I`ve found that if I delete the newer one and add this one - it do works. But this control works on another logic as I see and only with sharpmap layers (!?).
Oct 3, 2013 at 1:13 PM
Edited Oct 3, 2013 at 1:16 PM
unfortunately it gives the same result :(

Maybe there is something wrong with VS. I am so disapointed. Your library is amazing and I can`t use it.
Oct 3, 2013 at 1:22 PM
Edited Oct 3, 2013 at 1:25 PM
Pauldendulk, maybe you can share this small working proj and I will try this one? If it`s not a problem ofcourse. If it will not work too I will reinstall my VS. Maybe this would solve the problem.
Oct 3, 2013 at 5:00 PM
Tried to do the same on another pc (Win 8, first one was win7) and got the same error. But I can run it and the map works! Tomorrow will try it on my work computer.
Oct 3, 2013 at 6:51 PM
Have your tried to create a new project from scratch?

Here is the project. I wonder if it makes a difference:

I use Windows 8 btw.
Oct 4, 2013 at 9:16 AM
Edited Oct 4, 2013 at 9:38 AM
Unfortunately I have the same problem in your project. Both on Win 7 and Win 8. I do can compile and run the project. And the map control works. But in the designer I see this error and I can not work with the control.

In this way there is something wrong with the designer. But I can not understand why it works on your desktop and can`t work on my two different...
Oct 4, 2013 at 1:47 PM
Perhaps you need to install .net framework 4.0.3.
Oct 4, 2013 at 3:09 PM
Edited Oct 4, 2013 at 3:09 PM
I reinstalled both 4.0, 4.0.3, 4.5 and nothing changed. Paul, thank you for your help and time. I`ll try to do something on the weekends.
Oct 16, 2013 at 1:47 PM
Hi, Paul den Dulk! I solved the problem. That was as simple as snow. It does not work on Visual Studio 2012 Express, but it do works on Professional version. Now it`s ok. Thank you for your framework and help!