user2961965
user2961965

Reputation: 31

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

I have been working on a MVC5 application in VS2013 using EF6. 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.

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."

Line 35: Line 36: Line 37: @foreach (var item in Model) Line 38: { Line 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). In IIS I have configured my application pool to be using .NET 4 and am using an admin account as the identity for testing.

Thanks!

Upvotes: 2

Views: 1164

Answers (2)

Momodu Deen Swarray
Momodu Deen Swarray

Reputation: 1

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

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?. It does not make sense. But I accidentally did so when coding. So I just deleted the annotation.

Upvotes: 0

HeyZiko
HeyZiko

Reputation: 1720

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.

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:

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. Silly me. Hope it saves someone else from the hours I lost and shall never regain :)

Upvotes: 3

Related Questions