Deploying MVC3 to a shared host - asp.net-mvc

I am trying to deploy my MVC3 app on a shared host. I've got .Net4 on the shared host and I have worked through the various bin deploy steps cited all over the internet. The problem is that I don't get an error when I try to access the site, I just get a message saying directory browsing is not allowed. I have uploaded the files but its like the server doesn't know what to do when it gets there. I would appreciate any tips anyone has to give regarding this...I need to show a demo today.
Thanks !
Edit:
So I managed to figure out that my host placed my account on a server running IIS6 and therefore cannot process extensionless urls, so I modified my routing table to append a .aspx to the controller name so that IIS can process the request. Now I get this error (which I guess has to do with EF4) when I try to access the url
Attempt by method 'System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(System.Data.Common.DbConnection)' to access method 'System.Data.Common.DbProviderServices.GetProviderFactory(System.Data.Common.DbConnection)' failed.
[MethodAccessException: Attempt by method 'System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(System.Data.Common.DbConnection)' to access method 'System.Data.Common.DbProviderServices.GetProviderFactory(System.Data.Common.DbConnection)' failed.]
System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection) +52
System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +63
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +157
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +51
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +407
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +17
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +40
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
WebShop.Controllers.HomeController.Index() in C:\Users\owner\Documents\My Web Sites\WebShop\WebShop\WebShop\Controllers\HomeController.cs:18
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +188
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +267
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +329
System.Web.Mvc.Controller.ExecuteCore() +115
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +94
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8683441
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
Anyone know how I can sort this out?
Thanks

It's not enough to move files to the host, you have to tell IIS your files are an application. That's the most common reason for the directory browsing error. Your hoster should have help pages on deploying ASP.NET applications.

Related

How to resolve Dynamic LINQ ParseException: "Identifier Expected"

