dotnet/runtime

.Net Core 2.2 console application : System.Private.CoreLib System.ArgumentOutOfRangeException (FileSystemWatcher)

Open

#36 406 ouverte le 3 juin 2019

Voir sur GitHub
 (10 commentaires) (0 réactions) (1 assigné)C# (5 445 forks)batch import
area-Extensions-FileSystembughelp wantedos-windows

Métriques du dépôt

Stars
 (17 886 stars)
Métriques de merge PR
 (Merge moyen 12j 11h) (661 PRs mergées en 30 j)

Description

From @patrick-blanc on Thursday, May 16, 2019 1:29:06 PM

Getting unhandled exception from System.Private.CoreLib

System.ArgumentOutOfRangeException HResult=0x80131502 Message=startIndex cannot be larger than length of string. Parameter name: startIndex Source=System.Private.CoreLib StackTrace: at System.String.Substring(Int32 startIndex, Int32 length) at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.OnFileSystemEntryChange(String fullPath) at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.OnRenamed(Object sender, RenamedEventArgs e) at System.IO.FileSystemWatcher.NotifyRenameEventArgs(WatcherChangeTypes action, String name, String oldName) at System.IO.FileSystemWatcher.ParseEventBufferAndNotifyForEach(Byte[] buffer) at System.IO.FileSystemWatcher.ReadDirectoryChangesCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

My console application (running on windows machine) try to run "npm install" command in different task on different folders.

Sometimes, I get the exception sometimes not. I am not using any FileWatcher in my console application. So my question is why did I get this exception from .net core. Is a .net core console app using by default a file watcher ? Anyone to help me to get rid of that exception.

Here is information from dotnet --info


> .NET Core SDK (reflecting any global.json):
>  Version:   2.2.204
>  Commit:    8757db13ec
> 
> Runtime Environment:
>  OS Name:     Windows
>  OS Version:  10.0.17134
>  OS Platform: Windows
>  RID:         win10-x64
>  Base Path:   C:\Program Files\dotnet\sdk\2.2.204\
> 
> Host (useful for support):
>   Version: 2.2.5
>   Commit:  0a3c9209c0
> 
> .NET Core SDKs installed:
>   2.1.602 [C:\Program Files\dotnet\sdk]
>   2.1.604 [C:\Program Files\dotnet\sdk]
>   2.2.202 [C:\Program Files\dotnet\sdk]
>   2.2.204 [C:\Program Files\dotnet\sdk]
> 
> .NET Core runtimes installed:
>   Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
>   Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
>   Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
>   Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
>   Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
>   Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
>   Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
>   Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
>   Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
>   Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
>   Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
>   Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

I see a thread related to same exception on aspnetcore (1 year ago) : #https://github.com/aspnet/AspNetCore/issues/2536

it seems it has been fixed in release 2.0.1 of Microsoft.Extensions.FileProviders.Physical, as I am using .net core 2.2 I don't think it's related. As said before I am not creating any FileWatcher. My code is basically checking if directory exists (like node_modules) if not it run a process (cmd) and run the npm install.

Notice that I find strange that PhysicalFilesWatcher.OnRenamed is throwing an exception on System.String.Substring(Int32 startIndex, Int32 length) because OnRenamed does not use this method but is using System.String.Substring(Int32 startIndex)

Thanks for your help any hints would be greatly appreciated

Copied from original issue: dotnet/corefx#37707

Guide contributeur