1

These are my entities:

  Namespace Models.Entity

Public MustInherit Class Client
    <Key()> _
    Public Property ClientID As Integer
    <Required()> _
    Public Property UserName As String
    <Required()> _
    Public Property Password As String

    Public Property OmniSoftKey As String
    <Required()> _
    Public Property isValidated As Boolean
    <Required()> _
    Public Property AddressLine1 As String
    Public Property AddressLine2 As String
    <Required()> _
    Public Property City As String
    <Required()> _
    Public Property TypeOfClient As String
    <Required()> _
    Public Property PostCode As String
    ' <Required()> _
    Public Property ContactPersoon As String
    ' <Required()> _
    Public Property Phone As String
    <Required()> _
    Public Property Email As String
    '<Required()> _
    Public Property BTWNr As String
    Public Property KortingPercentage As Double
    Public Property ConfirmKey As String
    Public Property PrijsCode As Integer

    Public Overridable Property Orders As ICollection(Of Order)


End Class

Public Class SchoolClient
    Inherits Client
    Public Property DefaultClassRoom As String
    Public Property SchoolName As String
End Class
Public Class BusinessClient
    Inherits Client

    Public Property CompanyName As String
End Class

As my view isn't run, i won't show this.

My controller action doesn't run and this is the error i get:

System.MissingMethodException: Cannot create an abstract class.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
at System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor)
at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

It's very similar to this question .

The problem is, it has worked before. I don't know why it won't work now? What could be the problem?

Edit:

Controller (this event isn't fired though)

     Public Function Handle(Optional _Client As Client = Nothing, Optional ByVal OnCheckout As Boolean = False) As ActionResult
        '      Dim x As List(Of Client) = db.Clients.ToList
        ViewBag.CurrentPathDescription = "Inlog / Registreer pagina"
        ViewBag.OnCheckOut = OnCheckout
        Return View("Handle", _Client)
    End Function
Community
  • 1
  • 1
NicoJuicy
  • 3,435
  • 4
  • 40
  • 66
  • 1
    Did you try the answer in the linked question? What is your problem with it? – Daniel Hilgarth Jan 06 '12 at 11:31
  • Can you post code of your controller? Are you trying to create an instance of Client somewhere directly? – oleksii Jan 06 '12 at 11:36
  • Because i didn't had it before, and it worked then :s – NicoJuicy Jan 06 '12 at 12:30
  • 1
    @NicoJuicy, no, it couldn't have worked before. Abstract classes cannot be used as action arguments unless you have some custom logic such as a custom model binder to instantiate a concrete implementation. – Darin Dimitrov Jan 06 '12 at 12:33
  • I'm just saying what it did. It just worked... But something has messed it up. This is on the register / login page (where it gives an error). But for some reason it doesn't function now (btw. created 4 users with that page ... I'm not blind). The problem should be somewhere else, although it could be related to this one. I just can't find out what i'm "overlooking" – NicoJuicy Jan 06 '12 at 12:37
  • Or Perhaps it just worked in Entity framework 4.1 and not anymore in EF 4.2... ? – NicoJuicy Jan 06 '12 at 12:38
  • Even more, this was my example i based my code on and it just worked... http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx – NicoJuicy Jan 06 '12 at 12:40
  • The problem is not in EF so your linked example is not relevant. The problem is in Handle action expecting instance of abstract class. It could never work. Follow the solution from linked question. – Ladislav Mrnka Jan 06 '12 at 12:50
  • 2
    possible duplicate of [Can abstract class be a parameter in a controller's action?](http://stackoverflow.com/questions/5861241/can-abstract-class-be-a-parameter-in-a-controllers-action) – Ladislav Mrnka Jan 06 '12 at 12:51
  • I'd better read titles instead of cross referencing solutions - Thx a lot – NicoJuicy Jan 06 '12 at 13:14

0 Answers0