Skip to content

Occational null ref in CreateProxy #653

@HaoK

Description

@HaoK

We are seeing some rare null refs come from Moq: original issue: aspnet/Identity#1912

 var store = new Mock<IUserStore<TUser>>();
 var mgr = new Mock<UserManager<TUser>>(store.Object, null, null, null, null, null, null, null, null);

There's not too much going on here, but this sometimes fails rarely with:

System.NullReferenceException : Object reference not set to an instance of an object.
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
   at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
   at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments)
   at Moq.Mock`1.<InitializeInstance>b__20_0()
   at Moq.Mock`1.OnGetObject()
   at Moq.Mock`1.get_Object()
   at Microsoft.AspNetCore.Identity.Test.MockHelpers.MockUserManager[TUser]() in /_/test/Shared/MockHelpers.cs:line 22
   at Microsoft.AspNetCore.Identity.Test.SignInManagerTest.SetupUserManager(PocoUser user)
   at Microsoft.AspNetCore.Identity.Test.SignInManagerTest.CanExternalSignIn(Boolean isPersistent, Boolean supportsLockout) in /_/test/Identity.Test/SignInManagerTest.cs:line 523

Any ideas what could be going on?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions