获取对象时发生异常:无法从程序集中加载类型

时间:2018-12-03 21:21:03

标签: c# .net-core moq

我正在使用SystemWrapper来简化IO工作。
这是我的代码

var diMock = new Mock<IDirectoryInfo>(); 
diMock.Setup(i => i.Create()).Throws(new Exception("num"));
try
{
      var obj = diMock.Object;
}catch(Exception ex)
{
   //Could not load type 'System.Runtime.Remoting.ObjRef' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
}

调用堆栈为:

at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
at System.Reflection.RuntimeMethodInfo.GetParameters()
at Castle.DynamicProxy.Generators.MethodSignatureComparer.GetHashCode(MethodInfo obj)
at System.Linq.Set`1.InternalGetHashCode(TElement value)
at System.Linq.Set`1.Add(TElement value)
at System.Linq.Set`1.UnionWith(IEnumerable`1 other)
at System.Linq.Enumerable.DistinctIterator`1.FillSet()
at System.Linq.Enumerable.DistinctIterator`1.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Castle.DynamicProxy.Generators.MethodFinder.GetAllInstanceMethods(Type type, BindingFlags flags)
at Castle.DynamicProxy.Contributors.MembersCollector.CollectMethods(IProxyGenerationHook hook)
at Castle.DynamicProxy.Contributors.MembersCollector.CollectMembersToProxy(IProxyGenerationHook hook)
at Castle.DynamicProxy.Contributors.InterfaceProxyWithoutTargetContributor.CollectElementsToProxyInternal(IProxyGenerationHook hook)+MoveNext()
at Castle.DynamicProxy.Contributors.CompositeTypeContributor.CollectElementsToProxy(IProxyGenerationHook hook, MetaType model)
at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass6_0.<GenerateCode>b__0(String n, INamingScope s)
at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors)
at Moq.Mock`1.InitializeInstancePexProtected() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 258
at Moq.Mock`1.OnGetObject() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 286
at Moq.Mock`1.get_Object() in C:\projects\moq4\src\Moq\Mock.Generic.cs:line 197
at Ticket.Curiosity.Tests.Infrastructure_Tests.FileSystemMaterializationTests.SimpleProjectMaterializationTest() in C:\Users\laferreira\source\repos\ProjectCuriosity\Ticket.Curiosity.Tests\Infrastructure Tests\FileSystemMaterializationTests.cs:line 30

有什么想法吗?

信息:
-使用最小起订量
-.Net Core 2.1

0 个答案:

没有答案