Search code examples
c#asp.net-coreiis.net-6.0

Unexpected System.BadImageFormatException: Index not found That is Fixed with Restart


I have an ASP.NET Core 6 MVC web application hosted on IIS that all of a sudden started throwing the following exception:

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.

Index not found. (0x80131124)
Index not found. (0x80131124)
Index not found. (0x80131124)
Index not found. (0x80131124)
Index not found. (0x80131124)
Index not found. (0x80131124)

at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature) at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes() at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors() at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context) at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection() at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize() at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors() at Microsoft.AspNetCore.Mvc.Routing.AttributeRoute.GetTreeRouter() at Microsoft.AspNetCore.Mvc.Routing.AttributeRoute.RouteAsync(RouteContext context) at Microsoft.AspNetCore.Routing.RouteCollection.RouteAsync(RouteContext context) at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 114 at StackExchange.Exceptional.ExceptionalMiddleware.Invoke(HttpContext context) at StackExchange.Exceptional.ExceptionalMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) System.BadImageFormatException: Index not found. (0x80131124) System.BadImageFormatException: Index not found. (0x80131124) System.BadImageFormatException: Index not found. (0x80131124) System.BadImageFormatException: Index not found. (0x80131124) System.BadImageFormatException: Index not found. (0x80131124) System.BadImageFormatException: Index not found. (0x80131124)

I'm guessing it started happening after an automatic app pool recycle as there were no changes to the app or environment before the issue started happening. Restarting the VM fixed the issue but we don't know why it happened in the first place.

Any folks have any ideas how this happens all of sudden without any app or environment changes?


Solution

  • After looking through Windows Event Logs we noticed the VM ran out of memory at some point which we believe triggered this error: low memory warning in event viewer

    Even though the low memory condition didn't last very long we think it left the app in a broken state as it directly correlates with when the errors started: time series of available memory