1

I'm getting a System.OutOfMemoryException: Array dimensions exceeded supported range. in Microsoft.Extensions.DependencyInjection.ServiceProvider.CaptureDisposable

Which appears to be where the DI tracks the transient services for disposal.

I've recently used the standard DI pipeline to register services and I only have 2 services (controllers) that implement IDisposable

Any ideas?

Update from comments:

public class IoCServicesConfigurator : IServicesConfigurator 
{ 
    public void Configure(IServiceCollection serviceCollection) 
    { 
        serviceCollection.AddTransient<SiteSearchController>(); 
    }
}

Question

Does the Sitecore ServiceLocator.ServiceProvider.GetService(typeof(...)) reference a IServiceProvider as a per request item?

Sitecore

It looks like the ISitecoreServiceLocatorScope is resolved from the static serviceProvider, ISitecoreServiceLocatorScope is disposable so these references will build over time.

As ServiceLocator.serviceProvider is a static field on a static class I believe the ISitecoreServiceLocatorScopes won't be disposed until the app pool is reset?

Findings

It appears the static application service provider is not releasing Sitecore.DependencyInjection.SitecorePerRequestScopeModule.SitecoreServiceLocatorScope, this is Sitecore version 8.2

  • Paste the code of your controllers – Marek Musielak Apr 2 at 12:36
  • Have you looked at sitecore.stackexchange.com/questions/2859/… _ – Mark Cassidy Apr 2 at 12:51
  • I'm just registering the controllers as Transient, in debug they appear to be being created and disposed correctly. My assumption is in the CaptureDisposable where its tracking the disposables its exceeding the limit ~2,147,483,647. So the service provider be being reused across all requests – Matthew Butler Apr 2 at 12:58
  • public class IoCServicesConfigurator : IServicesConfigurator { public void Configure(IServiceCollection serviceCollection) { serviceCollection.AddTransient<SiteSearchController>(); } – Matthew Butler Apr 2 at 12:59
  • @MatthewButler for future reference, please update your question with code etc... You can't read that in the comments. I have updated your question for you this time. – Richard Seal Apr 2 at 13:20
1

It appears the ISitecoreServiceLocatorScope is registered as a transient on the global ServierProvider

serviceCollection.Add(new ServiceDescriptor(typeof (ISitecoreServiceLocatorScope), new Func(SitecorePerRequestScopeModule.GetScope), ServiceLifetime.Transient));

This appears to have been fixed in Sitecore 9

serviceCollection.Add(new ServiceDescriptor(typeof (ISitecoreServiceLocatorScope), typeof (SitecoreSingletonServiceScope), ServiceLifetime.Singleton));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.