I've been working with Linq to SQL for some time now, and I never had a problem ... until now. I have a method that send a query to the database, but different from the other times I did it, I cannot cast the result (be it to List or to Array). The method look as follows:
public List<vwContainer> GetConteinerPorto(int id)
{
return (from cont in db.vwContainers
where cont.idHarbor == id
orderby cont.Year
select cont).ToList();
}
I tried some variations of it, but it always result with a "Specified cast is not valid." exception being thrown. Can you guys give me some light?
Stacktrace:
[InvalidCastException: Specified cast is not valid.]
System.Data.SqlClient.SqlBuffer.get_Int32() +6271252
Read_vwCargas_movimentadas_conteiner(ObjectMaterializer`1 ) +636
System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +42
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +472
System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
WebPortosSEP.Web.Models.PortoRepository.GetConteinerPorto(Int32 id) +867
WebPortosSEP.Web.Controllers.PortoController.Cargas(Int32 id) +255
lambda_method(Closure , ControllerBase , Object[] ) +112
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +258
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +125
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709
System.Web.Mvc.Controller.ExecuteCore() +162
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
This might be because of the mismatch between the types of columns in the database and the .Net types.
When the values of fields like cont.idHarbor and cont.Year are read from the database and converted to .Net types the resulting types may not match those of the properties in your class.
Check if idHarbor is bigInt in database and you are comparing it with an int. Also check the Year field types. You can take a clue from the stacktrace. Is the exception thrown by SqlDataReader.GetInt64 or any such similar method?
It would seem that cont is not actually a vwContainer.
Your method does not contain any cast.
Are your sure the Exception is throw from within the method and not from its call site?
Try this:
public List<vwContainer> GetConteinerPorto(int id)
{
return (from cont in db.vwContainers
where cont.idHarbor == id
orderby cont.Year
select cont).ToList<vwContainer>();
}
It's possible you changed the database schema (e.g. an into to a string) and didn't update the DBML (you would only see this error at runtime when you first access the table that has the error)
If it's a runtime exception and not a compile tome error, then the problem is almost surely that your dbml file is out of sync with your database on some level. I have also seem similar problems when you have more than one dbml file in the same namespace.
Try deleting the table in question out of the dbml file and recreate it.
UPDATE:
Based on your stacktrace, I find it highly suspicious that your exception occurs within a lambda method, but the code you have sown does not include any lambdas. That's not to say there might not be an internal lambda going on, but I don't think so.
Also, note that your stack trace includes this:
Read_vwCargas_movimentadas_conteiner
That's different from the code you posted.
Update 2:
The exception is occuring in an Int32 conversion, which suggests that one of your data columns is not correctly defined. Did you change the type from nullable to non-nullable?
Related
Problem
There's WCF connected to Silverlight. When it's time for the service to return args, it returns an error with the exception and no actual result that it should return.
Exception
Value cannot be null.
Parameter name: headers
There's no parameter named headers. I put emphasis on not having a field named headers in the model which the service returns.
Possible Solution which didn't work out
Checked every Any(), Where and Count() not used when it's null
Checked {get;} doesn't exist except when it's with set;
Traced whole of code and it didn't have any exception or null value
Checked whole of code to be in different try-catches
Checked Web.config and all of connection strings are right; .
I updated the service multiple times and checked its configuration
I couldn't remove defining query I wasn't allowed to
Stack Trace
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at UIE.SrvE.SrvEClient.SrvEClientChannel.EndGetSubmit(IAsyncResult result)
at UIE.SrvE.SrvEClient.UIE.SrvEngineer.ISrvE.EndGetSubmit(IAsyncResult result)
at UIE.SrvE.SrvEClient.OnEndGetSubmit(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
There are so many questions about this exception like this one source but none of them is about headers.
Please, suggest to me any possible solutions.
Disclaimer/warning: I'm fairly new to .net, having just started working with it a year ago.
I have an MVC webapp using Entity Framework 5.0, .Net 4.6, and MVC 4.0, running on Azure. This app accesses two databases, both with EDMX files, and both living on the same Azure server. The connection strings for the databases are in the web.config as dev connections, but the Azure app has environment connection strings that override them.
Both EDMX files were generated by "Updating the Model from Database" (ie, database exists first and edmx is generated to match it). One EDMX file is in a second project in the same solution, and that project is a reference to my app.
This EDMX file / model works fine. The second EDMX file is in the Models section of my app, and only represents three tables and a handful of stored procedures. I haven't touched this EDMX in a year and it's had intermittent problems for the past year where it will occasionally not be able to access the database, but can be fixed by restarting the app.
Recently, I've been making changes to the webapp (but still not changing that EDMX or the views/controllers accessing the model for that database), and now the app is having trouble accessing the database very frequently. When I restart, or change the connection string, it will start working again, but forgets the database after an hour or so.
It feels like the webapp is losing the connection to the database somehow. The connection string is good, the model is accurate, etc (because it works when the app is restarted).
Why is this happening with the one database and not the other? What can I do to fix it? I can't just keep restarting the app every hour.
Here are the two error messages I'm currently getting:
When I try to pull back the records in a table named [Database] (which EF has called Databas in the model)
Message: [InvalidOperationException: The entity type Databas is not part of the model for the current context.]
System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType):59
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType):13
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize():0
System.Data.Entity.Internal.Linq.InternalSet`1.Include(String path):0
System.Data.Entity.Infrastructure.DbQuery`1.Include(String path):21
CVSupportPortal.Models.ViewModels.CloudAdminViewModel..ctor(Firm f):482
CVSupportPortal.Areas.CVS.Controllers.FirmsController.Cloud(Int32 firmid):206
(unknown).lambda_method(Closure , ControllerBase , Object[] ):-1
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters):129
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters):0
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41():0
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult):0
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass37+<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33():30
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult):0
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25+<>c__DisplayClass2a.<BeginInvokeAction>b__20():23
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult):0
And when I call a stored procedure:
Message: [InvalidOperationException: The type parameter 'CVSupportPortal.Models.EF.Database_Status_List_Result' in ExecuteFunction is incompatible with the type 'CloudDatabasesModel.Database_Status_List_Result' returned by the function. ]
System.Data.Common.Utils.MetadataHelper.CheckFunctionImportReturnType[TElement](EdmType expectedEdmType, MetadataWorkspace workspace):46
System.Data.Common.Utils.MetadataHelper.GetAndCheckFunctionImportReturnType[TElement](EdmFunction functionImport, Int32 resultSetIndex, MetadataWorkspace workspace):25
System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, MergeOption mergeOption, ObjectParameter[] parameters):0
CVSupportPortal.Models.EF.CloudDatabasesEntities.Database_Status_List():0
(unknown).lambda_method(Closure , ControllerBase , Object[] ):-1
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters):129
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters):0
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41():0
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult):0
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass37+<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33():30
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49():134
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult):0
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25+<>c__DisplayClass2a.<BeginInvokeAction>b__20():23
System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult):0
I still don't know what the cause of the problem is, but I was guessing that Entity Framework was losing the connection to the database somehow, since the database was accessible for other locations, just not through Entity Framework after it had been running for a while. I found out that the DbContext class has a constructor that allows you to specify a connection string at instantiation. My solution was to try using this in the hopes that it would start a new connection to the database instead of attempting to use an old one.
It worked. I haven't had any interruptions since I started using this. Here is what I changed (my database is called CloudDatabases).
CloudDatabases.Context.cs
// Already present
public CloudDatabasesEntities()
: base("name=CloudDatabasesEntities")
{
}
// Added this constructor
public CloudDatabasesEntities(string connStr)
: base(connStr)
{
}
In classes where I need to instantiate a connection to the database:
// Old, normal way
var cdb = new CloudDatabaseEntitites();
// New, non-breaking way
var connStr = ConfigurationManager.ConnectionStrings["CloudDatabasesEntities"].ConnectionString.ToString();
var cdb = new CloudDatabaseEntitites(connStr);
Where my Web.config (or Azure environment variables) has a connection string defined as such:
// Web.config
<add name="CloudDatabasesEntities" connectionString="metadata=res://*/CloudDatabases.csdl|res://*/CloudDatabases.ssdl|res://*/CloudDatabases.msl;provider=System.Data.SqlClient;provider connection string="data source=████████████████████████████████;initial catalog=CloudDatabases;persist security info=True;user id=████████████;password=██████████████████████;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
I am getting error "An item with the same key has already been added." I get this error randomly when many user try to access the same page on site in production at the same time.
In the code docid is passed and relevant help is displayed to user. As each user is viewing the same page so same ID is passed for all users. There is no insert operation in this call
Stack trace and souce code of mentioned line is given as follows
public string DocDescription(int docid)
{
DocumentRepository _Documentrepository = new DocumentRepository();
return _Documentrepository.GetDocDescription(docid);
}
}
public string GetDocDescription(int DocID)
{
if (DocID != 0)
return db.sysDocuments.SingleOrDefault(p => p.DocumentID == DocID).Description==null?"No Description Available":db.sysDocuments.SingleOrDefault(p => p.DocumentID == DocID).Description;
else
return "No Description Available";
}
Stack Trace excerpt:
System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. ---> System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Data.Linq.DataContext.GetTable(MetaTable metaTable)
at System.Data.Linq.DataContext.GetTable[TEntity]()
at UserManagement.Models.DocumentRepository.GetDocDescription(Int32 DocID) in D:\Myproj\UserManagement\UserManagement\Models\DocumnetRepository.cs:line 109
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod_callback(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at Castle.Proxies.Invocations.ControllerActionInvoker_InvokeActionMethod.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Glimpse.Net.Interceptor.InvokeActionMethodInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
From your code and comments, I get that you store db context in a static variable. This is generally a bad idea when working with entities.
DbContext is not thread safe. So, multiple users working with your site will cause such errors in context.
The general suggestion for working with context is to prefer short lived context. So just create a new instance, when you need it, and then forget it. For the web sites, it is quite common to use inversion of control container like Unity, Castle.Winsdor etc, and configure it to return one instance per web request for your DbContext. This will give you enough performance, so all entities needed for the current request are cached, and will not cause threading issues at the same time.
See comment too, static members are application scoped variables thus they're sharing the same dictionary which can throw errors like this if multiple requests add the same key.
This is really basic question and may be duplicate. Can anyone tell me how useful error info generated by any program in .Net.
Today I got an error "Ambiguous match found." while saving entity in database (using EF4)
I can't figure out why this error is coming, what is the root cause. Attached is the snap for same.
Here is the complete Error Details,
System.Reflection.AmbiguousMatchException was unhandled by user code
Message=Ambiguous match found.
Source=mscorlib
StackTrace:
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetProperty(String name)
at IAA.Data.EntityFramework.RepositoryWithTypedId`2.SaveOrUpdate[T](T entity)
at ABC.XYZ.ApplicationServices.AcknowledgementManagementService.SaveOrUpdate(AcknowledgementFormViewModel acknowledgementFormViewModel) in E:\RA\ABC.XYZ\app\ABC.XYZ.ApplicationServices\AcknowledgementManagementService.cs:line 123
at ABC.XYZ.Web.Controllers.AcknowledgementsController.Acknowledgements(AcknowledgementFormViewModel acknowledgementFormViewModel) in E:\RA\ABC.XYZ\app\ABC.XYZ.Web.Controllers\AcknowledgementsController.cs:line 68
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException:
This means that an System.Reflection.AmbiguousMatchException was thrown, and was not handled. It was thrown at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers), which was called from System.Type.GetProperty(String name), which was called from IAA.Data.EntityFramework.RepositoryWithTypedId2.SaveOrUpdate[T](T entity)`,
etc.
Hmya, no such luck. It would be very nice indeed if the Type.GetProperty() method would actually say which name was ambiguous. But it doesn't and you cannot easily find out. The code lives in the .NET framework and it is optimized, the debugger cannot retrieve the value of the name argument. Your only cue is that your entity model has two properties with the same name. Something like that anyway.
Debugging the .NET Framework can let you move into the call stack to the place where the exception occurs, where you can see local variables.
In Visual Studio 2010, this is as simple as setting Options in the Debugger section. In Visual Studio 2008, there are instructions here.
The callstack shows the following:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultModelBinder.CreateModel(ModelBindingContext bindingContext, Type modelType) +277
System.Web.Mvc.<>c__DisplayClass1.<BindModel>b__0() +98
System.Web.Mvc.ModelBindingContext.get_Model() +51
System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +2600
System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +1067
System.Web.Mvc.DefaultModelBinder.BindProperty(ModelBindingContext parentContext, Type propertyType, Func`1 propertyValueProvider, String propertyName) +208
System.Web.Mvc.DefaultModelBinder.BindModelCore(ModelBindingContext bindingContext) +1787
System.Web.Mvc.DefaultModelBinder.BindModel(ModelBindingContext bindingContext) +1067
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ParameterInfo parameterInfo) +355
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(MethodInfo methodInfo) +439
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +288
System.Web.Mvc.Controller.ExecuteCore() +180
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +96
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +36
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +377
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +71
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +36
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
I have a tiny form with a bunch of hidden fields and one submit button.
When I press it, I never even hit the requested method.
How do I go on and debug this?
It would be a great start if I knew WHAT object didn't have a parameterless constructor.
Where is this object? How can I solve this?
I know the question is rather vague, but currently it's all I've got..
--EDIT--
In my form I added Html.Hidden() inputs. Depending on previous actions, these can have a value of "". The action makes use of ModelBinding. Whenever the value is "" and the datatype is a SelectList, the modelbinder goes berzerk on me.
I feel more and more uncomfortable with how the SelectList is doing it's thing...
The idea is good, but there are some issues with it.
I solved the issue which is caused of SelectList object because it does not provide the default constructor so we cant have in out ViewModel.
For those Googling this exception, here is a more general way to diagnose it:
The only easy way I've found to diagnose this problem is to override MVC as close to the exception as possible with your own code. Then your code will break inside Visual Studio when this exception occurs, and you can read the Type causing the problem from the stack trace.
This seems like a horrible way to approach this problem, but it's very fast, and very consistent.
For example, if this error is occurring inside the MVC DefaultModelBinder (which you will know by checking the stack trace), then replace the DefaultModelBinder with this code:
public class MyDefaultModelBinder : System.Web.Mvc.DefaultModelBinder
{
protected override object CreateModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext, Type modelType)
{
return base.CreateModel(controllerContext, bindingContext, modelType);
}
}
And update your Global.asax.cs:
public class MvcApplication : System.Web.HttpApplication
{
...
protected void Application_Start(object sender, EventArgs e)
{
ModelBinders.Binders.DefaultBinder = new MyDefaultModelBinder();
}
}
Now the next time you get that exception, Visual Studio will stop inside your MyDefaultModelBinder class, and you can check the "modelType" property to see what type caused the problem.
The example above works for when you get the "No parameterless constructor defined for this object" exception during model binding, only. But similar code can be written for other extension points in MVC (e.g. controller construction).
Your custom classes in the action args must have a parameterless constructor in order to use the default model binder. Otherwise, either (1) create a custom model binder or (2) pass primitive types instead of custom classes to the Action.
I also have properties on my view model class that return SelectList instances. I decorated my class with the Bind attribute to exclude these properties like this:
[Bind(Exclude = "Countries")]
public class MyViewModel
{
...
public SelectList Countries { get; set; }
}
Hope that helps,
Roger
Did you remove Default.aspx? That needs to be in place to render the root properly. This can also happen if you're trying to use Dependency Injection and your container isn't setup properly - meaning there is no ControllerFactory that asks the DI Container for the instance.
The root of my problem was also SelectList.
I had this:
<%: Html.DropDownListFor(m => Model.Destinations, Model.Destinations)%>
When I should have had this:
<%: Html.DropDownListFor(m => Model.Destination, Model.Destinations)%>
Destination is the user's selection, Destinations is the list of possible values. Using the plural SelectList twice caused the problem.