简体   繁体   English

Windows 2012上的MVC5部署到IIS(Visual Studio 2013)

[英]MVC5 Deploy to IIS on Windows 2012 (Visual Studio 2013)

I have been working on a MVC5 application in VS2013 using EF6. 我一直在使用EF6在VS2013中开发MVC5应用程序。 I have not had any issues in the development environment but when publishing to the Win 2012 IIS Server and running the application I am faced with a number of page errors. 我在开发环境中没有任何问题,但是当发布到Win 2012 IIS服务器并运行应用程序时,我遇到了许多页面错误。

The error that I am facing seems to be consistent across the pages. 我面临的错误似乎在页面中是一致的。

"The property 'CountFrequency' is not a String or Byte array. Length can only be configured for String and Byte array properties." “属性'CountFrequency'不是String或Byte数组。只能为String和Byte数组属性配置Length。”

Line 35: Line 36: Line 37: @foreach (var item in Model) Line 38: { Line 39: 第35行:第36行:第37行:@foreach(模型中的var项)第38行:{第39行:

Here is the stack trace: 这是堆栈跟踪:

* *

[InvalidOperationException: The property 'CountFrequency' is not a String or Byte array. Length can only be configured for String and Byte array properties.]
   System.Data.Entity.ModelConfiguration.Configuration.ConventionPrimitivePropertyConfiguration.HasMaxLength(Int32 maxLength) +612
   System.Data.Entity.ModelConfiguration.Conventions.PrimitivePropertyAttributeConfigurationConvention`1.<.ctor>b__1(ConventionPrimitivePropertyConfiguration configuration, IEnumerable`1 attributes) +114
   System.Data.Entity.ModelConfiguration.Configuration.PropertyConfigurationConventionDispatcher.Dispatch() +38
   System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyPropertyConfiguration(PropertyInfo propertyInfo, Func`1 propertyConfiguration, ModelConfiguration modelConfiguration) +176
   System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyPropertyConfiguration(PropertyInfo propertyInfo, Func`1 propertyConfiguration, ModelConfiguration modelConfiguration) +218
   System.Data.Entity.ModelConfiguration.Mappers.PropertyMapper.MapPrimitiveOrComplexOrEnumProperty(PropertyInfo propertyInfo, Func`1 structuralTypeConfiguration, Boolean discoverComplexTypes) +650
   System.Data.Entity.ModelConfiguration.Mappers.<>c__DisplayClass14.<MapEntityType>b__e(PropertyMapper m, PropertyInfo p) +46
   System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapStructuralElements(Type type, ICollection`1 annotations, Action`2 propertyMappingAction, Boolean mapDeclaredPropertiesOnly, Func`1 structuralTypeConfiguration) +516
   System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType(Type type) +876
   System.Data.Entity.<>c__DisplayClassd.<MapTypes>b__7(Type type) +16
   System.Linq.WhereListIterator`1.MoveNext() +165
   System.Data.Entity.Utilities.IEnumerableExtensions.Each(IEnumerable`1 ts, Action`1 action) +168
   System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model) +428
   System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +281
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +288
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +94
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +248
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +618
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +26
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +72
   System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +21
   ASP._Page_Views_Logic_List_cshtml.Execute() in c:\inetpub\Internal\KSCycleCounts\Views\Logic\List.cshtml:37
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +110
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

* *

I know my connection strings are valid and are working. 我知道我的连接字符串是有效的并且正在工作。 In Windows 2012 I have installed all the roles (ASP.NET 4.5 and .NET 4.5). 在Windows 2012中,我安装了所有角色(ASP.NET 4.5和.NET 4.5)。 In IIS I have configured my application pool to be using .NET 4 and am using an admin account as the identity for testing. 在IIS中,我已将我的应用程序池配置为使用.NET 4,并使用管理员帐户作为测试标识。

Thanks! 谢谢!

Though the question is almost a year old at the time of my answer, I recently encountered the same exception when trying to loop through an Entity Framework DbSet. 虽然这个问题在我回答的时候已经快一年了,但是我最近在尝试循环实体框架DbSet时遇到了同样的异常。

I initially had a string as a field: 我最初有一个字符串作为字段:

public class Table
{
  [StringLength(20)]
  public string Ref {get;set;}
}

Which I later changed to an int: 我后来改为int:

public class Table
{
  [StringLength(20)]  // <-- hint: int doesn't need a string-length limitation
  public int Ref {get;set;}
}

Notice that I kept the StringLength attribute... but it naturally has no bearing on an int, and ended up throwing the exception. 请注意,我保留了StringLength属性......但它自然与int无关,最终抛出了异常。 Silly me. 傻我。 Hope it saves someone else from the hours I lost and shall never regain :) 希望它从我失去的时间中拯救别人,永远不会重获:)

I also had this same problem. 我也有同样的问题。 The table you are accessing is not always the one that is causing the error. 您正在访问的表并不总是导致错误的表。 For me I was accessing a table called bnapp_tr in doing something like 对我来说,我正在做一个名为bnapp_tr的表

List<bnapp_tr> bn = db.bnapp_tr.ToList();

But the error was in a class I created later which had a Field that was wrongly annotated which was 但错误发生在我后来创建的一个类中,其中有一个被错误注释的字段

[StringLength(25)] // <---Here
public decimal? frec_no { get; set; }

StringLength annotated is NOT AVAILABLE for decimal? StringLength注释不可用于decimal? . It does not make sense. 它没有任何意义。 But I accidentally did so when coding. 但是我在编码时不小心这样做了。 So I just deleted the annotation. 所以我刚刚删除了注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM