[mapserver-users] Type initializer exception with C# MapScript

Daniel Walton dgwalton at gmail.com
Fri Oct 2 07:55:02 PDT 2009


Hey guys,

I'm new to MS, and using the MS4W distribution. It was the only Windows
binary dist. I found that had C# MapScript set up. Anyway, I get the
following exception when I try to construct a mapObj:

*The type initializer for 'OSGeo.MapServer.mapscriptPINVOKE' threw an
exception.*

Anyone else out there seen this?


I have referenced mapscript_csharp.dll compiled by the MS4W folks, and here
is the properties pane in VS2008:

*Aliases: global
Copy Local: true
File Type: Assembly
Identity: mapscript_csharp
Path:
C:\Domains\Website1\ImageService\ImageService1\bin\mapscript_csharp.dll
Resolved: true
Runtime Version: v2.0.50727
Specific Version: true
Strong Name: true
Version: 1.0.3491.26938*


Here is the basic structure of my code:

 private void CreateMap(string folder)
        {
            //Add a new map (based on a unique ticket string)
            string mapfilename = folder + this.ticket + ".map";
            string[] rasterfiles = Directory.GetFiles(folder, "*.tif",
SearchOption.AllDirectories);
            string[] shapefiles = Directory.GetFiles(folder, "*.shp",
SearchOption.AllDirectories);
            mapObj map = new mapObj(mapfilename);

            //Add raster layers to the map
            foreach (string rasterfile in rasterfiles)
            {
                //Call GDAL utils
                string tiledrasterfile =
rasterfile.Substring(0,rasterfile.LastIndexOf(".")) + "_tiled.tif";
                //Create image tiles for full raster
                Shell(gdalroot + "gdal_translate"," -co TILED=YES " +
rasterfile + " " + tiledrasterfile);
                //Add Overviews for various zoom levels
                Shell(gdalroot + "gdaladdo", tiledrasterfile + " 2 4 8 16 32
64");

                layerObj layer = new layerObj(map);
                layer.connectiontype = MS_CONNECTION_TYPE.MS_RASTER;
                layer.type = MS_LAYER_TYPE.MS_LAYER_RASTER;
                layer.data = rasterfile;
                layer.status = mapscript.MS_ON;
            }

            //Add shape layers to the map (ESRI shapefile)
            foreach (string shapefile in shapefiles)
            {
                layerObj layer = new layerObj(map);
                layer.connectiontype = MS_CONNECTION_TYPE.MS_SHAPEFILE;
                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;
                layer.data = shapefile;
                layer.status = mapscript.MS_ON;
            }
            map.save(mapfilename);
        }

Dan Walton
dgwalton at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20091002/1a038b26/attachment.htm>


More information about the MapServer-users mailing list