Hot reload error: `System.AggregateException: One or more errors occurred. (Format of the executable (.exe) or library (.dll) is invalid.)`
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
I'm running my Aspire-based project with `dotnet watch run --project "./Ogma3.AppHost/Ogma3.AppHost.csproj"`. Hot reload works.
Eventually, though, it randomly throws the forementioned error after a file change, and from that point on it stops working completely. The application itself does not crash, it just doesn't hot reload anymore.
### Reproduction Steps
I tried recreating this issue with a simple project, but failed. It could very well be a function of complexity.
### Expected behavior
```
dotnet watch ⌚ File updated: F:\VS Projects\Ogma3\Ogma3\Pages\Index.cshtml
dotnet watch 🔥 [Ogma3.AppHost (net10.0)] Hot reload succeeded.
```
### Actual behavior
```
dotnet watch ⌚ File updated: F:\VS Projects\Ogma3\Ogma3\Pages\Index.cshtml
dotnet watch 🔥 [Ogma3.AppHost (net10.0)] Hot reload succeeded.
dotnet watch ⚠ [Ogma3 (net10.0)] Exception from 'Microsoft.AspNetCore.Mvc.HotReload.HotReloadService.UpdateApplication': System.AggregateException: One or more errors occurred. (Format of the executable (.exe) or library (.dll) is invalid.)
---> System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
at System.Reflection.Metadata.RuntimeTypeMetadataUpdateHandler.IsMetadataUpdateDeleted(RuntimeModule module, Int32 memberToken)
at System.RuntimeType.RuntimeTypeCache.MemberInfoCache`1.PopulateConstructors(Filter filter)
at System.RuntimeType.RuntimeTypeCache.MemberInfoCache`1.GetListByName(String name, Span`1 utf8Name, MemberListType listType, CacheType cacheType)
at System.RuntimeType.RuntimeTypeCache.MemberInfoCache`1.Populate(String name, MemberListType listType, CacheType cacheType)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultBindingMetadataProvider.CreateBindingMetadata(BindingMetadataProviderContext context)
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultCompositeMetadataDetailsProvider.CreateBindingMetadata(BindingMetadataProviderContext context)
at Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo.TryApplyBindingInfo(ModelMetadata modelMetadata)
at Microsoft.AspNetCore.Mvc.ModelBinding.BindingInfo.GetBindingInfo(IEnumerable`1 attributes, ModelMetadata modelMetadata)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.CompiledPageActionDescriptorFactory.CreateCompiledDescriptor(PageActionDescriptor actionDescriptor, CompiledViewDescriptor viewDescriptor)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.CompiledPageActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration`1.OnChangeTokenFired()
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
--- End of inner exception stack trace ---
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
at Microsoft.DotNet.HotReload.MetadataUpdateHandlerInvoker.<>c__DisplayClass19_0.b__6(Type[] types)
dotnet watch 🔥 [Ogma3 (net10.0)] Hot reload succeeded.
```
### Regression?
_No response_
### Known Workarounds
_No response_
### Configuration
* .NET 10
* Win 11
* x64
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.