Repository navigation
Open
Labels
Description
Describe the bug
I keep getting this error while working with dotnet watch on a ASP.NET Core project
An unhandled exception occurred while processing the request.
ArgumentOutOfRangeException: Token 2007ffe is not valid in the scope of module System.ModuleHandle. (Parameter 'typeToken')
System.ModuleHandle.ResolveTypeHandle(int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
ArgumentOutOfRangeException: Token 2007ffe is not valid in the scope of module System.ModuleHandle. (Parameter 'typeToken')
System.ModuleHandle.ResolveTypeHandle(int typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, ref MetadataImport scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable, ref ListBuilder<object> derivedAttributes, out RuntimeType attributeType, out IRuntimeMethodInfo ctorWithParameters, out bool isVarArg)
System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, int decoratedMetadataToken, RuntimeType attributeFilterType, int attributeCtorToken, bool mustBeInheritable)
System.Linq.Enumerable+ArrayWhereSelectIterator<TSource, TResult>.ToArray(ReadOnlySpan<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> selector)
System.Linq.Enumerable+ArrayWhereSelectIterator<TSource, TResult>.ToArray()
Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator..ctor(Type pageType, Type declaredModelType, IModelMetadataProvider metadataProvider, PropertyValueAccessors propertyValueAccessors)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageFactoryProvider.CreatePageFactory(CompiledPageActionDescriptor actionDescriptor)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerCache.CreateCacheEntry(CompiledPageActionDescriptor compiledActionDescriptor, FilterItem[] cachedFilters)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerCache.GetCachedResult(ActionContext actionContext)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageRequestDelegateFactory+<>c__DisplayClass13_0.<CreateRequestDelegate>b__0(HttpContext context)
Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
EduConvert.Helpers.CurrentUserMiddleware.InvokeAsync(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
To Reproduce
I am not sure how to reproduce it. I've never seen this error before until I upgraded to SDK 9.0.201
I simply trigger dotnet watch to reload a project by modifying any of its files (both cshtml or cs) and I get this error.
CTRL+R fixes it but kills the dev experience.
Further technical details
$ dotnet --info
.NET SDK:
Version: 9.0.201
Commit: 071aaccdc2
Workload version: 9.0.200-manifests.21502d11
MSBuild version: 17.13.13+1c2026462
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.201\
.NET workloads installed:
[aspire]
Installation Source: VS 17.11.35222.181
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.3
Architecture: x64
Commit: 831d23e561
.NET SDKs installed:
6.0.428 [C:\Program Files\dotnet\sdk]
8.0.310 [C:\Program Files\dotnet\sdk]
8.0.400 [C:\Program Files\dotnet\sdk]
8.0.407 [C:\Program Files\dotnet\sdk]
9.0.201 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
C:\Users\rg1844\Development\EduConvert\EduConvert\global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
$ cat .\global.json
{
"sdk": {
"version": "9.0.100",
"allowPrerelease": false,
"rollForward": "latestMinor"
}
}
Reacted by Peter Kneale, Kieran Benton, Rui Mourato, Garry Pshonik, Krzysztof Jeske and nglessner-msfw
Activity
KalleOlaviNiemitalo commentedon Apr 6, 2025
Although
dotnet watchshouldn't cause the exception in the first place, the exception message also looks suboptimal.Instead of "System.ModuleHandle", it would be more useful to show the name of the module.
The exception message is formatted here: https://github.com/dotnet/runtime/blob/831d23e56149cd59c40fc00c7feb7c5334bd19c4/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs#L1324-L1331
It uses
new ModuleHandle(module)as a format argument, but ModuleHandle is a struct that does not override ToString.That is not a regression, as .NET Framework has similar code here: https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/runtimehandles.cs#L1916-L1918
System.Reflection.Module, the base class of RuntimeModule, does override ToString and it is used as a format argument elsewhere, so I think this format call should just use
module.tmat commentedon Jun 21, 2025
Thanks for report. Could you please provide repro steps?
Alternatively, please set
Microsoft_CodeAnalysis_EditAndContinue_LogDirenv variable to a directory path, rundotnet-watch --verboseand share the content of the directory and the console output.Kralizek commentedon Jun 24, 2025
I don't have a repro.
I'm working on an ASP.NET Core solution. I use
dotnet watch runand since the change of SDK version, I randomly get the error shown in the opening thread.It happens when I change the Razor pages code behind class more often than when changing the actual razor file.
Only way to restore is stopping and restarting the watcher.
tmat commentedon Jun 24, 2025
If you remember to set
Microsoft_CodeAnalysis_EditAndContinue_LogDirbefore running dotnet watch you could work as usual and when you encounter an issue you could share the latest logs from the directory.Kralizek commentedon Jun 24, 2025
I hope I can get stuff to happen and give you the logs.
[release/10.0] Add property and event parent lookup table entries in …