I am getting generic error message System.Linq.Dynamic.ParseException: Identifier expected.
What should I check in order to resolve it? The error isn't very detailed.
I did check the source and the selector params from the ParseLambda method and T-SQL they carry seems valid and execute fine in the SQL Management Studio.
Server Error in '/' Application.
________________________________________
Identifier expected
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Linq.Dynamic.ParseException: Identifier expected
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ParseException: Identifier expected]
System.Linq.Dynamic.ExpressionParser.ValidateToken(TokenId t, String errorMessage) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1952
System.Linq.Dynamic.ExpressionParser.GetIdentifier() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1941
System.Linq.Dynamic.ExpressionParser.ParseNew() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:1038
System.Linq.Dynamic.ExpressionParser.ParseIdentifier() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:966
System.Linq.Dynamic.ExpressionParser.ParsePrimaryStart() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:867
System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:848
System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:844
System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:798
System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:771
System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:702
System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:689
System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:676
System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:662
System.Linq.Dynamic.ExpressionParser.Parse(Type resultType) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:629
System.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:166
System.Linq.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:161
System.Linq.Dynamic.DynamicQueryable.Select(IQueryable source, String selector, Object[] values) in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\DynamicQuery\Dynamic.cs:34
WebUI.Controllers.VoterController.ExportToExcel() in C:\Projects\EDgE\EDgE-EDGE_Parsippany\WebUI\Controllers\VoterController.cs:2288
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod_callback(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +42
Castle.Proxies.Invocations.ControllerActionInvoker_InvokeActionMethod.InvokeMethodOnTarget() +208
Castle.DynamicProxy.AbstractInvocation.Proceed() +56
Glimpse.Mvc3.Interceptor.InvokeActionMethodInterceptor.Intercept(IInvocation invocation) +408
Castle.DynamicProxy.AbstractInvocation.Proceed() +94
Castle.Proxies.ControllerActionInvokerProxy.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +222
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970141
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
ParseException at line 1952:
Call Stack exception source:
OK, I don't know if this is Microsoft bug in the System.Linq.Dynamic library or misuse of SQL column alias names, but in this special case the parser fails:
Select Col1 as First_Name, Col2 as Last_Name, col3 as 2012_P_Customer
From MyTable
The System.Linq.Dynamic parser fails when parsing Col3 as 2012_P_Customer. It did not like the 2012 number as prefix.
When I changed it to "col3 as P_Customer_2012 " it worked fine.
I knew that prefixing SQL column is a bad practice, but I did not know that the same is valid for the column alias.

DotNetOpenAuth...CreatRequest breaks on server (Works on my machine ;-)

I've created a site based on the ASP.NET MVC 4 Web Application. I have enabled the OpenAuth login providers for Twitter, Facebook and Google by following the instructions in AuthConfig.cs.
This works fine when the site is debugged on my local machine from Visual Studio on IIS Express. However, when I copy the site over to another machine, the entire site works fince, except anything that uses open auth.
On this machine I can access twitter, facebook and google using the browser.
When I try to log on using my site I get:
for Google: "Sequence contains no elements" with the stacktrace pointing at
[InvalidOperationException: Sequence contains no elements]
System.Linq.Enumerable.First(IEnumerable`1 source) +514
DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) +106
[ProtocolException: No OpenID endpoint found.]
DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) +303
DotNetOpenAuth.AspNet.Clients.OpenIdClient.RequestAuthentication(HttpContextBase context, Uri returnUrl) +135
DotNetOpenAuth.AspNet.OpenAuthSecurityManager.RequestAuthentication(String returnUrl) +666
NotesBoard.Controllers.ExternalLoginResult.ExecuteResult(ControllerContext context) in d:\dtaylor\Documents\Visual Studio 2012\Projects\NotesBoard\NotesBoard\Controllers\AccountController.cs:369
System.Web.Mvc.<>c_DisplayClass1a.b_17() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c_DisplayClass25.b_22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c_DisplayClass1d.b_18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
For Twitter I get: "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 199.16.156.72:443" with the following Stack trace
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 199.16.156.72:443]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +273
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +584
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetResponse() +8527180
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) +261
[ProtocolException: Error occurred while sending a direct message or getting the response.]
DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest request, DirectWebRequestOptions options) +1862
DotNetOpenAuth.Messaging.Channel.RequestCore(IDirectedProtocolMessage request) +516
DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage) +138
DotNetOpenAuth.Messaging.Channel.Request(IDirectedProtocolMessage requestMessage) +45
DotNetOpenAuth.OAuth.ConsumerBase.PrepareRequestUserAuthorization(Uri callback, IDictionary2 requestParameters, IDictionary2 redirectParameters, String& requestToken) +202
DotNetOpenAuth.AspNet.Clients.DotNetOpenAuthWebConsumer.RequestAuthentication(Uri callback) +88
DotNetOpenAuth.AspNet.OpenAuthSecurityManager.RequestAuthentication(String returnUrl) +666
NotesBoard.Controllers.ExternalLoginResult.ExecuteResult(ControllerContext context) in d:\dtaylor\Documents\Visual Studio 2012\Projects\NotesBoard\NotesBoard\Controllers\AccountController.cs:369
System.Web.Mvc.<>c_DisplayClass1a.b_17() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func1 continuation) +613
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
System.Web.Mvc.Async.<>c_DisplayClass25.b_22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c_DisplayClass1d.b_18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
Facebook on the other hand actually prompts me for a username and password but then also comes back with "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.252.100.27:443" and the following stack trace:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.252.100.27:443]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +273
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +584
[WebException: Unable to connect to the remote server]
System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +3624556
System.Net.WebClient.DownloadString(Uri address) +213
DotNetOpenAuth.AspNet.Clients.FacebookClient.QueryAccessToken(Uri returnUrl, String authorizationCode) +399
DotNetOpenAuth.AspNet.Clients.OAuth2Client.VerifyAuthentication(HttpContextBase context, Uri returnPageUrl) +186
DotNetOpenAuth.AspNet.OpenAuthSecurityManager.VerifyAuthentication(String returnUrl) +502
Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.VerifyAuthenticationCore(HttpContextBase context, String returnUrl) +250
NotesBoard.Controllers.AccountController.ExternalLoginCallback(String returnUrl) in d:\dtaylor\Documents\Visual Studio 2012\Projects\NotesBoard\NotesBoard\Controllers\AccountController.cs:225
lambda_method(Closure , ControllerBase , Object[] ) +127
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +274
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +39
System.Web.Mvc.Async.<>c_DisplayClass39.b_33() +120
System.Web.Mvc.Async.<>c_DisplayClass4f.b_49() +452
System.Web.Mvc.Async.<>c_DisplayClass4f.b_49() +452
System.Web.Mvc.Async.<>c_DisplayClass37.b_36(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c_DisplayClass2a.b_20() +33
System.Web.Mvc.Async.<>c_DisplayClass25.b_22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c_DisplayClass1d.b_18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
PS. It's worth mentioning that we access the internet via a proxy, which is set up on the server in IE. I haven't found any code in the provided templates that let me specify proxy servers etc.
Help please.
I think I was able to resolve this issue. It turns out that our proxy server seems to have been the issue. I had the Application pool that was running this site in IIS configured to use NetworkServices as the Application Pool Identity. I changed the Identity to run as myself to see if the problem was resolved and it was. It's obviously not recommended to have a site run as a user account, so I will be requesting our IT team to create a domain account for this site, that also has access through our proxy servers.
I hope that helps someone else having the same problem.

MVC Async error - The asynchronous action method 'Complete' cannot be executed synchronously

I am using MVC4 with VS 2010. I have an async action that I am trying to get working. My controller inherits from AsyncController and I have the ~Async and ~Completed methods. I am able to execute my async action correctly in a sample test project. But when I run it as part of my core web app it get this exception
[InvalidOperationException: The asynchronous action method 'Complete' cannot be executed synchronously.]
System.Web.Mvc.Async.AsyncActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +133
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +39
I am using Unity for Dependency Injection, ActionAttributeFilters and MVCSiteMapProvider, I am wondering if one of these is causing the above issue. Any help is appreciated.
Thanks
The whole stack trace
[InvalidOperationException: The asynchronous action method 'Complete' cannot be executed synchronously.]
System.Web.Mvc.Async.AsyncActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +133
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() +129
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +978122
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +978400
NotFoundMvc.ActionInvokerWrapper.InvokeActionWith404Catch(ControllerContext controllerContext, String actionName) in c:\Users\Andrew Davey\projects\opensource\NotFoundMvc\src\NotFoundMvc\ActionInvokerWrapper.cs:40
NotFoundMvc.ActionInvokerWrapper.InvokeAction(ControllerContext controllerContext, String actionName) in c:\Users\Andrew Davey\projects\opensource\NotFoundMvc\src\NotFoundMvc\ActionInvokerWrapper.cs:21
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__19() +40
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +67
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +53
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +53
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
It looks like the NotFoundMVC Lib cause this problem. uninstall this package you will get work fine!

Azure not supporting reflection?

I uploaded an ASP.NET MVC site to Azure, which works just fine in the emulator. When I run it on Azure however I get the error "Method not found: 'System.Object System.Reflection.PropertyInfo.GetValue(System.Object)'"
Stack Trace:
[MissingMethodException: Method not found: 'System.Object System.Reflection.PropertyInfo.GetValue(System.Object)'.]
FW.Helpers.ListHelper.ToSelectListItemModels(IEnumerable`1 list, Expression`1 valueProperty, Expression`1 textProperty) +0
My.Application.MyBuilderService.GetFilterList() +1444
My.Application.MyBuilderService.BuildMyViewModel(Query query) +547
My.Appsite.Controllers.MyController.BuildMyViewModel(Query query) in C:\Users\user\documents\visual studio 2010\Projects\WindowsAzureProject3\MvcWebRole1\Controllers \MyController.cs:40
lambda_method(Closure , ControllerBase , Object[] ) +127
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +248
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +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) +691
System.Web.Mvc.Controller.ExecuteCore() +162
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +305
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
It is a normal Windows and .NET installation. Reflection is supported. Clearly there is another factor here. We don't have enough information to help however. A stack trace is important for things like this.
You probably need to make sure the DLLs you use all have the Copy Local property set to True. Like:
http://stevesmithblog.com/blog/asp-net-mvc-2-and-windows-azure/

