Cannot create an instance of "MapControl"

Aug 28, 2013 at 7:15 AM
Edited Aug 28, 2013 at 7: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:
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Windows="clr-namespace:Mapsui.Windows;assembly=Mapsui.Windows" x:Class="TileMapWPF.MainWindow"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:Wpf="clr-namespace:TileMapWPF"
            mc:Ignorable="d"
        d:DesignWidth="1164" d:DesignHeight="345"
        Title="MainWindow" >
    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Windows:MapControl x:Name="mapControl" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />  <!-- *-->
    </Grid>
</Window>
  • Here I got this message:
"Could not load file or assembly 'System, Version=2.0.5.0, 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 6:13 AM
PLease, help somebody, I really need this map control for my app!
Sep 2, 2013 at 6:26 AM
Edited Sep 2, 2013 at 8:33 AM
Oh, It`s ok now, forgot to add a WpfRendering reference.
Oct 2, 2013 at 12:46 PM
Edited Oct 2, 2013 at 12:53 PM
This error appears only when I`m trying to use a NuGet version of Mapsui.

Here is the screenshot:

Image

Can you explain how to use a NuGet version of Mapsui for example to implement a simple MapControl? Or it is an error?
Coordinator
Oct 3, 2013 at 7:19 AM
Edited Oct 3, 2013 at 7: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:
<Grid>
     <windows:MapControl x:Name="FuuunkyMapControl"></windows:MapControl>
</Grid>
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 11:37 AM
Edited Oct 3, 2013 at 11:38 AM
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"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mapsui="clr-namespace:Mapsui.Windows;assembly=Mapsui.Windows"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:Wpf="clr-namespace:ETLtoMap"
            mc:Ignorable="d"
        Title="ETLtoMap" d:DesignWidth="1120" d:DesignHeight="345" >
    <Grid>
        <mapsui:MapControl x:Name="myMapControl"></mapsui:MapControl> 

    </Grid>
</Window>
And get this error:

"Could not load file or assembly 'System, Version=2.0.5.0, 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...
Coordinator
Oct 3, 2013 at 12:07 PM
oh, maybe there is something wrong with the namespace. This is my full xaml:
<Window x:Class="Fuuunky.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:windows="clr-namespace:Mapsui.Windows;assembly=Mapsui.Windows"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <windows:MapControl x:Name="FuuunkyMapControl"></windows:MapControl>
    </Grid>
</Window>
Oct 3, 2013 at 12:08 PM
I have another version of Mapsui.Windows.dll (0.3.0.0) 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 12:13 PM
Edited Oct 3, 2013 at 12: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 12:22 PM
Edited Oct 3, 2013 at 12: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 4: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.
Coordinator
Oct 3, 2013 at 5:51 PM
Have your tried to create a new project from scratch?

Here is the project. I wonder if it makes a difference:
https://dl.dropboxusercontent.com/u/53172278/Fuuunky2.zip

I use Windows 8 btw.
Oct 4, 2013 at 8:16 AM
Edited Oct 4, 2013 at 8: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...
Coordinator
Oct 4, 2013 at 12:47 PM
Perhaps you need to install .net framework 4.0.3.
Oct 4, 2013 at 2:09 PM
Edited Oct 4, 2013 at 2: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 12: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!