System.BadImageFormatException Wrong image format

Hi, im using the latest version of the Performance Profiler (10.1.8.1426 pro).

I tryed to profile my ASP.net MVC version 4.7.2 application on IIS. 

Since the latest update, this error message occured:
System.BadImageFormatException: Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B)

Log Errors:

28 Aug 2019 13:24:36.030 [21] ERROR RedGate.Profiler.Engine.Startup.IIS.IIS7Utilities - The profiler tried to run "C:\WINDOWS\system32\inetsrv\appcmd.exe list apppools " but got the error: "<?xml version="1.0" encoding="UTF-8"?>

    <ERROR message="Konfigurationsfehler &#xD;&#xA;Dateiname: redirection.config&#xD;&#xA;Zeilennummer: 0&#xD;&#xA;Beschreibung: Die Konfigurationsdatei kann aufgrund unzureichender Berechtigungen nicht gelesen werden.&#xD;&#xA;." />

" and exit code: 5

Do you have some idea how i can fix it? 
:) 

Greetings, 
Lasse
Tagged:

Answers

  • Jessica RJessica R Posts: 1,319 Rose Gold 4

    Thanks for your post and sorry to hear you're running into an issue!

    Can I just confirm, does the profiler itself throw the System.BadImageFormatException or is it your application that throws the error when ANTS launches it? Does it still happen if you use Sampling mode of profiling?

    I think the error in the log is likely a red herring, but as it says "The configuration file can not be read due to insufficient permissions" can you kindly try running the profiler explicitly as administrator to see if the error remains?

    If so, can you please send us a screenshot of the error, and also check Event Viewer>Windows log>Application for any related entries? 

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • frostfirefrostfire Posts: 1 New member
    Hi, I just updated to the latest version and ran into the exact same issue.
    Had to do a restore and go back to the previously installed version (10.1.5.xxx)

    I was launching a .Net Core project, and the bad image error was dumped in the Output in the profiler with a stacktrace back to my startup code.

    After going back to the previous version, it all works again.

    Googling only led me to switching to 32bit mode, but that option is only available for iis express profiling
  • Jessica RJessica R Posts: 1,319 Rose Gold 4

    Thanks @frostfire!

    That note about 32-bitness led me to change the config of my test application to 32-bit, and I do then get the System.BadImageFormatException when profiling. However, even when I run the 32-bit application outside of the profiler, it still crashes (without a clear error), so I'm not sure if it's the same thing. :/

    I was thinking that maybe even if my un-profiled application version crashes, that I could see if the previous version of the profiler was correctly launches the 32-bit version of dotnet.exe, while the latest launches the 64-bit, and that it would explain the problem.

    However, I also get the System.BadImageFormatException error even when profiling with 10.1.5, and they're both launching the 64-bit version of dotnet.exe, so I'm not sure if what I'm experiencing is exactly the same.

    Can I just confirm if your application does run as 32-bit? Can I also check--@frostfire, when  you profile with the older version, can you check Task Manager to see the path of the dotnet.exe process that was launched? Is it C:\Program Files(x86)\dotnet\dotnet.exe or C:\Program Files\dotnet\dotnet.exe?

    Thank you!

    Jessica Ramos

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • vishnu4vishnu4 Posts: 4 New member
    this looks like no one has responded in a while, but i'm getting exactly the same problem.  my application works fine, until i start it (both in IIS and IIS express) in ANTS, and then i get the following error:

    An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Type = System.BadImageFormatException Source = CoBRACommon at _ANTS_Managed_Begin_Async() at CoBRACommon.Utilities.CacheExtensions.GetAsync[T](ICacheManager cacheManager, String key, Func`1 acquire) at CoBRAMVC4Portal.Services.ProjectService.<GetProjectCacheAsync>d__26.MoveNext() in C:\Code\CoBRAGit\CoBRAMVC4Portal\Services\ProjectService.cs:line 352 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at CoBRAMVC4Portal.Areas.Tools.Controllers.API.RolesManagerAPIController.<CheckForPosition>d__11.MoveNext() in C:\Code\CoBRAGit\CoBRAMVC4Portal\Areas\Tools\Controllers\API\RolesManagerAPIController.cs:line 134

    I can't move past this and ANTS is basically unusable for me while this is happening.  I have the latest version of ANTS profiler on my box (10.1)
  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    Hi @vishnu4 ,

    So sorry to hear you're running into an issue as well!

    Based on the stack trace, I think your issue can likely be worked around by disabling Tools>Advanced Options>Profile with async awareness. (I wonder if this may have an effect for @frostfire as well.)

    As to why async profiling is causing this though, I'm not yet sure - if you have a supported license, can you please open a ticket with support@red-gate.com so that we can investigate further?

    Thank you!


    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • NiklasUhlinNiklasUhlin Posts: 0 New member
    I am also getting BadImageFormatException when profiling our ASP.NET 4.7.2 app:
    <div>[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]
    </div><div>&nbsp; &nbsp;_ANTS_Managed_Begin_Async() +0
    </div><div>&nbsp; &nbsp;Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) +91
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +134
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +257
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +117
    </div><div>&nbsp; &nbsp;System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +510
    </div><div>&nbsp; &nbsp;System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
    </div>

    I can confirm that disabling async awareness as suggested above made the error go away.
  • NiklasUhlinNiklasUhlin Posts: 0 New member
    I am also getting BadImageFormatException when profiling our ASP.NET 4.7.2 app:
    <div>[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]</div><div>&nbsp; &nbsp;_ANTS_Managed_Begin_Async() +0
    </div><div>&nbsp; &nbsp;Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) +91
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +134
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +257
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +117
    </div><div>&nbsp; &nbsp;System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +510
    </div><div>&nbsp; &nbsp;System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
    </div>

    I can confirm that disabling async awareness as suggested above made the error go away.
  • NiklasUhlinNiklasUhlin Posts: 0 New member
    I am also getting BadImageFormatException when profiling our ASP.NET 4.7.2 app:
    <div>[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]</div><div>&nbsp; &nbsp;_ANTS_Managed_Begin_Async() +0
    </div><div>&nbsp; &nbsp;Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) +91
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +134
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +257
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +117
    </div><div>&nbsp; &nbsp;System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +510
    </div><div>&nbsp; &nbsp;System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
    </div>

    I can confirm that disabling async awareness as suggested above made the error go away.
  • NiklasUhlinNiklasUhlin Posts: 0 New member
    I am also getting BadImageFormatException when profiling our ASP.NET 4.7.2 app:
    <div>[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]</div><div>&nbsp; &nbsp;_ANTS_Managed_Begin_Async() +0
    </div><div>&nbsp; &nbsp;Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) +91
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +134
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +257
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +117
    </div><div>&nbsp; &nbsp;System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +510
    </div><div>&nbsp; &nbsp;System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
    </div>

    I can confirm that disabling async awareness as suggested above made the error go away.
  • NiklasUhlinNiklasUhlin Posts: 0 New member
    I am also getting BadImageFormatException when profiling our ASP.NET 4.7.2 app:
    <div>[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]
    </div><div>&nbsp; &nbsp;_ANTS_Managed_Begin_Async() +0
    </div><div>&nbsp; &nbsp;Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) +91
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +134
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +257
    </div><div>&nbsp; &nbsp;System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
    </div><div>&nbsp; &nbsp;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +117
    </div><div>&nbsp; &nbsp;System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +510
    </div><div>&nbsp; &nbsp;System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +40
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +155
    </div><div>&nbsp; &nbsp;System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
    </div>

    I can confirm that disabling async awareness as suggested above made the error go away.
  • maazlmaazl Posts: 0 New member
    Same problem here: .NET 4.8, IIS 10, ANTS 10.3.0.1774

    When profiling the application it stops with System.BadImageFormatException roughly when the login screen should appear:
    Microsoft.AspNet.Identity.Owin
    
    Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B)
    bei _ANTS_Managed_Begin_Async() bei Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__7.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__12.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) bei System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() bei System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    To circumvent this bug I need either
    • downgrade the application pool worker to 32 bit - unfortunately our application tends to use more memory, so this likely causes OutOfMemoryException - or
    • disable "Profile with async awareness".
    Profiling of 64 bit web applications with async awareness does not work.
  • maazlmaazl Posts: 0 New member
    Same problem here: .NET 4.8, IIS 10, ANTS 10.3.0.1774

    When profiling the application it stops with System.BadImageFormatException roughly when the login screen should appear:
    Microsoft.AspNet.Identity.Owin
    
    Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B)
    bei _ANTS_Managed_Begin_Async() bei Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__7.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__12.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) bei System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() bei System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    To circumvent this bug I need either
    • downgrade the application pool worker to 32 bit - unfortunately our application tends to use more memory, so this likely causes OutOfMemoryException - or
    • disable "Profile with async awareness".
    Profiling of 64 bit web applications with async awareness does not work.
  • maazlmaazl Posts: 0 New member
    Same problem here: .NET 4.8, IIS 10, ANTS 10.3.0.1774

    When profiling the application it stops with System.BadImageFormatException roughly when the login screen should appear:
    Microsoft.AspNet.Identity.Owin
    
    Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B)
    bei _ANTS_Managed_Begin_Async() bei Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__7.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__12.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) bei System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() bei System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    To circumvent this bug I need either
    • downgrade the application pool worker to 32 bit - unfortunately our application tends to use more memory, so this likely causes OutOfMemoryException - or
    • disable "Profile with async awareness".
    Profiling of 64 bit web applications with async awareness does not work.
  • maazlmaazl Posts: 0 New member
    Same problem here: .NET 4.8, IIS 10, ANTS 10.3.0.1774

    When profiling the application it stops with System.BadImageFormatException roughly when the login screen should appear:
    Microsoft.AspNet.Identity.Owin
    
    Es wurde versucht, eine Datei mit einem falschen Format zu laden. (Ausnahme von HRESULT: 0x8007000B)
    bei _ANTS_Managed_Begin_Async() bei Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.Invoke(IOwinContext context) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__7.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__12.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) bei System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() bei System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    To circumvent this bug I need either
    • downgrade the application pool worker to 32 bit - unfortunately our application tends to use more memory, so this likely causes OutOfMemoryException - or
    • disable "Profile with async awareness".
    Profiling of 64 bit web applications with async awareness does not work.
Sign In or Register to comment.