title: Type to mock must be an interface or an abstract or non-sealed class
body: <p>I'm using Moq to mock the following class in VB:</p>
  
  <pre><code>Public class Factory(Of T)
    Inherits Factory
  
    Public Overridable Shadows Readonly Property Model() as TModel
      Get
         ..
      End Get
    End Property
  </code></pre>
  
  <p>When I attempt to use Moq to mock the Model property in a unit test like so:</p>
  
  <pre><code>Dim factory As New Mock(of Factory(Of TestModel))
  factory.Setup(Function(i) i.Model).Returns(new TestModel With { .. })
  </code></pre>
  
  <p>This fails with the error:</p>
  
  <blockquote>
    <p>System.ArgumentException: Type to mock must be an interface or an
    abstract or non-sealed class.  ---> System.TypeLoadException: Access
    is denied:
    'PA.PSP.PFAD.Mvc.PFADFactory`1[PA.PSP.PFAD.Mvc.OrderExtensionsTest+TestModel]'.
    Result StackTrace:     at
    System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule
    module, Int32 tk, ObjectHandleOnStack type)    at
    System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()    at
    System.Reflection.Emit.TypeBuilder.CreateType()    at
    Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder
    type)    at
    Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
    at
    Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String
    name, Type[] interfaces, INamingScope namingScope)</p>
  </blockquote>
  
  <p>Any idea why because while it's not an interface or abstract, it's not sealed (doesn't define NotInheritable in VB)....</p>