Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load type 'System.Web.Mvc.ViewUserControl<SOMETYPE>'

I'm trying to deploy ASP.NET MVC 2 project (VS2010) to Win Server 2008 R2

It works perfectly on dev machine. But strange error occurs at Server 2008 R2: When .ascx file has header that uses generic type:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyProj.Web.Models.RangeViewModel>" %>

Server reports Could not load type 'System.Web.Mvc.ViewUserControl<MyProj.Web.Models.RangeViewModel>'.

But when I declare somewhere in .cs file type like

public class AA : System.Web.Mvc.ViewUserControl<MyProj.Web.Models.RangeViewModel>
{
}

and use it instead in <%@ Control header. Then it works as it should.

Am I missing something?

UPDATE

I deploy app in two steps (on server):

  1. Rebuild VS solution from source using command-line MSBuild (for .NET 4)
  2. Launch custom msbuild task (have publih.msbuild file for this) that executes two targets: Targets="ResolveReferences;_CopyWebApplication"
like image 330
Evgenyt Avatar asked May 10 '10 14:05

Evgenyt


3 Answers

I looks that the view engine has problems compiling strongly typed base class in Inherit attribute. I had the same issue and updating the "pages" section of Web.Config to this helped:

 <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <controls>
          <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
        <!-- rest of your pages section -->
</pages>
like image 159
PanJanek Avatar answered Nov 06 '22 04:11

PanJanek


Could not find why but the following helped (web.config):

<pages
         pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
         pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
         userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

Initially found similar for asp.net mvc 1

like image 42
Evgenyt Avatar answered Nov 06 '22 04:11

Evgenyt


I had similar problem. There are several important points

  1. Required space between the brackets and type name.
  2. Need cast model for your model type.

Here's what I got

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl <MyNamespace.MyModel>" %>
<%@ Import Namespace="MyNamespace" %>
<% var model = (MyModel)Model; %>

<h1><% model.MyField %></h1>
like image 45
Sergey Ryzhov Avatar answered Nov 06 '22 05:11

Sergey Ryzhov