11

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"
Evgenyt
  • 10,201
  • 12
  • 40
  • 44
  • Have you tried `Inherits="System.Web.Mvc.ViewUserControl`1[[MyProj.Web.Models.RangeViewModel]]"`? – João Angelo May 10 '10 at 14:41
  • Why aren't you just building inside Visual Studio (or Express, if you are using it)? You could try that out too and the pinpoint it down to msbuild configuration if it works from VS build. – mare May 10 '10 at 14:43

4 Answers4

16

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>
PanJanek
  • 6,593
  • 2
  • 34
  • 41
  • Oh yes - for MVC2 it should be "Versions=2.0.0.0". Teoretically - if the MVC project is properly build and published this tweaking of "pages" section is not neccesary. In practice, when migrating between different versions and builds of MVC it's the easiest way to repair the project – PanJanek May 10 '10 at 14:55
  • 1
    Similarly - you might see this error if you deployed a new "area" and forgot to copy the area's `web.config`. Just happened to me. – bendytree Feb 11 '14 at 14:39
5

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

Evgenyt
  • 10,201
  • 12
  • 40
  • 44
  • There's something wrong with your project or its build because that is not required in web.config for ASP.NET MVC application to work either locally or on the server. – mare May 10 '10 at 14:52
  • @mare you are right in one resepect, it should not be required, but in one instance we could not get an app executing without adding the pages tag as described. WOuld love to know the real issue, mayby machine.config is doing something? – Jafin Apr 06 '11 at 04:25
1

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>
0

Could be messed up ASP.NET MVC installation on the server. I suggest uninstalling MVC and reinstalling with Web Platform Installer. I had problems too when I installed using the downloaded setups files, so I removed everything and went with the Web Platform Installer.

Another suggestion would be to make a new fresh server box - can be virtual - and try there.

Also rebuilding solution could help and checking out that web.config is ok too.

Also try if MvcDiagnostics.aspx tool shows any abnormalities. Check out this blog post

Let us know if anything helps.

mare
  • 13,033
  • 24
  • 102
  • 191