I have simple project using the template of Microsoft MVC's Authentication. upon debugging on the development machine and IIS express, I can create an new user I can Log in using its default controllers, But when i tried to publish it on IIS i catch a null reference exception on the Registration Process. here is the stacktrace:
[NullReferenceException: Object reference not set to an instance of an object.]
TrabahoNow.Web.Controllers.<Register>d__8.MoveNext() +224
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +84
System.Web.Mvc.Async.<>c__DisplayClass37. <BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.AsyncInvocationWithFilters. <InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
System.Web.Mvc.Async.<>c__DisplayClass46. <InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651796
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I have no Idea what cause it coz it is running on express. here is my controller action:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser()
{
UserName = model.Email,
FirstName = model.FirstName.ToUpper(),
LastName = model.LastName.ToUpper(),
MiddleName = model.MiddleName.ToUpper(),
Email = model.Email,
PhoneNumber = model.Phone,
DesiredPosition = model.DesiredPosition,
BirthDate = DateTime.Now,
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
This fails in IIS Server. Can someone help me figure this one out??
here is my set up..
.NET 4.5.1
EF 6.0
MVC 5
Given the exception that you have, and confirmation that the error happens when you construct an instance of your ApplicationUser class, your issue is highly likely to be that either model.FirstName, model.LastName or model.MiddleName is null.
The call to ToUpper() will be the root cause of your exception.
Either check for null:
FirstName = string.IsNullOrEmpty(model.FirstName) ? null : model.FirstName
Or, if C# 6 is available to you, use the null propagation operator:
FirstName = model.FirstName?.ToUpper();
Related
we are facing with a very strange problem with azure search which only happens on our live environment.
This is the code
var aaa= new SearchServiceClient("name", new SearchCredentials("XXX"));
Literally one line of code, directly under Controller, the page breaks with following message:
[AmbiguousMatchException: Multiple custom attributes of the same type found.]
System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) +119
Microsoft.Rest.ServiceClient`1.get_FrameworkVersion() +103
Microsoft.Rest.ServiceClient`1.get_DefaultUserAgentInfoList() +120
Microsoft.Rest.ServiceClient`1.SetUserAgent(String productName, String version) +50
TMDApi.Controllers.HomeController.Fucker() in C:\PROJECTS\txfmd\TMDApi\Controllers\HomeController.cs:66
lambda_method(Closure , ControllerBase , Object[] ) +87
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +209
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +40
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +71
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +43
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +385
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +43
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +30
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +39
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +656
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +143
We are using Azure.Search v4.0.0.0
This looks like a known compatibility issue with an older version of Application Insights. See this GitHub issue for details on how to resolve it.
I'm trying to create an error banner for my site for things like a webjob failing, third party service down, etc. I put a function in my controller that queries my "errors" table and should ideally display each message in the view. I made the partial page render in my layout page, however I run into a NullReferenceException error since the partial page renders before the actual site's content is created and rendered. Here is the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.HttpContextBaseExtensions.GetOwinEnvironment(HttpContextBase context) +34
System.Web.HttpContextBaseExtensions.GetOwinContext(HttpContextBase context) +50
Webapp.Controllers.ManageController.getContext() in c:\Users\Sergey\Source\Workspaces\xxx\xxx\Webapp\Controllers\ManageController.cs:26
Webapp.Controllers.ManageController.SiteErrorBanner() in c:\Users\Sergey\Source\Workspaces\xxx\xxx\Webapp\Controllers\ManageController.cs:485
ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Users\Sergey\Source\Workspaces\xxx\xxx\Webapp\Views\Shared\_Layout.cshtml:25
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +121
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +145
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) +41
System.Web.WebPages.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer) +335
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
System.Web.WebPages.WebPageBase.Write(HelperResult result) +53
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178
System.Web.WebPages.WebPageBase.PopContext() +229
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +154
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +321
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651516
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I'm a bit lost as to how to access the database before it's instantiated. How does one access the data and display it before the rest of the page loads? Is there a better way to implement this error banner too?
Edit: some code for context.
Here's the layout file structure:
<html>
<head>
<!-- meta tags, etc. -->
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryval")
#Scripts.Render("~/bundles/bootstrap")
</head>
<body>
<div id="wrapper">
#Html.Action(MVC.Manage.SiteErrorBanner())
<!-- nav, other user profile dropdowns, etc -->
#RenderBody()
</body>
</html>
Here are the relevant functions in the controller:
public partial class ManageController : Controller
{
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
private DBContext _dbContext;
public DBContext DBContext
{
get
{
return _dbContext ?? HttpContext.GetOwinContext().Get<DBContext>();
}
private set
{
_dbContext = value;
}
}
// some user profile functions
[ChildActionOnly]
public ActionResult SiteErrorBanner()
{
var model = new Webapp.Models.SiteErrorModel();
model.UnresolvedErrors = new List<DataLibrary.site_errors>();
model.UnresolvedErrors = DBContext.site_errors.Where(error => error.resolved == false).ToList();
return PartialView(MVC.Shared.Views.ErrorBanner, model);
}
}
I am having a hard time authenticating doing external authentication with Facebook on Web API. This is my controller to handle the Facebook button click.
[Route("facebooklogin", Name= "FacebookLogin")]
[ValidateAntiForgeryToken()]
public async Task<ActionResult> FacebookLogin()
{
string facebookLink = string.Empty;
//Get available logins from api
using(HttpClient client = new HttpClient() { BaseAddress = new Uri(Request.Url.GetLeftPart(UriPartial.Authority)) })
{
var returnUrl = Url.RouteUrl("FacebookCallback");
var url = "/api/Account/ExternalLogins?returnUrl=" + HttpUtility.UrlEncode(returnUrl + "&generateState=true");
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
var loginList = await response.Content.ReadAsAsync<List<ExternalLoginViewModel>>();
facebookLink = loginList.Where(x => x.Name == "Facebook").Select(x => x.Url).FirstOrDefault();
//Send a get request to the facebook url
var facebookUrlResponse = await client.GetAsync(facebookLink);
facebookUrlResponse.EnsureSuccessStatusCode();
}
else { }
}
return View();
}
[Route("facebookcallback", Name="FacebookCallback")]
public ActionResult FacebookLoginCallback()
{
//Parse the access_token from facebook from the url
return View();
}
Whenenever i debug to var facebookUrlResponse = await client.GetAsync(facebookLink);, i realise i have a bad request. My code gets all the available external login providers and then try to use the url available generated for Facebook to hit the /api/Account/ExternalLogin endpoint in the account controller. I am unable hit that endpoint.
I get this error message:
Response status code does not indicate success: 400 (Bad Request).
I plan to have the redirect uri come to the FacebookCallback route. Then i can parse the access_token from the uri and do further procession. Can anyone please help me out?
I could glean this info from postman:
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.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
The source error is:
//Send a get request to the facebook url
Line 135: var facebookUrlResponse = await client.GetAsync(facebookLink);
This is the stacktrace also:
[HttpRequestException: Response status code does not indicate success: 400 (Bad Request).]
System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() +92180
Blinkas.Web.Controllers.<FacebookLogin>d__6.MoveNext() in C:\Users\Williams\Documents\Visual Studio 2015\Projects\Blinkas\Blinkas.Web\Controllers\HomeController.cs:136
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
System.Runtime.CompilerServices.TaskAwaiter.GetResult() +26
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +42
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +73
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +37
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +27
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +58
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +68
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +69
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +230
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +27
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +27
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +58
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +68
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +42
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +124
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +27
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +58
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +30
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +27
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +58
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +30
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +21
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +32
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +26
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +40
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +58
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +30
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +21
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +24
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +27
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +58
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +30
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +21
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +29
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +23
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
For whatever reason when we started getting this exception message on one of our servers, all are Window server 2008 R2. The website site was fine a few weeks ago and we can't tell what has changed. The application pool has enable 32 bit apps set to true. We can deploy the same source code to another server and it works but not vice versa.
Anyone have any ideas?
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.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +0
System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary2 identifierValues, List1 generatedValues) +645
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +140
[UpdateException: An error occurred while updating the entries. See the inner exception for details.]
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +303
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) +9
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(T noChangesResult, Func`2 updateFunction, Boolean throwOnClosedConnection) +124
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update(Boolean throwOnClosedConnection) +89
System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__b() +18
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +314
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy) +161
System.Data.Entity.Core.Objects.<>c__DisplayClass9.<SaveChanges>b__6() +21
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +153
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +226
System.Data.Entity.Internal.InternalContext.SaveChanges() +141
[DbUpdateException: An error occurred while updating the entries. See the inner exception for details.]
System.Data.Entity.Internal.InternalContext.SaveChanges() +209
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +27
System.Data.Entity.DbContext.SaveChanges() +20
SecureEDI.PMS.DataAccess.CrudEFRepository`1.Save() +35
SecureEDI.PMS.DataAccess.CrudEFRepository`1.Create(T entity) +183
SecureEDI.PMS.BusinessLogic.CrudEFManager`1.Create(T entity) +61
SecureEDI.PMS.Core.Exceptions.ExceptionHandler.LogException(Exception e) +1724
SecureEDI.PMS.Core.Exceptions.ExceptionHandler.HandleException(Exception exception) +1434
SecureEDI.PMS.Core.Exceptions.ExceptionHandler..ctor(Exception exception) +24
SecureEDI.PMS.Web.Controllers.BaseController.OnException(ExceptionContext filterContext) +582
System.Web.Mvc.Controller.System.Web.Mvc.IExceptionFilter.OnException(ExceptionContext filterContext) +10
System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception) +115
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +106
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +47
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +18
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +29
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +52
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +28
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +46
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +52
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +28
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +15
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +30
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +25
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +52
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +28
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +15
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +820
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +148
I want to include all files in directory like this:
bundles.Add(new StyleBundle("~/Content/simpliq_css").Include(
"~/Content/simpliq/*.css"
));
But i got this error Index was outside the bounds of the array
and red line is:
#Styles.Render("~/Content/simpliq_css")
[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.String.get_Chars(Int32 index) +0
Microsoft.Ajax.Utilities.CssParser.Append(Object obj, TokenType tokenType) +402
Microsoft.Ajax.Utilities.CssParser.AppendCurrent() +74
Microsoft.Ajax.Utilities.CssParser.ParseElementName() +321
Microsoft.Ajax.Utilities.CssParser.ParseSimpleSelector() +54
Microsoft.Ajax.Utilities.CssParser.ParseSelector() +555
Microsoft.Ajax.Utilities.CssParser.ParseRule() +165
Microsoft.Ajax.Utilities.CssParser.ParseStylesheet() +186
Microsoft.Ajax.Utilities.CssParser.Parse(String source) +946
Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String source, CssSettings settings, CodeSettings scriptSettings) +439
Microsoft.Ajax.Utilities.Minifier.MinifyStyleSheet(String source, CssSettings settings) +73
System.Web.Optimization.CssMinify.Process(BundleContext context, BundleResponse response) +302
System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable`1 bundleFiles) +207
System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) +355
System.Web.Optimization.Bundle.GetBundleResponse(BundleContext context) +104
System.Web.Optimization.BundleResolver.GetBundleContents(String virtualPath) +254
System.Web.Optimization.AssetManager.EliminateDuplicatesAndResolveUrls(IEnumerable`1 refs) +435
System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 assets) +1030
System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) +75
System.Web.Optimization.Styles.RenderFormat(String tagFormat, String[] paths) +293
System.Web.Optimization.Styles.Render(String[] paths) +51
ASP._Page_Areas_Admin_Views_Shared__Layout_cshtml.Execute() in f:\MyProjects\Fables\Fables\Fables.Web\Areas\Admin\Views\Shared\_Layout.cshtml:8
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +271
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +120
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +145
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer) +41
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +335
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
System.Web.WebPages.WebPageBase.Write(HelperResult result) +53
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178
System.Web.WebPages.WebPageBase.PopContext() +347
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +154
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106
System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +321
System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Problem was in version of next packages:
You have to update it and problem will be solved.
I had the same problem and when I tried different checking I found out that there is a selector in my css file like this that cause the problem:
.glyphicons-icon _:-o-prefocus, .glyphicons-icon { background-image: url(../images/glyphicons.png); }
it seems that Microsoft.Ajax.Utilities.CssParser has a problem with _: css selector. I removed the line and it's working.
The same error can appear when one try to add javascript files to a StyleBundle.
I had the same error. My ASP.NET Web Optimization Framework was updated, but Bootstrap was at version 3.3.0. I updated Bootstrap to 3.3.5 and the error is gone.
In my case it was just an extra apostrophe "`" in one of js files. ASP.NET seems to be sensitive to this particular character (Grave accent). So be sure to check your code for typos.
Note that this can be caused by invalid JavaScript. While working on some JavaScript, I noticed that my bundles suddenly started throwing this message. The stack trace showed that it was blowing up on "Microsoft.Ajax.Utilities.JSScanner.ScanTemplateLiteral". It turns out I had inadvertently added a ` (backtick) in my JavaScript. Removing it caused everything to work again. I'm running Webgrease 1.6.0 and Microsoft ASP.NET Web Optimization Framework 1.1.2.
The bundler was not affected when the CSS had a backtick in it.