EF4 trying to re-create database even though it's already there?

I'm using ASP.NET MVC 3 and have learnt through the MVC Music Store and other sources. I was able to create a database and have it live but the weird thing was about 5 hours after it was live it went down and had the following error and stack trace:
Note: This also seems to be the case whenever I publish the site. I have to go and delete the database manually for it to re create it and then it will work. But now that I'm live I can't do that because data is already being stored in there that I don't want to redo.
File already exists. Try using a different database name. [ File name = C:\HostingSpaces\...\wwwroot\App_Data\Test.sdf ]
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlServerCe.SqlCeException: File already exists. Try using a different database name. [ File name = C:\HostingSpaces\mtnp55\pricexperience.com\wwwroot\App_Data\Test.sdf ]
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlCeException (0x80004005): File already exists. Try using a different database name. [ File name = C:\HostingSpaces\...\wwwroot\App_Data\Test.sdf ]]
System.Data.SqlServerCe.SqlCeEngine.ProcessResults(IntPtr pError, Int32 hr) +72
System.Data.SqlServerCe.SqlCeEngine.CreateDatabase() +658
System.Data.SqlServerCe.SqlCeProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 timeOut, StoreItemCollection storeItemCollection) +194
System.Data.Objects.ObjectContext.CreateDatabase() +84
System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext) +8
System.Data.Entity.Database.Create() +76
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +387
System.Data.Entity.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c) +75
System.Data.Entity.Internal.<>c__DisplayClass5.<PerformDatabaseInitialization>b__3() +19
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +72
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +169
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +118
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +190
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +28
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +62
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
PriceXperience.Controllers.AppsController.ViewLeaderboards(Int32 gameId) in C:\Users\Public\Documents\Development\...\Controllers\AppsController.cs:42
lambda_method(Closure , ControllerBase , Object[] ) +101
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
I've tried many things but still cannot figure out why it does this. I do have a database initialize.
System.Data.Entity.Database.SetInitializer<MobileEntities>(new SampleData());
public class SampleData : CreateDatabaseIfNotExists<MobileEntities>
The code that runs when I try to access the db is the following:
public ActionResult ViewLeaderboards(int gameId)
{
var leaderboards = from u in mobileDB.Scores
where u.GameId == gameId
select u;
return View(leaderboards.OrderByDescending(u => u.Score).ToList());
}
When publishing you need to be sure to REMOVE the Initializer from the Global.asax. The Initializer is only for populating test data, and should not be in use during production. I also remember reading somewhere that setting the Initializer to null might work.
Database.SetInitializer<MyContext>(null);
Or just comment out the line where you call SetInitializer before publishing. I also exclude my Initializer class from the project before publishing.
The default strategy for Code First contexts is an instance of CreateDatabaseIfNotExists.
So it is necessary to include the
Database.SetInitializer<MyContext>(null);
so that the default initializer is not called which might then give an error!
Also, it is necessary to include the generic tag when setting it to null or the compiler will give an error.

Resources