2

I'm trying to create a DbGeometry type polygon. it works fine on my local machine but I am getting an error on the return statement when hosting my website on an Azure Web Role.

Code:

string polygon = “POLYGON ((-30.3637216 30.7124139,-30.3632216 30.7124139,-30.3632216 30.7129139,-30.3637216 30.7129139,-30.3637216 30.7124139))”;

return DbGeometry.FromText(polygon, 4326);

Exception:

Exception has been thrown by the target of an invocation.


at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at System.Data.SqlClient.SqlSpatialServices.GeometryFromText(String geometryText)

   at Library.Modules.FindMyWay.SpatialFunctions.GetDefaultBox(Decimal latitude, Decimal longitude)

   at Library.Stop.ImportStops(String userName, IEnumerable`1 stops, Int32 companyId) Inner Exception:    at Microsoft.SqlServer.Types.GLNativeMethods.IsValid(GeoMarshalData g, Boolean& result)

   at Microsoft.SqlServer.Types.GLNativeMethods.IsValid(GeoData g)

   at Microsoft.SqlServer.Types.SqlGeometry.IsValidExpensive()

   at Microsoft.SqlServer.Types.SqlGeometry.GeometryFromText(OpenGisType type, SqlChars text, Int32 srid)

   at Microsoft.SqlServer.Types.SqlGeometry.Parse(SqlString s)

Do you have any idea why this polygon is Invalid?

Oofpez
  • 514
  • 1
  • 7
  • 18
  • 1
    I don't have an answer but just wanted to comment that we are seeing a similar problem where SqlGeometry would work in all contexts except when running as an azure web role. It worked locally. It worked as an azure website. Just not as a webrole. – chrismay Oct 23 '15 at 03:11

2 Answers2

1

Okay I fixed this in a roundabout way by converting a SqlGeometry to a DbGeometry:

is there something like dbgeometry makevalid in .net 4.5

SqlGeometry geom = SqlGeometry.STPolyFromText(new SqlChars(new SqlString(polygon)), 4326);
                 return DbGeometry.FromBinary(geom.STAsBinary().Buffer);

This code produced exception:

Unable to load DLL 'SqlServerSpatial.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

To fix:

Unable to load DLL 'SqlServerSpatial.dll'

The 64 bit dll resulted in this exception:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

So I had to add the 32bit dll to the project to work with Azure.

Result: Its fine now, but I'm still not sure why DbGeometry not working on Azure, also not sure why the 64bit dll is not working on Azure either.

Community
  • 1
  • 1
Oofpez
  • 514
  • 1
  • 7
  • 18
0

I had the same problem. My fix is to put the following Dll's in the folder C:/windows/System32:

SqlServerSpatial.dll SqlServerSpatial110.dll

Entity framework uses these dll's according to this source: https://alastaira.wordpress.com/2011/08/19/spatial-applications-in-windows-azure-redux-including-denali/

leondepdelaw
  • 51
  • 2
  • 6