This project has moved and is read-only. For the latest updates, please go here.


Topics: Algorithms, General Topics, SharpMap Project
Mar 4, 2010 at 2:40 PM

Everytime we try to compile a programm using the SharpMap Library we get this Exception

An unhandled exception of type 'System.BadImageFormatException' occurred in TestShapeFileReader.exe

Additional information:

The File or Assembly "SharpMap, Version=0.9.3582.17966, Culture=neutral, PublicKeyToken=null"

or a dependency  was not found.  It has been tried to load a File with a wrong Format.


We need the Library for a school project of ours, and it runs perfectly fine on one of my collegues PCs while it doesn't run on mine, or on the PC of my Partner.

Here is the Code we want to run:

public Form1()

            this.MouseWheel += new MouseEventHandler(Form1_Mousewheel);
            //Declare Map
            testMap = new SharpMap.Map(new Size(20000, 20000));
            //add layer
            SharpMap.Layers.VectorLayer VLayer = new SharpMap.Layers.VectorLayer("TestLayer");
            SharpMap.Data.Providers.ShapeFile testFile = new SharpMap.Data.Providers.ShapeFile(@"C:\Users\Nahro\Documents\PUC_C++_Projekte\c#\TestShapeFileReader\salzburg shape\wa_la.shp");
            VLayer.DataSource = testFile;

            System.Drawing.Image imgMap = testMap.GetMap();
            pbOutput.Image = imgMap;



We really don't know what we are missing, so please if somebody could help us!


PS: We actually use a German Version of MS Visual Studio 2008, and the Exception Informations were translated by me, so if it helps here is the Original Exception Text:

An unhandled exception of type 'System.BadImageFormatException' occurred in TestShapeFileReader.exe

Additional information: Die Datei oder Assembly "SharpMap, Version=0.9.3582.17966, Culture=neutral, PublicKeyToken=null" oder eine Abhängigkeit davon wurde nicht gefunden.

Es wurde versucht, eine Datei mit einem falschen Format zu laden.


Thanks to everyone willing to help




Mar 4, 2010 at 3:25 PM
Edited Mar 4, 2010 at 10:01 PM

Hello nahro1001,

did you compile the sharpmap library yourself? If not, please do that.

It is hard to tell what causes your error, either

  • one of the referenced libraries is corrupt
  • one of the referenced libraries was compiled for x64 and you try to run it on x86 (or vice versa)
  • ...

Btw, the Map you are createing is fairly large. The call to map.GetMap will return an image of that size (20000x20000).
I assume you don't want that.

Hth FObermaier

P.S.: I just noticed that SharpMap, SharpMap.Extensions and SharpMap.UI are, by default, all build to target x86 platforms. Even if the configuration says "All Platforms". Try setting the target platform for your application to x86 and see if it works.

Mar 5, 2010 at 10:41 AM
Edited Mar 5, 2010 at 10:41 AM

Thank you very much for the quick reply!

With your tipp checking the compatiblity for x64 you were right, while me and my partner use x64 the other System were running x86

We will try if this is solving the problem, but I pretty sure this is it.

thanks again!

PS: I know that the size setting is far to high, we were just messing around ;D