InvalidOperationException in Lazy<T>: ValueFactory attempted to access the Value property of this instance.
See original GitHub issueIn some circumstances when LifetimeScope.Build()
is called, one of VContainer’s private Lazy<object>
s will throw an InvalidOperationException
upon accessing its Value
property as promised in its documentation. Here’s my stack trace:
[19:38:18:120] InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
System.Lazy`1[T].CreateValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].LazyInitValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].get_Value () (at <695d1cc93cca45069c528c15c9fdd749>:0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:110)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:77)
VContainer.ScopedContainer.Resolve (System.Type type) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:57)
VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/IObjectResolverExtensions.cs:32)
VContainer.Internal.ReflectionInjector.CreateInstance (VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/ReflectionInjector.cs:39)
VContainer.Internal.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/Registration.cs:38)
VContainer.ScopedContainer+<>c__DisplayClass10_0.<.ctor>b__1 () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:50)
System.Lazy`1[T].CreateValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].LazyInitValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].get_Value () (at <695d1cc93cca45069c528c15c9fdd749>:0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:110)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:77)
VContainer.ScopedContainer.Resolve (System.Type type) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:57)
VContainer.IObjectResolverExtensions.Resolve[T] (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/IObjectResolverExtensions.cs:8)
CorundumGames.Chromavaders.Tests.Attributes.SimulatedInputAttribute.SimulatedInputServiceFactory (VContainer.IObjectResolver container) (at Assets/Scripts/Tests/Common/SimulatedInput/SimulatedInputAttribute.cs:87)
VContainer.Internal.FuncRegistration.SpawnInstance (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/FuncRegistration.cs:34)
VContainer.ScopedContainer+<>c__DisplayClass10_0.<.ctor>b__1 () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:50)
System.Lazy`1[T].CreateValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].LazyInitValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].get_Value () (at <695d1cc93cca45069c528c15c9fdd749>:0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:110)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:77)
VContainer.ScopedContainer.Resolve (System.Type type) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:57)
VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/IObjectResolverExtensions.cs:32)
VContainer.Internal.ReflectionInjector.CreateInstance (VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/ReflectionInjector.cs:39)
VContainer.Internal.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/Registration.cs:38)
VContainer.ScopedContainer+<>c__DisplayClass10_0.<.ctor>b__1 () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:50)
System.Lazy`1[T].CreateValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].LazyInitValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].get_Value () (at <695d1cc93cca45069c528c15c9fdd749>:0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:110)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:74)
VContainer.ScopedContainer.Resolve (System.Type type) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:57)
VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/IObjectResolverExtensions.cs:32)
VContainer.Internal.ReflectionInjector.CreateInstance (VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/ReflectionInjector.cs:39)
VContainer.Internal.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/Registration.cs:38)
VContainer.ScopedContainer+<>c__DisplayClass10_0.<.ctor>b__1 () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:50)
System.Lazy`1[T].CreateValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].LazyInitValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].get_Value () (at <695d1cc93cca45069c528c15c9fdd749>:0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:110)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:74)
VContainer.ScopedContainer.Resolve (System.Type type) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:57)
VContainer.IObjectResolverExtensions.ResolveOrParameter (VContainer.IObjectResolver resolver, System.Type parameterType, System.String parameterName, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/IObjectResolverExtensions.cs:32)
VContainer.Internal.ReflectionInjector.CreateInstance (VContainer.IObjectResolver resolver, System.Collections.Generic.IReadOnlyList`1[T] parameters) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/ReflectionInjector.cs:39)
VContainer.Internal.Registration.SpawnInstance (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/Registration.cs:38)
VContainer.ScopedContainer+<>c__DisplayClass10_0.<.ctor>b__1 () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:50)
System.Lazy`1[T].CreateValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].LazyInitValue () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Lazy`1[T].get_Value () (at <695d1cc93cca45069c528c15c9fdd749>:0)
VContainer.ScopedContainer.CreateTrackedInstance (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:110)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:77)
VContainer.Internal.CollectionRegistration.SpawnInstance (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Internal/Registration.cs:97)
VContainer.ScopedContainer.Resolve (VContainer.IRegistration registration) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:65)
VContainer.ScopedContainer.Resolve (System.Type type) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:57)
VContainer.IObjectResolverExtensions.Resolve[T] (VContainer.IObjectResolver resolver) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/IObjectResolverExtensions.cs:8)
VContainer.Unity.EntryPointDispatcher.Dispatch () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Unity/EntryPointDispatcher.cs:34)
VContainer.Unity.EntryPointsBuilder+<>c.<EnsureDispatcherRegistered>b__0_0 (VContainer.IObjectResolver container) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Unity/ContainerBuilderUnityExtensions.cs:20)
VContainer.ContainerBuilder.EmitCallbacks (VContainer.IObjectResolver container) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/ContainerBuilder.cs:124)
VContainer.ScopedContainerBuilder.BuildScope () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/ContainerBuilder.cs:34)
VContainer.ScopedContainer.CreateScope (System.Action`1[T] installation) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:88)
VContainer.Container.CreateScope (System.Action`1[T] installation) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Container.cs:183)
VContainer.Unity.LifetimeScope.Build () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Unity/LifetimeScope.cs:163)
VContainer.Unity.LifetimeScope.Awake () (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Unity/LifetimeScope.cs:130)
UnityEngine.GameObject:SetActive(Boolean)
VContainer.Unity.LifetimeScope:CreateChild(IInstaller) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Unity/LifetimeScope.cs:193)
VContainer.Unity.LifetimeScope:CreateChild(Action`1) (at Library/PackageCache/jp.hadashikick.vcontainer@1.8.4/Runtime/Unity/LifetimeScope.cs:198)
CorundumGames.Chromavaders.Tests.Common.<<SetUpTestScope>b__7_0>d:MoveNext() (at Assets/Scripts/Tests/Common/ScopedTestFixture.cs:94)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1:Run() (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/CompilerServices/StateMachineRunner.cs:189)
Cysharp.Threading.Tasks.AwaiterActions:Continuation(Object) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/UniTask.cs:21)
Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1:TrySetResult(ITestScene) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/UniTaskCompletionSource.cs:139)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`2:SetResult(ITestScene) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/CompilerServices/StateMachineRunner.cs:328)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskMethodBuilder`1:SetResult(ITestScene) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs:201)
CorundumGames.Chromavaders.Tests.Attributes.<LoadSceneAsyncPrivate>d__5:MoveNext() (at Assets/Scripts/Tests/Common/Attributes/Scene/SceneAddressAttribute.cs:48)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`2:Run() (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/CompilerServices/StateMachineRunner.cs:313)
Cysharp.Threading.Tasks.AwaiterActions:Continuation(Object) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/UniTask.cs:21)
Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1:TrySetResult(SceneInstance) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/UniTaskCompletionSource.cs:139)
Cysharp.Threading.Tasks.AsyncOperationHandleConfiguredSource`1:Continuation(AsyncOperationHandle`1) (at Library/PackageCache/com.cysharp.unitask@2.2.5/Runtime/External/Addressables/AddressablesAsyncExtensions.cs:333)
DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.18.9/Runtime/ResourceManager/Util/DelegateList.cs:69)
UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:UpdateCallback(Single)
DelegateList`1:Invoke(Single) (at Library/PackageCache/com.unity.addressables@1.18.9/Runtime/ResourceManager/Util/DelegateList.cs:69)
UnityEngine.ResourceManagement.ResourceManager:Update(Single)
MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.18.9/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:26)
This occurs reliably, but I don’t know the conditions under which it does so (or else I’d provide a minimal code sample). What information can I give you about my dependency registrations or their implementations that would be useful?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
c# - InvalidOperationException in my Lazy<> value factory
ValueFactory attempted to access the Value property of this instance. I don't see anything in my "value factory" method that accesses the Value ......
Read more >ValueFactory attempted to access the Value property of this ...
I get System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance. when I try to add ASP.NET API ...
Read more >ValueFactory attempted to access the Value property of this ...
I want to show dyanmic created values in PermissionManagement screen which are created on the go.
Read more >ValueFactory attempted to access the Value property of this ...
System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance. at System.Lazy`1.CreateValue()
Read more >Blazor TypeClient `AddHttpMessageHandler` emits ...
InvalidOperationException : ValueFactory attempted to access the Value property of this instance. at System.Lazy`1[[Microsoft.Extensions.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had this exception too. The cause was also circular reference, and I already solved it. Here is an example code to reproduce it.
And here’s the stack trace.
Fixed #311