Hey guys,<br><br><div class="gmail_quote">I&#39;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:<br>

<br><i><b>The type initializer for &#39;OSGeo.MapServer.mapscriptPINVOKE&#39; threw an exception.</b></i><br>
<br>Anyone else out there seen this?<br><br><br>I have referenced mapscript_csharp.dll compiled by the MS4W folks, and here is the properties pane in VS2008:<br><br><b>Aliases: global<br>Copy Local: true<br>File Type: Assembly<br>

Identity: mapscript_csharp<br>Path: C:\Domains\Website1\ImageService\ImageService1\bin\mapscript_csharp.dll<br>Resolved: true<br>Runtime Version: v2.0.50727<br>Specific Version: true<br>Strong Name: true<br>Version: 1.0.3491.26938</b><br>

<br><br>
Here is the basic structure of my code:<br><br><span style="font-family: courier new,monospace;"> private void CreateMap(string folder)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            //Add a new map (based on a unique ticket string)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            string mapfilename = folder + this.ticket + &quot;.map&quot;;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            string[] rasterfiles = Directory.GetFiles(folder, &quot;*.tif&quot;, SearchOption.AllDirectories);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            string[] shapefiles = Directory.GetFiles(folder, &quot;*.shp&quot;, SearchOption.AllDirectories);</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            mapObj map = new mapObj(mapfilename);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //Add raster layers to the map</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            foreach (string rasterfile in rasterfiles)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                //Call GDAL utils</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                string tiledrasterfile = rasterfile.Substring(0,rasterfile.LastIndexOf(&quot;.&quot;)) + &quot;_tiled.tif&quot;;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                //Create image tiles for full raster</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                Shell(gdalroot + &quot;gdal_translate&quot;,&quot; -co TILED=YES &quot; + rasterfile + &quot; &quot; + tiledrasterfile);</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                //Add Overviews for various zoom levels</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                Shell(gdalroot + &quot;gdaladdo&quot;, tiledrasterfile + &quot; 2 4 8 16 32 64&quot;);</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                layerObj layer = new layerObj(map);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                layer.connectiontype = MS_CONNECTION_TYPE.MS_RASTER;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                layer.type = MS_LAYER_TYPE.MS_LAYER_RASTER;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                layer.data = rasterfile;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                layer.status = mapscript.MS_ON;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //Add shape layers to the map (ESRI shapefile)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            foreach (string shapefile in shapefiles)</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                layerObj layer = new layerObj(map);</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                layer.connectiontype = MS_CONNECTION_TYPE.MS_SHAPEFILE;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">                layer.data = shapefile;                </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                layer.status = mapscript.MS_ON;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            map.save(mapfilename);            </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        }</span><br><blockquote style="margin: 1.5em 0pt;"><div style="border: 1px solid black; padding: 5px; font-family: tahoma; font-size: 8pt; font-weight: bold; width: 150px;">



Dan Walton<br>
<a href="mailto:dgwalton@gmail.com" target="_blank">dgwalton@gmail.com</a>
</div></blockquote><br>
</div><br>