BadImageFormatException error on Azure web app

0

I have published my website as a Azure web application(through Visual Studio publish) and I am getting a An unhandled exception has occurred while executing the System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124) error. The application however works fine on my local machine. Between the time when the application was working and now, the major changes that were made (to the application) were:

a. Added "Stripe.net" Version="25.19.0" (and pages that depend on it).

b. Added "Newtonsoft.Json" Version="12.0.2" (and pages that depend on it).

c. Removed AspNetCoreHostingModel=>InProcess from the application's project file.

What could be causing the issue? How should I go about diagnosing the issue, (other than rolling back the application code bit by bit)?

StackTrace:

2019-05-19T19:19:49.383181992Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
2019-05-19T19:19:49.383206193Z       Request starting HTTP/1.1 GET http://simplerproductsscrubber.azurewebsites.net/  
2019-05-19T19:19:49.383210893Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
2019-05-19T19:19:49.383214793Z       Executing endpoint 'Page: /Index'
2019-05-19T19:19:49.383218493Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
2019-05-19T19:19:49.383222293Z       Executed endpoint 'Page: /Index'
2019-05-19T19:19:49.383239793Z [41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
2019-05-19T19:19:49.383244393Z       An unhandled exception has occurred while executing the request.
2019-05-19T19:19:49.383247993Z System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124)
2019-05-19T19:19:49.383251793Z    at System.RuntimeTypeHandle.ConstructName(RuntimeTypeHandle handle, TypeNameFormatFlags formatFlags, StringHandleOnStack retString)
2019-05-19T19:19:49.383255693Z    at System.RuntimeType.RuntimeTypeCache.ConstructName(String& name, TypeNameFormatFlags formatFlags)
2019-05-19T19:19:49.383259593Z    at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultPageApplicationModelProvider.CreateModel(PageActionDescriptor actionDescriptor, TypeInfo pageTypeInfo)
2019-05-19T19:19:49.383263293Z    at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultPageApplicationModelProvider.OnProvidersExecuting(PageApplicationModelProviderContext context)
2019-05-19T19:19:49.383266893Z    at Microsoft.AspNetCore.Mvc.RazorPages.Internal.DefaultPageLoader.Load(PageActionDescriptor actionDescriptor)
2019-05-19T19:19:49.383270593Z    at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvokerProvider.OnProvidersExecuting(ActionInvokerProviderContext context)
2019-05-19T19:19:49.383274193Z    at Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory.CreateInvoker(ActionContext actionContext)
2019-05-19T19:19:49.383277693Z    at Microsoft.AspNetCore.Mvc.Internal.MvcEndpointDataSource.<>c__DisplayClass21_0.<CreateEndpoint>b__0(HttpContext context)
2019-05-19T19:19:49.383281493Z    at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
2019-05-19T19:19:49.383285093Z    at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
2019-05-19T19:19:49.383288493Z    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.383324793Z    at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.383330093Z    at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.383333793Z    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.383582695Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
2019-05-19T19:19:49.383591995Z       Executing endpoint 'Page: /Error'
2019-05-19T19:19:49.383803496Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
2019-05-19T19:19:49.383812596Z       Route matched with {page = "/Error", area = ""}. Executing page /Error
2019-05-19T19:19:49.384038497Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[101]
2019-05-19T19:19:49.384047697Z       Executing handler method Scrubber.Pages.ErrorModel.OnGet with arguments ((null)) - ModelState is Valid
2019-05-19T19:19:49.384195798Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[102]
2019-05-19T19:19:49.384203898Z       Executed handler method OnGet, returned result .
2019-05-19T19:19:49.384333699Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[103]
2019-05-19T19:19:49.384341699Z       Executing an implicit handler method - ModelState is Valid
2019-05-19T19:19:49.384470799Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[104]
2019-05-19T19:19:49.384478599Z       Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
2019-05-19T19:19:49.391635738Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[4]
2019-05-19T19:19:49.391647438Z       Executed page /Error in 7.6849ms
2019-05-19T19:19:49.391843939Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
2019-05-19T19:19:49.391853239Z       Executed endpoint 'Page: /Error'
2019-05-19T19:19:49.393836350Z [41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[3]
2019-05-19T19:19:49.393846750Z       An exception was thrown attempting to execute the error handler.
2019-05-19T19:19:49.393850550Z System.BadImageFormatException: Bad binary signature. (Exception from HRESULT: 0x80131192)
2019-05-19T19:19:49.393902050Z    at System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo method)
2019-05-19T19:19:49.393908850Z    at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType, Object target)
2019-05-19T19:19:49.393966351Z    at System.Linq.Expressions.Compiler.LambdaCompiler.CreateDelegate()
2019-05-19T19:19:49.393978851Z    at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
2019-05-19T19:19:49.393982651Z    at System.Linq.Expressions.Expression`1.Compile(Boolean preferInterpretation)
2019-05-19T19:19:49.393985951Z    at System.Linq.Expressions.Expression`1.Compile()
2019-05-19T19:19:49.394034551Z    at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
2019-05-19T19:19:49.394152852Z    at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)
2019-05-19T19:19:49.394230152Z    at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
2019-05-19T19:19:49.394238052Z    at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
2019-05-19T19:19:49.394290453Z    at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindPage(ActionContext context, String pageName)
2019-05-19T19:19:49.394298453Z    at Microsoft.AspNetCore.Mvc.Razor.RazorView.GetLayoutPage(ViewContext context, String executingFilePath, String layoutPath)
2019-05-19T19:19:49.394382253Z    at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
2019-05-19T19:19:49.394390853Z    at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
2019-05-19T19:19:49.394483754Z    at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
2019-05-19T19:19:49.394490454Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
2019-05-19T19:19:49.394493954Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
2019-05-19T19:19:49.394539654Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
2019-05-19T19:19:49.394545854Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
2019-05-19T19:19:49.394587054Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
2019-05-19T19:19:49.394593454Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
2019-05-19T19:19:49.394596754Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
2019-05-19T19:19:49.394647854Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2019-05-19T19:19:49.394654555Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
2019-05-19T19:19:49.394692355Z    at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
2019-05-19T19:19:49.394698155Z    at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
2019-05-19T19:19:49.394713655Z    at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
2019-05-19T19:19:49.394769155Z    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.394775855Z    at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.394779255Z    at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.394815655Z    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.402328096Z [41m[30mfail[39m[22m[49m: Microsoft.AspNetCore.Server.Kestrel[13]
2019-05-19T19:19:49.402372796Z       Connection id "0HLMRF8FM006I", Request id "0HLMRF8FM006I:00000001": An unhandled exception was thrown by the application.
2019-05-19T19:19:49.402422297Z System.BadImageFormatException: Index not found. (Exception from HRESULT: 0x80131124)
2019-05-19T19:19:49.402439497Z    at System.RuntimeTypeHandle.ConstructName(RuntimeTypeHandle handle, TypeNameFormatFlags formatFlags, StringHandleOnStack retString)
2019-05-19T19:19:49.402492897Z    at System.RuntimeType.RuntimeTypeCache.ConstructName(String& name, TypeNameFormatFlags formatFlags)
2019-05-19T19:19:49.402499697Z    at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultPageApplicationModelProvider.CreateModel(PageActionDescriptor actionDescriptor, TypeInfo pageTypeInfo)
2019-05-19T19:19:49.402587197Z    at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultPageApplicationModelProvider.OnProvidersExecuting(PageApplicationModelProviderContext context)
2019-05-19T19:19:49.402594898Z    at Microsoft.AspNetCore.Mvc.RazorPages.Internal.DefaultPageLoader.Load(PageActionDescriptor actionDescriptor)
2019-05-19T19:19:49.402636698Z    at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvokerProvider.OnProvidersExecuting(ActionInvokerProviderContext context)
2019-05-19T19:19:49.402650398Z    at Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory.CreateInvoker(ActionContext actionContext)
2019-05-19T19:19:49.402700598Z    at Microsoft.AspNetCore.Mvc.Internal.MvcEndpointDataSource.<>c__DisplayClass21_0.<CreateEndpoint>b__0(HttpContext context)
2019-05-19T19:19:49.402707498Z    at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
2019-05-19T19:19:49.402710898Z    at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
2019-05-19T19:19:49.402788099Z    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.402795299Z    at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.402799099Z    at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.402848499Z    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.402855199Z    at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
2019-05-19T19:19:49.402920099Z    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
2019-05-19T19:19:49.411044143Z [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
2019-05-19T19:19:49.411055543Z       Request finished in 29.3949ms 500 

Update 1:

  • When publishing, tried to "Remove Additional Files at destination" option.
  • Made sure that all the projects(only one) were being build as "any CPU" in both "debug" and "release" configuration.
c#
azure
asp.net-core
azure-web-app-service
razor-pages
asked on Stack Overflow May 19, 2019 by Ajit Goel • edited May 20, 2019 by Ajit Goel

1 Answer

0

I turned on Application Insights on the Azure portal and the issue seems to have been fixed. (I turned it off again). Very weird.

answered on Stack Overflow May 20, 2019 by Ajit Goel

User contributions licensed under CC BY-SA 3.0