title: Mocking MongoCollection crashes - Exception has been thrown by the target of an invocation
body: <p>I use Moq to mock the <code>GetCollection</code> method but the line crashes.</p>
  
  <pre><code>var collectionSettings = new MongoCollectionSettings
  {
      GuidRepresentation = GuidRepresentation.Standard,
      ReadEncoding = new UTF8Encoding(),
      ReadPreference = new ReadPreference(),
      WriteConcern = new WriteConcern(),
      WriteEncoding = new UTF8Encoding()
  };
  
  var collection = new Mock&lt;MongoCollection&lt;BsonDocument&gt;&gt;(database.Object, "MyCollection", collectionSettings);
  
  //crashing here without any error dumped
  database.Setup(f =&gt; f.GetCollection("MyCollection", collectionSettings)).Returns(collection.Object);
  </code></pre>
  
  <p>This is the error I got</p>
  
  <pre><code>Exception of type 'System.ArgumentOutOfRangeException' was thrown.
  Parameter name: name
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
     at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark&amp; stackMark)
     at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
     at System.Activator.CreateInstance(Type type, Object[] args)
     at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(Type proxyType, List`1 proxyArguments, Type classToProxy, Object[] constructorArguments)
     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.&lt;InitializeInstance&gt;b__0()
     at Moq.PexProtector.Invoke(Action action)
     at Moq.Mock`1.InitializeInstance()
     at Moq.Mock`1.OnGetObject()
     at Moq.Mock.GetObject()
     at Moq.Mock.get_Object()
     at Moq.Mock`1.get_Object()
  </code></pre>
  
  <p>Any idea about hot to fix it?</p>