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

When service is not registered, unhelpful NullReferenceException is thrown instead of InvalidOperationException #28

Closed
JarkoDubbeldam opened this issue Jul 11, 2022 · 0 comments · Fixed by #29

Comments

@JarkoDubbeldam
Copy link
Contributor

Describe the Bug

When using AutofacWebServiceHostFactory to create a service, when that service is not registered in the container, results in an unhelpful NRE, instead of throwing the intended InvalidOperationException (

throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, AutofacHostFactoryResources.ServiceNotRegistered, value));
).

Steps to Reproduce

See this minimal working example project: https://github.com/JarkoDubbeldam/Autofac.Integraction.Wcf.BugRepro/blob/master/BugRepro/ServiceHostFactory.cs

Expected Behavior

I'd expect a more helpful error :)

Exception with Stack Trace

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Autofac.Integration.Wcf
  StackTrace:
   at Autofac.Integration.Wcf.DefaultServiceImplementationDataProvider.GetServiceImplementationData(String value)
   at Autofac.Integration.Wcf.AutofacHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at BugRepro.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) in C:\Users\jdubbeldam\source\repos\BugRepro\BugRepro\ServiceHostFactory.cs:line 17

Dependency Versions

<packages>
  <package id="Autofac" version="6.0.0" targetFramework="net472" />
  <package id="Autofac.Wcf" version="6.0.0" targetFramework="net472" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net472" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net472" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.7.1" targetFramework="net472" />
  <package id="System.Memory" version="4.5.4" targetFramework="net472" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net472" />
</packages>

Additional Info

It appears to me that this statement can never be true, due to serviceRegistration not being nullable.

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