Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException Sitecore 9.3 build #410

Open
kwyc opened this issue Jun 17, 2020 · 5 comments
Open

NullReferenceException Sitecore 9.3 build #410

kwyc opened this issue Jun 17, 2020 · 5 comments

Comments

@kwyc
Copy link

kwyc commented Jun 17, 2020

Hi, we have encountered null exceptions, which I think is related to Sitecore context being lost on Singleton lifecycle, and currently it is only misbehaving on CM, and requires restarting CM.

Might be related to these posts, but I would've thought the issue would've been addressed in latest version.
#340
#374

Version: Glass.Mapper.Sc.93 (5.6.160)

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Glass.Mapper.Sc
at Glass.Mapper.Sc.GetItemByIdOptions.GetItem(Database database) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc:line 51
at Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:line 336
at Glass.Mapper.Sc.SitecoreService.GetItem[T](GetItemOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:line 320

Code,
serviceCollection.AddSingleton<Func<Database, ISitecoreService>>(_ => CreateSitecoreService);
serviceCollection.AddScoped(_ => CreateSitecoreContextService());
serviceCollection.AddScoped(_ => CreateRequestContext());
serviceCollection.AddScoped(_ => CreateGlassHtml());
serviceCollection.AddScoped(_ => CreateMvcContext());
serviceCollection.AddScoped(_ => CreateWebFormsContext());

@mikeedwards83
Copy link
Owner

Are one of the scoped instances disposing the singleton instance?

@mihaela-radu
Copy link

Hi Mike,

We're experienced this very exact issue with Glass Mapper 5.8.170 on Sitecore 9.3.0. Are you aware of any workarounds or estimate of when this will be fixed?

Thank you in advance,
Mihaela.

@mikeedwards83
Copy link
Owner

This is probably a disposal of the SitecoreService before it should have been. You need to check the lifecycle of the object and see if you have anything disposing the service incorrectly. Check your IOC registrations as well..

@webbson
Copy link

webbson commented Nov 15, 2021

Hi. We are experiencing this now as well on a Sitecore 9.3 installation running Glass.Mapper.Sc.93 (5.6.160).
It only happens on CM for us as well and a restart solves it. There is no continuity, it just happens randomly, often over the weekend when no-one has been working in the environment, but has happened mid week once.

@Mitya88
Copy link

Mitya88 commented Nov 25, 2021

@webbson You need check if you have any service registered as Singleton and check if they are depending on ISitecoreService (or any service which uses ISitecoreService, e.g IRequestContext etc) I had exactly the same issue on Sitecore V10.1. (and I had a singleton service, using IRequestContext, which uses ISitecoreService)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants