Rotativa PDF generation failure and web farm - asp.net-mvc

I'm using both the ViewAsPDF and ActionAsPDF methods at different parts of the website and have deployed the code to our production servers. When I access the individual server IP addresses then the PDF's print as expected but when I use the URL which is load balanced across the servers, the PDF functionality fails with the following error:
Exception information:
Exception type: Exception
Exception message: Error: Failed loading page http://example.com/PDF (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: UnknownNetworkError
at Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html)
at Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches)
at Rotativa.AsPdfResultBase.CallTheDriver(ControllerContext context)
at Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context)
at Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
A common solution to PDF generation is to add the msvcp120.dll and msvcr120.dll files to the same folder as wkhtmltopdf.exe but this hasn't made a difference.

Related

Rotativa - Wkhtmltopdf has stopped working

I get the following exception (no actual message, just a stack trace) when trying to generate some PDF with Rotativa, in an ASP.NET MVC application.
System.Exception at Rotativa.WkhtmltopdfDriver.Convert(String
wkhtmltopdfPath, String switches, String html) at
Rotativa.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String
switches, String html) at
Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) at
Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) at
Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context)
at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext
controllerContext, ActionResult actionResult) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1
filters, Int32 filterIndex, ResultExecutingContext preContext,
ControllerContext controllerContext, ActionResult actionResult) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1
filters, Int32 filterIndex, ResultExecutingContext preContext,
ControllerContext controllerContext, ActionResult actionResult) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1
filters, Int32 filterIndex, ResultExecutingContext preContext,
ControllerContext controllerContext, ActionResult actionResult) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
controllerContext, IList1 filters, ActionResult actionResult) at
System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult
asyncResult) at
System.Web.Mvc.Controller.b__1d(IAsyncResult
asyncResult, ExecuteCoreState innerState) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.b__15(IAsyncResult
asyncResult, Controller controller) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult
asyncResult) at
System.Web.Mvc.MvcHandler.b__5(IAsyncResult
asyncResult, ProcessRequestState innerState) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult
asyncResult) at
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End()
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult
asyncResult) at
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
The issue is not related to missing C++ Redistributable Package for Visual Studio 2013(MSVCP120.dll), as they are installed on the machine.
Actually, some PDF can be generated through the application, which makes me think there is something in the view that causes Wkhtmltopdf to stop working sometimes...
Any idea as to what causes this exception or how I could debug it?
(The Rotativa version is 1.6.4 I am using MVC5)
I found the solution after a number of trials and errors. This question also pointed me in the right direction. It is apparently an issue with wkhtmltopdf page breaking algorithm, and large table or HTML blocks. So, to solve my problem I changed my HTML into smaller chunks and it now works.

OData DELETE request conflicts with ASP.NET MVC

I have an MVC4 web webapplication running on my server and I have a ADO.NET Data Service (OData) service in the same directory.
Everything is working fine, my views can consume my OData service from client-side, but all the DELETE requests are failing with Error 500:
Exception type: InvalidOperationException
Exception message: The view 'Northwind.svc/Products(90)' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Northwind.svc/Products(90).aspx
~/Views/Home/Northwind.svc/Products(90).ascx
~/Views/Shared/Northwind.svc/Products(90).aspx
~/Views/Shared/Northwind.svc/Products(90).ascx
~/Views/Home/Northwind.svc/Products(90).cshtml
~/Views/Home/Northwind.svc/Products(90).vbhtml
~/Views/Shared/Northwind.svc/Products(90).cshtml
~/Views/Shared/Northwind.svc/Products(90).vbhtml
at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The request:
Request URL:http://{myhost}/Northwind.svc/Products(90)
Request Method:DELETE
Accept:application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,hu;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Host: {myhost}
MaxDataServiceVersion:2.0
Origin:http://{myhost}
Did anybody experience the same issue? I appreciate all the ideas.

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.

Can't understand why I'm getting this nullReference exception in ASP MVC when loading a page

I have a web application that is not giving me any problems on my computer, but when I deploy it to the server I get this error. It doesn't give me any source code lines to check and I don't have any idea why it may be happening
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[No relevant source lines]
Source File: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a9dc635c\ccb3814\App_Web_item.cshtml.f0356b3c.uyw8roer.0.cs Line: 0
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP._Page__AssemblyResource_MyProject_Web_Mvc__Version_1_0_0_0__Culture_neutral__PublicKeyToken_null_Views_LeagueGlobal_Item_cshtml.Execute() in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a9dc635c\ccb3814\App_Web_item.cshtml.f0356b3c.uyw8roer.0.cs:0
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +279
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +125
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +195
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +383
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +32
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +977396
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +977396
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +964636
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +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
I run into the same issue. Unfortunately the stack trace isn't very helpful in this case. The exception is happening for sure in the view, what it was in my case:
#Model.SomeProperty.Trim()
And Model.SomeProperty was null. As there is no way how to debug it; I recommend binary split approach:
save your view somewhere else
remove one-by-one logical parts from your view
after each removal save your view and retest
if the exception is no longer reproducible, the NullReferenceException happened in the block you've removed; so add it back and remove logical parts inside this block until you isolate the line causing an exception
Its lame I know, but I found no other way - btw. this is what I got for doing controller job in view.
Go to line 0 of your source file at:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\a9dc635c\ccb3814\App_Web_item.cshtml.f0356b3c.uyw8roer.0.cs
Then, use this to pin-point where exactly the exception happens in your code block:
try
{
...
}
catch (NullReferenceException ex)
{
ShowMessageBox("Error" + ex.Message);
}
Check that:
You've initiated the variables that you're manipulating.
Variables that you're using have not become null since deploying it to the server.
You are not using variables outside of your scope.

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!

Resources