SharpMap0.9+OpenLayers tile Problem

Topics: SharpMap v0.9 / v1.x
Dec 3, 2008 at 4:38 AM
When I used OpenLayers to call map tiles from WMS ,some tiles were not show. So I debug my progress, I found error here:
code:
g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));

the error type is InvalidOperationException .

what can I do?

OpenLayers Code:
var wmsLayer = new OpenLayers.Layer.WMS("PointLayer", "http://localhost:3013/wms/wms.ashx", {
            layers: 'Points',
            format: 'image/png'
        }, {
            maxExtent:new OpenLayers.Bounds(12210356.643400002,4070118.880600002,12836528.779000003,4383204.948400002),
            isBaseLayer: false,
            //transitionEffect:'resize',
            buffer: 1
        });
Map.addLayers([wmsLayer]);






SharpMap Code:
 public void ProcessRequest(HttpContext context)
    {
       
        string url = (context.Request.Url.Query.Length > 0 ?
            context.Request.Url.AbsoluteUri.Replace(context.Request.Url.Query, "") : context.Request.Url.AbsoluteUri);
        SharpMap.Web.Wms.Capabilities.WmsServiceDescription description =
            new SharpMap.Web.Wms.Capabilities.WmsServiceDescription("JQSOFT Corp. Map Server", url);

       
        description.Abstract = "Map Server maintained by JQSOFT Corporation. Contact: www.joy.com. High-quality maps showing roadrunner nests and possible ambush locations.";
        description.Keywords = new string[3];
        description.Keywords[0] = "bird";
        description.Keywords[1] = "roadrunner";
        description.Keywords[2] = "ambush";

       
        description.ContactInformation.PersonPrimary.Person = "Stephen";
        description.ContactInformation.PersonPrimary.Organisation = "JQ Inc";
        description.ContactInformation.Address.AddressType = "NanJing";
        description.ContactInformation.Address.Country = "NanJing";
        description.ContactInformation.VoiceTelephone = "888888";
        description.MaxWidth = 1000; //Set image request size width
        description.MaxHeight = 500; //Set image request size height
        SharpMap.Map myMap = MapHelper.InitializeMap(new System.Drawing.Size(1, 1));  
        SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap, description);
    }

Coordinator
Dec 3, 2008 at 8:46 AM
Hi wungin, my guess is that symbol is null, try setting a breakpoint on that line and see if that is the case.
If it is null, then you need to set the Symbol property of the VectorStyle for that layer to a Bitmap
hth jd
Dec 4, 2008 at 4:14 AM
Thanks for your help,Johndiss.
The symbol was not null, it said something was uesed  in other place.
I guess that the Graphics was call too many times to deal with it.
but I can't find the way to solute.
Coordinator
Dec 4, 2008 at 9:10 AM
Edited Dec 4, 2008 at 9:12 AM
Ah yes the infamous and cryptic 'Object in use elsewhere'. This exception is a real pain - it stems from the fact that GDI+ is not intended to be used in servers/services as it interacts with the os. Microsofts' Source Servers comments around the offending call show:

///

 

<devdoc>

 

 

 

/// GDI+ will return a 'generic error' with specific win32 last error codes when

 

 

 

/// a terminal server session has been closed, minimized, etc... We don't want

 

 

 

/// to throw when this happens, so we'll guard against this by looking at the

 

 

 

/// 'last win32 error code' and checking to see if it is either 1) access denied

 

 

 

/// or 2) proc not found and then ignore it.

 

 

 

///

 

 

 

/// The problem is that when you lock the machine, the secure desktop is enabled and

 

 

 

/// rendering fails which is expected (since the app doesn't have permission to draw

 

 

 

/// on the secure desktop). Not sure if there's anything you can do, short of catching

 

 

 

/// the desktop switch message and absorbing all the exceptions that get thrown while

 

 

 

/// it's the secure desktop.

 

 

 

/// </devdoc>

 

 

 
There doesn't seem to be any solution to this and my experience shows that it gets worse the more cores and processors you throw into the mix. For v2 we are looking into swapping the GDI rendering engine for something different - perhaps AGG.
You *may* be able to ease the pain by experimenting with the user account that the Asp.Net app pool runs in and granting elevated privileges - 'Interact with Desktop' and probably run as an admin - this is a *massive risk* and you will not be able to do it in a hosted environment. I haven't spent much time doing this and didnt show any signs of improvement..
Other things that may help:
Create a new style for each request - do not cache styles in a static variable
If the data doesn't change use a tile cache that way there will hopefully be less contention for what ever the object that is in use elsewhere is - though I am not sure that the error message bears any relation to the error itself
hth jd
Dec 6, 2008 at 3:24 PM
Thanks for your help,It maybe work.