# The provider did not return a DbSpatialServices instance

**URL:** <https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132>\
**Category:** .NET\
**Created:** [May 15, 2012, 4:01pm UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132 "2012-05-15T16:01:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![phaedrus](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/phaedrus/32/1038_2.png) [@phaedrus](https://community.miniprofiler.com/u/phaedrus)\
**Post date:** [May 15, 2012, 4:01pm UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/1 "2012-05-15T16:01:40Z")

</div>

I have an MVC 4 project using EF 5 Code First. I pulled **MiniProfiler 2.0.1** and **MiniProfiler.EF 2.0.2** from NuGet, added the following on the Global.asax.cs:

```
protected void Application_Start()
{
    MiniProfilerEF.Initialize(); 
}

```

Immediately upon run, I get this error:

##_The provider did not return a DbSpatialServices instance._##

```
Line 58: if (user != null)
Line 59: {
Line 60:>>> if (user.Places != null)
Line 61: {
Line 62: var place= user.Places.OrderByDescending(x => x.CreationTime).FirstOrDefault();

[ProviderIncompatibleException: The provider did not return a DbSpatialServices instance.]
   System.Data.Common.DbProviderServices.GetDbSpatialDataReader(DbDataReader fromReader, String manifestToken) +62
   System.Data.Common.DbProviderServices.GetSpatialDataReader(DbDataReader fromReader, String manifestToken) +101
   System.Data.Spatial.SpatialHelpers.CreateSpatialDataReader(MetadataWorkspace workspace, DbDataReader reader) +70
   System.Data.Common.Internal.Materialization.Shaper.CreateSpatialDataReader() +12
   System.Data.Common.Utils.Singleton`1.get_Value() +25
   System.Data.Common.Internal.Materialization.Shaper.<GetSpatialPropertyValueWithErrorHandling>b__d(DbDataReader reader, Int32 column) +12
   System.Data.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +149
   System.Data.Common.Internal.Materialization.Shaper.GetSpatialPropertyValueWithErrorHandling(Int32 ordinal, String propertyName, String typeName, PrimitiveTypeKind spatialTypeKind) +269
   lambda_method(Closure , Shaper ) +942
   System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +239
   lambda_method(Closure , Shaper ) +221
   System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +163
   System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +88
   System.Data.Objects.DataClasses.RelatedEnd.Merge(IEnumerable`1 collection, MergeOption mergeOption, Boolean setIsLoaded) +222
   System.Data.Objects.DataClasses.EntityCollection`1.Load(List`1 collection, MergeOption mergeOption) +218
   System.Data.Objects.DataClasses.EntityCollection`1.Load(MergeOption mergeOption) +25
   System.Data.Objects.DataClasses.RelatedEnd.Load() +37
   System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad() +300
   System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty(TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject) +85
   System.Data.Objects.Internal.<>c __DisplayClass7`2.<GetInterceptorDelegate>b__ 1(TProxy proxy, TItem item) +105
   System.Data.Entity.DynamicProxies.User_C006B0EF9498157C70250EEE038C6BEADB719A2D5BDC4AA1FB567FB579AECEB5.get_Places() +55
   Project.Web.Controllers.PlaceController.Ribbon() in c:\Project\Project.Web\Controllers\PlaceController.cs:60
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +204
   System.Web.Mvc.Async.<>c __DisplayClass42.<BeginInvokeSynchronousActionMethod>b__ 41() +30
   System.Web.Mvc.Async.<>c __DisplayClass8`1.<BeginSynchronous>b__ 7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +45
   System.Web.Mvc.Async.<>c __DisplayClass39.<BeginInvokeActionMethodWithFilters>b__ 33() +58
   System.Web.Mvc.Async.<>c __DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__ 49() +225
   System.Web.Mvc.Async.<>c __DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__ 49() +225
   System.Web.Mvc.Async.<>c __DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__ 49() +225
   System.Web.Mvc.Async.<>c __DisplayClass37.<BeginInvokeActionMethodWithFilters>b__ 36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.<>c __DisplayClass2a.<BeginInvokeAction>b__ 20() +24
   System.Web.Mvc.Async.<>c __DisplayClass25.<BeginInvokeAction>b__ 22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +42
   System.Web.Mvc.<>c __DisplayClass1d.<BeginExecuteCore>b__ 18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c __DisplayClass4.<MakeVoidDelegate>b__ 3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +54
   System.Web.Mvc.Async.<>c __DisplayClass4.<MakeVoidDelegate>b__ 3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +9
   System.Web.Mvc.<>c __DisplayClassb.<BeginProcessRequest>b__ 4(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c __DisplayClass4.<MakeVoidDelegate>b__ 3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.<>c __DisplayClasse.<EndProcessRequest>b__ d() +47
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.Mvc.<>c __DisplayClassa.<EndProcessRequest>b__ 9() +22
   System.Web.Mvc.<>c __DisplayClass4.<Wrap>b__ 3() +10
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +64
   System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result) +71
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1121

```

I have a couple of DbGeography types in my Places POCO.

```
public class Places 
{
    public Guid PlacesId { get; set; }
    ...
    public DbGeography Location { get; set; }
    public DbGeography Area { get; set; }
    ...
}
```

---

<div class="post-metadata">

**Author:** ![counsellorben](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/counsellorben/32/487_2.png) [@counsellorben](https://community.miniprofiler.com/u/counsellorben)\
**Post date:** [May 18, 2012, 8:57am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/2 "2012-05-18T08:57:18Z")

</div>

Phaedrus,

How are you wrapping your connection?

Also, can you create a small repo as an example? If so, please respond back with a link to the repo.

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![mic](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/mic/32/1014_2.png) [@mic](https://community.miniprofiler.com/u/mic)\
**Post date:** [May 23, 2012, 4:13am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/3 "2012-05-23T04:13:42Z")

</div>

The same issue for me

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://community.miniprofiler.com/u/kevin)\
**Post date:** [July 25, 2012, 4:34am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/4 "2012-07-25T04:34:40Z")

</div>

MiniProfiler works great apart from on pages that use DbGeography when you get a yellow screen of death instead.

The specified type member ‘GeoLocation’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

public DbGeography GeoLocation { get; set; }

When I comment out MiniProfiler then my code works.

I use StructureMap:

> For\<.Entities\>().HybridHttpOrThreadLocalScoped().Use(()  
> =\> new Entities());

(added . to the first Entities otherwise it didn’t show in this editor)

---

<div class="post-metadata">

**Author:** ![mic](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/mic/32/1014_2.png) [@mic](https://community.miniprofiler.com/u/mic)\
**Post date:** [August 28, 2012, 2:54am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/5 "2012-08-28T02:54:57Z")

</div>

Is there any update on this?

---

<div class="post-metadata">

**Author:** ![Murray\_Grant](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Murray\_Grant](https://community.miniprofiler.com/u/Murray_Grant)\
**Post date:** [December 19, 2012, 11:22am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/6 "2012-12-19T11:22:43Z")

</div>

I’ve created a branch which adds support for spatial in Sql Server, if people are interested. However, it requires targeting .net 4.5.

> **[ligos/MiniProfiler](https://github.com/ligos/MiniProfiler)**
>
> A simple but effective mini-profiler for ASP.NET MVC, ASP.NET and Ruby. - ligos/MiniProfiler

  

> <https://github.com/SamSaffron/MiniProfiler/pull/100>

Tested with very read and write tests for SqlGeography points.

---

<div class="post-metadata">

**Author:** ![s\_meijer](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/s_meijer/32/423_2.png) [@s\_meijer](https://community.miniprofiler.com/u/s_meijer)\
**Post date:** [January 20, 2013, 4:00am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/7 "2013-01-20T04:00:37Z")

</div>

Hi Murray,

Your branch is working great when its just about returning geometries. Unfortunately it still crashes on spatial queries.

Try for example something like:

```
public IQueryable<DbGeometry> GetWithin(DbGeometry geometry, int limit)
{
    return _dbContext.Features.Where(x => x.PolygonShape.Intersects(geometry))
        .Select(x => x.PolygonShape).Take(limit);
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Trevor](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@Trevor](https://community.miniprofiler.com/u/Trevor)\
**Post date:** [May 28, 2013, 3:44am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/8 "2013-05-28T03:44:46Z")

</div>

I’ve got this to work by grabbing the patch from [https://github.com/ligos/MiniProfiler](https://github.com/ligos/MiniProfiler) and adding this simple extra override in a similar manner to the ProfiledDbProviderServices.cs file in the StackExchange.Profiling.EntityFramework project:

```
    protected override void SetDbParameterValue(DbParameter parameter, System.Data.Metadata.Edm.TypeUsage parameterType, object value)
    {
        if (value is DbGeography) {
            value = ((DbGeography) value).ProviderValue;
        }
        base.SetDbParameterValue(parameter, parameterType, value);
    }

```

I haven’t tested it extensively yet, however a spatial query worked for me!

Cheers  
Trev

---

<div class="post-metadata">

**Author:** ![Bill](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@Bill](https://community.miniprofiler.com/u/Bill)\
**Post date:** [September 26, 2013, 3:30am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/9 "2013-09-26T03:30:40Z")

</div>

I performed what Trevor did and it worked for me. My issue was surfacing on dynamic data pages that had any DbGeography fields.

---

<div class="post-metadata">

**Author:** ![softwaremills](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/softwaremills/32/976_2.png) [@softwaremills](https://community.miniprofiler.com/u/softwaremills)\
**Post date:** [January 3, 2014, 7:28pm UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/10 "2014-01-03T19:28:42Z")

</div>

Would love to profile stuff returning DbGeography instances but I don’t have enough knowhow to grab MiniProfiler, apply the patches from Murray and Trevor, and then use the result. Hoping someone integrates this into the main distribution. Pretty please? 😄

---

<div class="post-metadata">

**Author:** ![Yaakov\_Ellis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.miniprofiler.com/yaakov_ellis/32/961_2.png) [@Yaakov\_Ellis](https://community.miniprofiler.com/u/Yaakov_Ellis)\
**Post date:** [April 27, 2014, 7:14am UTC](https://community.miniprofiler.com/t/the-provider-did-not-return-a-dbspatialservices-instance/132/11 "2014-04-27T07:14:00Z")

</div>

This is included in [MiniProfiler.EF6 3.0.10-beta5](https://www.nuget.org/packages/MiniProfiler.EF6/3.0.10-beta5)
