DbGeography does not work when published to a server

The following code works in my local machine while debugging but throws an error when published to a server.

public IEnumerable<Restaurant> Nearby(double latitude, double longitude, double distance)
{
    var region = DbGeography.PointFromText(string.Format("POINT({1} {0})", latitude, longitude), 4326).Buffer(10000);
    return Find(x => SqlSpatialFunctions.Filter(x.Location, region) ?? false);
}

After searching like a madman, I installed Microsoft.SqlServer.Types from nuget. (version 14.0.1016.290)

Added the required dlls in the ~/bin folder (provided by the above package).

Added the following code in Global.asax.cs

SqlServerTypes.Utilities.LoadNativeAssemblies(Server.MapPath("~/bin"));

But still the code throws a “500 Internal Server Error. An error has occured”.

Note: This works perfectly in my local machine.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Whew, finally this answer worked.

Note: I had to include Microsoft.SqlServer.Types.dll from

~/packages/Microsoft.SqlServer.Types.14.0.1016.290libnet40 in the ~/bin folder as well


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x