The type initializer for 'SharpMap.Map' threw an exception.

Topics: SharpMap Project, WinForms Controls
Jul 1, 2013 at 4:33 PM
Edited Jul 1, 2013 at 4:50 PM
Dear all,

I am new to SharpMap. It might be a simple question but it really make trouble to me.

I want to use SharpMap.dll to build a desktop application (Windows form). I downloaded the SharpMap_1.0.RC3, I follows the tutorial to add a map control onto windows from by referencing SharpMap.UI. I have adjusted the target frametwork to .Net 4.0. My current machine is 64 bit Operating system.

But when I compiled, it pops up

"The type initializer for 'SharpMap.Map' threw an exception."

I do not know why, and I am looking for your helps or instruction!

By the way, I used Visual studio 2012.
Coordinator
Jul 1, 2013 at 5:43 PM
Hi, you need to add the assemblyRedirect for GeoAPI, se the release notes..


Redirecting GeoAPI
Until next version of NetTopologySuite is release you need to add an assemblyRedirect of GeoAPI in your config file
Add this configuration to your app's config-file.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="GeoAPI" publicKeyToken="a1a0da7def465678" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.7.1.0" newVersion="1.7.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Jul 1, 2013 at 6:03 PM
Many thanks, petlof, it indeed works for me! It take me half day to figure this out.
Aug 28, 2013 at 2:20 PM
Edited Aug 28, 2013 at 2:26 PM
I am new to SharpMap.
I ran into exact same issue and I added App.config file to my project as per the suggestion which looks like the following but still getting "TypeInitializationException". The version of SharpMap is 1.0.4.0
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="GeoAPI" publicKeyToken="a1a0da7def465678" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.7.1.0" newVersion="1.7.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
I will appreciate any help/guidance.

Thank you.
Aug 29, 2013 at 3:47 AM
Edited Aug 29, 2013 at 1:46 PM
Well, adding the MapBox during the run time resolved this. I am not sure I got lucky or what but not getting the error when I added the MapBox programmatically.
Coordinator
Aug 29, 2013 at 7:29 AM
musabiralo wrote:
I am new to SharpMap.
I ran into exact same issue and I added App.config file to my project as per the suggestion which looks like the following but still getting "TypeInitializationException". The version of SharpMap is 1.0.4.0
Did you get it from the download tab or from the nuget stream?
Aug 29, 2013 at 1:44 PM
I got it from Download Tab as i am not sure what nuget stream is. And the version number was SharpMap assembly version number, just to be clear.