'Autofac Dependency Resolution Exception with .Net Core
I am trying to hit an endpoint in the WebAPI which is developed using .Net core. I am getting the below error ->
ERROR: API exception occurred
Autofac.Core.DependencyResolutionException: An exception was thrown while activating ?:TRS.Flint.Security.TRSMembershipProvider
Stacktrace -
TRS.Flint.BLL.Entities.PasswordPolicyHelper. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(TRS.Flint.IoC.Services.IAppSettingsProvider, TRS.Flint.IApplicationLazyCache)' on type 'PasswordPolicyHelper'. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating TRS.Flint.BLL.Entities.Database.LegacyDatabaseContext. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Boolean, TRS.Flint.BLL.Entities.Database.ILegacySessionScopeResolver, TRS.Flint.BLL.Security.IDataAccessProvider)' on type 'LegacyDatabaseContext'. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating TRS.Flint.BLL.Entities.SessionScope. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(System.String, System.Transactions.TransactionScopeOption)' on type 'SessionScope'. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating ?:TRS.Flint.Security.TRSMembershipProvider -> TRS.Flint.BLL.Entities.PasswordPolicyHelper. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(TRS.Flint.IoC.Services.IAppSettingsProvider, TRS.Flint.IApplicationLazyCache)' on type 'PasswordPolicyHelper'. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating TRS.Flint.BLL.Entities.Database.LegacyDatabaseContext. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Boolean, TRS.Flint.BLL.Entities.Database.ILegacySessionScopeResolver, TRS.Flint.BLL.Security.IDataAccessProvider)' on type 'LegacyDatabaseContext'. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating TRS.Flint.BLL.Entities.SessionScope. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(System.String, System.Transactions.TransactionScopeOption)' on type 'SessionScope'. ---> System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at U4.StudentManagement.Api.Platform.Mvc.Core.Security.IdentityPrincipalProvider.ProvidePrincipalFromHttpContext(HttpContext context) in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Security\IdentityPrincipalProvider.cs:line 39
at U4.StudentManagement.Api.Platform.Mvc.Core.Security.HttpContextPrincipalProvider.ProvidePrincipal() in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Security\HttpContextPrincipalProvider.cs:line 46
at TRS.Flint.BLL.Security.PrincipalResolver.ResolvePrincipal() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Security\PrincipalResolver.cs:line 29
at TRS.Flint.BLL.Entities.Manager.get_CurrentPrincipal() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Framework\Manager.cs:line 87
at TRS.Flint.BLL.Entities.Manager.CurrentUserGroupIDs() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Framework\Manager.cs:line 321
at TRS.Flint.BLL.Entities.DB.Extensions.SessionExtensions.EnableRowSecurity(ISession session) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\Extensions\SessionExtensions.cs:line 39
at TRS.Flint.BLL.Entities.DB.Extensions.SessionExtensions.Initialize(ISession session) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\Extensions\SessionExtensions.cs:line 49
at TRS.Flint.BLL.Entities.SessionScope.GetSession() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\SessionScope.cs:line 107
at TRS.Flint.BLL.Entities.DBManager.PushSessionScope(ISessionScope sessionScope) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\DBManager.cs:line 192
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at lambda_method(Closure , String , TransactionScopeOption )
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at lambda_method(Closure , Nullable`1 )
at TRS.Flint.BLL.Entities.Database.LegacyDatabaseContextFactory.GetDatabaseContext() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Database\LegacyDatabaseContextFactory.cs:line 37
at TRS.Flint.BLL.Entities.DB.ContextWrapper.RunGetAction[TResult](Func`2 resultFactory, Boolean enforce) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\ContextWrapper.cs:line 63
at TRS.Flint.BLL.Entities.Base.GeneratedCodeBodies.Get[T](Guid locGid, String entityTypeName, String entityGid, String simpleName, ILog log) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Base\GeneratedCodeBodies.cs:line 176
at TRS.Flint.BLL.Entities.PasswordPolicyHelper.<>c__DisplayClass39_0.<GetPasswordPolicy>b__0() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Security\PasswordPolicyHelper.cs:line 75
at TRS.Flint.PerApplication.LazyGet[T](String key, Func`1 lazy, Nullable`1 expirationTime, Boolean skipProxy, String[] keyDependencies) in E:\TC\work\8927d1b2781d569f\Flint\src\Utilities\Utility\PerApplication.cs:line 723
at TRS.Flint.PerApplication.LazyGet[T](String key, Func`1 lazy, Boolean skipProxy, String[] keyDependencies) in E:\TC\work\8927d1b2781d569f\Flint\src\Utilities\Utility\PerApplication.cs:line 713
at TRS.Flint.PerApplication.LazyGet[T](String key, Func`1 lazy, String[] keyDependencies) in E:\TC\work\8927d1b2781d569f\Flint\src\Utilities\Utility\PerApplication.cs:line 484
at TRS.Flint.BLL.Entities.PasswordPolicyHelper.GetPasswordPolicy() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Security\PasswordPolicyHelper.cs:line 73
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Features.LazyDependencies.LazyRegistrationSource.<>c__DisplayClass5_1`1.<CreateLazyRegistration>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at U4.StudentManagement.Api.Platform.Mvc.Core.Security.IdentityPrincipalProvider.ProvidePrincipalFromHttpContext(HttpContext context) in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Security\IdentityPrincipalProvider.cs:line 39
at U4.StudentManagement.Api.Platform.Mvc.Core.Security.HttpContextPrincipalProvider.ProvidePrincipal() in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Security\HttpContextPrincipalProvider.cs:line 46
at TRS.Flint.BLL.Security.PrincipalResolver.ResolvePrincipal() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Security\PrincipalResolver.cs:line 29
at TRS.Flint.BLL.Entities.Manager.get_CurrentPrincipal() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Framework\Manager.cs:line 87
at TRS.Flint.BLL.Entities.Manager.CurrentUserGroupIDs() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Framework\Manager.cs:line 321
at TRS.Flint.BLL.Entities.DB.Extensions.SessionExtensions.EnableRowSecurity(ISession session) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\Extensions\SessionExtensions.cs:line 39
at TRS.Flint.BLL.Entities.DB.Extensions.SessionExtensions.Initialize(ISession session) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\Extensions\SessionExtensions.cs:line 49
at TRS.Flint.BLL.Entities.SessionScope.GetSession() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\SessionScope.cs:line 107
at TRS.Flint.BLL.Entities.DBManager.PushSessionScope(ISessionScope sessionScope) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\DBManager.cs:line 192
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at lambda_method(Closure , String , TransactionScopeOption )
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at lambda_method(Closure , Nullable`1 )
at TRS.Flint.BLL.Entities.Database.LegacyDatabaseContextFactory.GetDatabaseContext() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Database\LegacyDatabaseContextFactory.cs:line 37
at TRS.Flint.BLL.Entities.DB.ContextWrapper.RunGetAction[TResult](Func`2 resultFactory, Boolean enforce) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\DB\ContextWrapper.cs:line 63
at TRS.Flint.BLL.Entities.Base.GeneratedCodeBodies.Get[T](Guid locGid, String entityTypeName, String entityGid, String simpleName, ILog log) in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Base\GeneratedCodeBodies.cs:line 176
at TRS.Flint.BLL.Entities.PasswordPolicyHelper.<>c__DisplayClass39_0.<GetPasswordPolicy>b__0() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Security\PasswordPolicyHelper.cs:line 75
at TRS.Flint.PerApplication.LazyGet[T](String key, Func`1 lazy, Nullable`1 expirationTime, Boolean skipProxy, String[] keyDependencies) in E:\TC\work\8927d1b2781d569f\Flint\src\Utilities\Utility\PerApplication.cs:line 723
at TRS.Flint.PerApplication.LazyGet[T](String key, Func`1 lazy, Boolean skipProxy, String[] keyDependencies) in E:\TC\work\8927d1b2781d569f\Flint\src\Utilities\Utility\PerApplication.cs:line 713
at TRS.Flint.PerApplication.LazyGet[T](String key, Func`1 lazy, String[] keyDependencies) in E:\TC\work\8927d1b2781d569f\Flint\src\Utilities\Utility\PerApplication.cs:line 484
at TRS.Flint.BLL.Entities.PasswordPolicyHelper.GetPasswordPolicy() in E:\TC\work\8927d1b2781d569f\Flint\src\BLL\Entity\Security\PasswordPolicyHelper.cs:line 73
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--- End of inner exception stack trace ---
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Features.LazyDependencies.LazyRegistrationSource.<>c__DisplayClass5_1`1.<CreateLazyRegistration>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at U4.StudentManagement.Api.Platform.Mvc.Core.Middleware.UserActivityUpdaterMiddleware.InvokeAsync(HttpContext httpContext) in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Middleware\UserActivityUpdaterMiddleware.cs:line 32
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.<Invoke>d__7.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 Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.<Invoke>d__5.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 Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__4.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 U4.StudentManagement.Api.Platform.Mvc.Core.Middleware.SwaggerAuthorizedMiddleware.<InvokeAsync>d__0.MoveNext() in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Middleware\SwaggerAuthorizedMiddleware.cs:line 18
--- 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.Builder.UseMiddlewareExtensions.<>c__DisplayClass5_1.<<UseMiddlewareInterface>b__1>d.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 U4.StudentManagement.Api.Platform.Mvc.Core.Authentication.MultipleSchemesAuthenticationMiddleware.<InvokeAsync>d__2.MoveNext() in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Authentication\MultipleSchemesAuthenticationMiddleware.cs:line 40
--- 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.Builder.UseMiddlewareExtensions.<>c__DisplayClass5_1.<<UseMiddlewareInterface>b__1>d.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.StaticFiles.StaticFileMiddleware.<Invoke>d__7.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 U4.StudentManagement.Api.Platform.Mvc.Core.Middleware.ExceptionHandlingMiddleware.<InvokeAsync>d__3.MoveNext() in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Middleware\ExceptionHandlingMiddleware.cs:line 26
I have already checked that the dependency is resolved properly inside the solution. What else can it be? Also the issue seems to be intermittent and API starts working normally for some time and again starts failing automatically. We have also observed that there is memory spike in the system when we call the API.
Solution 1:[1]
In these cases, it's important to read the whole exception message all the way to the end. It looks like something going on in your code. Truncated:
...Autofac.Core.DependencyResolutionException: An exception was thrown while activating TRS.Flint.BLL.Entities.SessionScope. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(System.String, System.Transactions.TransactionScopeOption)' on type 'SessionScope'. ---> System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at U4.StudentManagement.Api.Platform.Mvc.Core.Security.IdentityPrincipalProvider.ProvidePrincipalFromHttpContext(HttpContext context) in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Security\IdentityPrincipalProvider.cs:line 39
at U4.StudentManagement.Api.Platform.Mvc.Core.Security.HttpContextPrincipalProvider.ProvidePrincipal() in E:\TC\work\8927d1b2781d569f\Api\Platform\Api.Platform.Mvc.Core\Security\HttpContextPrincipalProvider.cs:line 46
So, while trying to create a TRS.Flint.BLL.Entities.SessionScope
, it appears to be calling the HttpContextPrincipalProvider.ProvidePrincipal()
method. In there it calls IdentityPrincipalProvider.ProvidePrincipalFromHttpContext()
, which then looks like it's getting something from a Lazy<T>
. But it looks like something in that Lazy<T>
may be trying to get the value of itself before it's instantiated? Or something? Whatever it is, it's happening in that Lazy<T>
instance, and that's the message:
System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
You need to look at your code to see what's going on there.
I do see it has something to do with HttpContext
; sometimes folks forget that things may be resolved/called when there is no HttpContext
(like at app startup or in a background task) and that causes problems. I don't know if that's the issue here, just suggesting something to look at.
However, otherwise, the exception message and stack trace points you right to the thing in your code to look at. That's where I'd start.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Travis Illig |