This project has moved. For the latest updates, please go here.

Exception when changing DashStyle

Topics: General Topics
Sep 25, 2006 at 7:27 PM
Exception occurs when thi sstatement is executed:

layFairway.Style.Outline.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

SharpMap.Map map = new SharpMap.Map(size);
//Set up the Fairways layer
SharpMap.Layers.VectorLayer layFairway = new SharpMap.Layers.VectorLayer("FAIRWY_poly");
SharpMap.Data.Providers.ShapeFile shpFairway = new SharpMap.Data.Providers.ShapeFile(@"C:\FAIRWY_poly.shp", true);
layFairway.DataSource = shpFairway;
layFairway.CoordinateTransformation = Transform2Mercator(shpFairway.CoordinateSystem);
layFairway.Style.Fill = new SolidBrush(Color.Yellow);
layFairway.Style.Outline = System.Drawing.Pens.Black;
layFairway.Style.EnableOutline = true;
layFairway.Style.Outline.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; // Exception occurs here, not sure what could cause this error
layFairway.MaxVisible = 40000;
layFairway.MinVisible = 0;

System.ArgumentException was unhandled by user code
Message="Changes cannot be made to Pen because permissions are not valid."
at System.Drawing.Pen.set_DashStyle(DashStyle value)
at NavAidMap.CreateMap(Size size) in c:\Documents and Settings\kbradley\Desktop\VirtualEarth\App_Code\Map.cs:line 54
at mapservice.ProcessRequest(HttpContext context) in c:\Documents and Settings\kbradley\Desktop\VirtualEarth\VEmap.ashx:line 35
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Sep 25, 2006 at 9:57 PM

Your problem is the manipulation of a system defined "Pen".
In this case is it "Black"
This shouldn't be done.

You could build your own Pen like this:

Pen dashedPen = Pens.Back.Clone() as Pen;
dashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
layFairway.Style.Outline = dashedPen;
layFairway.Style.EnableOutline = true;