So this is kind of a crazy problem to me, but I've had no luck Googling it. I have an ASP.NET MVC 2 application (under .NET 4.0) running locally just fine. When I upload it to my production server (under shared hosting) I get
Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<TheActivityTracker.Resident>' does not contain a definition for 'TextBoxFor' and no extension method 'TextBoxFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<TheActivityTracker.Resident>' could be found (are you missing a using directive or an assembly reference?)
for this code:
<%= this.Html.TextBoxFor(person => person.LastName) %>
This is one of the new standard extension methods in MVC 2. So I wrote some diagnostic code:
System.Reflection.Assembly ass = System.Reflection.Assembly.GetAssembly(typeof(InputExtensions));
Response.Write("From GAC: " + ass.GlobalAssemblyCache.ToString() + "<br/>");
Response.Write("ImageRuntimeVersion: " + ass.ImageRuntimeVersion.ToString() + "<br/>");
Response.Write("Version: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(ass.Location).ToString() + "<br/>");
foreach (var method in typeof(InputExtensions).GetM开发者_如何转开发ethods())
{
Response.Write(method.Name + "<br/>");
}
running locally (where it works fine), I get this as output:
From GAC: True ImageRuntimeVersion: v2.0.50727 Version: File: C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\2.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll InternalName: System.Web.Mvc.dll OriginalFilename: System.Web.Mvc.dll FileVersion: 2.0.50217.0 FileDescription: System.Web.Mvc.dll Product: Microsoft® .NET Framework ProductVersion: 2.0.50217.0 Debug: False Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language: Language Neutral CheckBox CheckBox CheckBox CheckBox CheckBox CheckBox CheckBoxFor CheckBoxFor CheckBoxFor Hidden Hidden Hidden Hidden HiddenFor HiddenFor HiddenFor Password Password Password Password PasswordFor PasswordFor PasswordFor RadioButton RadioButton RadioButton RadioButton RadioButton RadioButton RadioButtonFor RadioButtonFor RadioButtonFor TextBox TextBox TextBox TextBox TextBoxFor TextBoxFor TextBoxFor ToString Equals GetHashCode GetType
and when running on the production server (where it fails), I see:
From GAC: True ImageRuntimeVersion: v2.0.50727 Version: File: C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\2.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll InternalName: System.Web.Mvc.dll OriginalFilename: System.Web.Mvc.dll FileVersion: 2.0.50217.0 FileDescription: System.Web.Mvc.dll Product: Microsoft® .NET Framework ProductVersion: 2.0.50217.0 Debug: False Patched: False PreRelease: False PrivateBuild: False SpecialBuild: False Language: Language Neutral CheckBox CheckBox CheckBox CheckBox CheckBox CheckBox Hidden Hidden Hidden Hidden Hidden Hidden Password Password Password Password RadioButton RadioButton RadioButton RadioButton RadioButton RadioButton TextBox TextBox TextBox TextBox ToString Equals GetHashCode GetType
note that "TextBoxFor" is not present (hence the error).
I have MVC referenced in the csproj:
<Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>True</SpecificVersion>
<HintPath>References\System.Web.Mvc.dll</HintPath>
<Private>True</Private>
</Reference>
Upon user Levi's suggestion, I uploaded and ran the MvcFutures' diagnostics page - here's the innocent looking output:
Microsoft ASP.NET MVC Diagnostics Information This page is designed to help diagnose common errors related to mismatched or conflicting ASP.NET MVC binaries. If a known issue is identified, it will be displayed below in red text. For questions or problems with ASP.NET MVC or this utility, please visit the ASP.NET MVC forums at http://forums.asp.net/1146.aspx. Environment Information Operating system: Microsoft Windows NT 6.0.6002 Service Pack 2 .NET Framework version: 4.0.30319.1 (32-bit) Web server: Microsoft-IIS/7.0 Integrated pipeline: True Worker process: w3wp.exe ASP.NET MVC Assembly Information (System.Web.Mvc.dll) Assembly version: ASP.NET MVC 2 RTM (2.0.50217.0) Full name: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Code base: file:///C:/Windows/assembly/GAC_MSIL/System.Web.Mvc/2.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll Deployment: GAC-deployed ASP.NET MVC Futures Assembly Information (Microsoft.Web.Mvc.dll) An ASP.NET MVC Futures assembly has not been loaded into this application. If desired, you can download ASP.NET MVC 2 RTM Futures from http://go.microsoft.com/fwlink/?LinkID=183739. All Loaded Assemblies 50 assemblies are loaded. * A_d509bf65_3d32_48f0_8ab6_566e289003a6, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * App_global.asax.5qqlf9ir, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * App_Web_2vnklzay, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * App_Web_n3cjbc0f, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * App_Web_v3sxbd4u, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null * DotNetPanel.IIsModules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=37f9c58a0aa32ff0 * Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * Microsoft.JScript, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * SMDiagnostics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Data.Services.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.Runtime.DurableInstancing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Web.RegularExpressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a * System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 * System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 * TheActivityTracker, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Diagnostics version: 02/16/2010 00:00:00 v7 Report generated on: 05/05/2010 18:12:56
I just can't figure it what to do next. Thoughts?
Thanks!
-Mike
Your hoster is running a prerelease version of MVC 2. (Even worse, they seem to have GACed it!) They might also be running a prerelease version of the .NET 4 Framework.
Call them and tell them to upgrade to the RTM builds. :)
Try removing the hint path and specific version
<Reference
Include="System.Web.Mvc, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35,
processorArchitecture=MSIL" />
精彩评论