Skip to content

NullReferenceException at React.AspNet.HttpContextLifetimeProvider.get_Registrations() during Startup #814

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

Closed
4 tasks done
kurtcodemander opened this issue May 22, 2019 · 2 comments

Comments

@kurtcodemander
Copy link

Please verify these steps before filing an issue, and check them off as you go

  • The relevant native JavascriptEngineSwitcher library packages are installed (such as JavaScriptEngineSwitcher.V8.Native.win-x64)
  • The VC++ 2017 runtime is installed
  • The value of SetUseReact and SetUseBabel is correct in ReactConfig.cs or Startup.cs
  • I've looked at the sample projects in this repo to verify that my app is configured correctly

I'm using these library versions:

  • ReactJS.NET: 4.2.0-beta1
  • JavaScriptEngineSwitcher: 3.1.1
  • react and react-dom: N/A
  • webpack: N/A
  • node: N/A
  • JavaScriptEngineSwitcher.V8.Native.win-x64

Runtime environment:

  • OS: Windows 2016 DataCenter, 64-bit
  • .NET Framework 4.7.2

VS 2019 Build Tools workloads installed in Azure Service Fabric VMs:

  • Microsoft.VisualStudio.Workload.MSBuildTools
  • Microsoft.VisualStudio.Workload.NetCoreBuildTools
  • Microsoft.VisualStudio.Workload.NodeBuildTool
  • Microsoft.VisualStudio.Workload.WebBuildTools --includeRecommended --quiet
  • Microsoft.Net.Component.4.6.2.SDK
  • Microsoft.Net.Component.4.6.2.TargetingPack
  • Microsoft.Net.Component.4.7.1.SDK
  • Microsoft.Net.Component.4.7.1.TargetingPack
  • Microsoft.Net.Component.4.7.2.SDK
  • Microsoft.Net.Component.4.7.2.TargetingPack

I'm trying to run my ASP.NET Core project, running under .NET Framework 4.7.2, to run in Azure Service Fabric. However I'm getting System.NullReferenceException at React.AspNet.HttpContextLifetimeProvider.get_Registrations() , when running app.UseReact(...).

The exception looks similar to #600 [Rendering without HTTPContext]

It works in Azure Service Fabric on my development computer, but I cannot for the life of me figure out what's wrong in Azure or what's missing in the VMs.

Startup.cs, ConfigureServices contains this code before call to services.AddMvc(...):

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddReact();
services.AddJsEngineSwitcher(options => options.DefaultEngineName = ChakraCoreJsEngine.EngineName).AddChakraCore();

Startup.cs, Configure contains this code (no custom configuration) before call to app.UseStaticFiles();:

app.UseReact(config =>{});

I've tried changing

void ConfigureServices(...)

to

IServiceProvider ConfigureServices(...)
...
return return services.BuildServiceProvider();

Any tips on how to hunt this down?

Exception:

System.RA' reported Warning for property 'ReplicaOpenStatus'. Replica had multiple failures during open on _Primary_0. API call: IStatelessServiceInstance.Open(); Error = System.NullReferenceException (-2147467261) Object reference not set to an instance of an object.
at React.AspNet.HttpContextLifetimeProvider.get_Registrations()
at React.AspNet.HttpContextLifetimeProvider.ReleaseObject()
at React.TinyIoC.SafeDictionary2.set_Item(TKey key, TValue value)
at React.TinyIoC.TinyIoCContainer.RegisterRegisterType,RegisterImplementation
at React.AssemblyRegistration.Register(TinyIoCContainer container)
at React.Initializer.InitializeIoC(Func2 requestLifetimeRegistration)
at React.AspNet.ReactBuilderExtensions.UseReact(IApplicationBuilder app, Action`1 configure, BabelFileOptions fileOptions) at AdminWeb.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in C:\CloudIDE\Workspaces\Codemander\Azure Service Fabric\AdminWeb\Startup.cs:line 1082
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.ServiceFabric.Services.Communication.AspNetCore.AspNetCoreCommunicationListener.OpenAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Runtime.StatelessServiceInstanceAdapter.d__13.MoveNext()

@dustinsoftware
Copy link
Member

Hmm.. if service fabric explicitly disallows IHttpContextAccessor from accessing the current context then you may be out of luck here for right now. The library needs some form of temporary storage for DI to work properly.

That said, we may be able to swap out TinyIoCContainer with a lightweight wrapper around .NET Core DI when targeting netcoreapp (which might fix your issue). I have not done enough digging in this area to say for sure whether that will work; if you end up forking the library and taking a stab this, I would love to support this scenario, since HttpContext is only really used to facilitate DI.

@dustinsoftware
Copy link
Member

Going to close this since reworking the DI system is not on the roadmap...

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

No branches or pull requests

2 participants