aspnet / aspnet-docker

[Archived] ASP.NET Core Docker images for 1.x. Go to https://github.com/dotnet/dotnet-docker for 2.1 and up.
https://asp.net
719 stars 171 forks source link

Unhandled Exception: System.ArgumentException: Illegal characters in path. #288

Closed liugt34 closed 7 years ago

liugt34 commented 7 years ago

CentOS7.0 .NET CORE 1.1.2 I have met this problem, i did'not find anyway to solve it , i have no idea about it

Unhandled Exception: System.ArgumentException: Illegal characters in path.
Parameter name: path
   at System.IO.PathInternal.CheckInvalidPathChars(String path)
   at System.IO.Path.Combine(String path1, String path2)
   at System.IO.UnixFileSystem.FileSystemEnumerable`1.<Enumerate>d__11.MoveNext()
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance..ctor(FileSystemWatcher watcher, SafeFileHandle inotifyHandle, String directoryPath, Boolean includeSubdir                                         ectories, NotifyEvents notifyFilters, CancellationToken cancellationToken)
   at System.IO.FileSystemWatcher.StartRaisingEvents()
   at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()
   at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__0_0()
   at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Web.Startup..ctor(IHostingEnvironment env) in E:\012.NET项目组\DOTNET国旅\项目\春之翼官网\代码\Spring_CZY\Web\Startup.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.Internal.StartupLoader.LoadMethods(IServiceProvider hostingServiceProvider, Type startupType, String environmentName)
   at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass1_0.<UseStartup>b__1(IServiceProvider sp)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Web.Program.Main(String[] args) in E:\012.NET项目组\DOTNET国旅\项目\春之翼官网\代码\Spring_CZY\Web\Program.cs:line 19
liugt34 commented 7 years ago

My Dockerfile

FROM microsoft/aspnetcore:1.1.2 WORKDIR /app EXPOSE 80 COPY . . ENTRYPOINT ["dotnet", "Spring.Web.dll"]

then i use the command $ docker build -t springapp . $ docker run -d -p 8000:80 springapp

the container's status is Exited(139) 20s ago

natemcmaster commented 7 years ago

@liugt34 can you share enough code to reproduce this bug? It does not appear to be related to Docker specifically, but it is hard to tell without a way to reproduce your error.

liugt34 commented 7 years ago

@natemcmaster thank you for reply, but it worked well on windows it is the program.cs `

var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .Build();
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseConfiguration(config)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                //.UseUrls("http://*:8080")
                .UseApplicationInsights()
                .Build();

            host.Run(); 
`

it is the Startup.cs `

var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();
            Configuration = builder.Build();

when i comment the AddJsonFile(xxx) method , it can run on linux

appsettings.json

{
    "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
            "Default": "Warning"
        }
    },
    "Admin": {
        "UserName": "008759,008758",
        "Password": "123456,12345456789"
    },
    "Data": "LineZero",
    "ConnectionStrings": {
        "DefaultConnection": "Server=10.xxx.xxx.xx0;Port=3xx8;DataBase=czygw_db;uid=springweb;password=11111;SslMode=None"
    }
}
natemcmaster commented 7 years ago

when i comment the AddJsonFile(xxx) method , it can run on linux

Which AddJsonFile call? Or do you have to remove both?

(1) > .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) (2) > .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)

I am assuming it's only (1). The stack trace shows that the error came from instantiating the file watcher. I'm guessing this means that there is a directory in your project that has illegal characters in the file or directory name. By default, the file watcher scans all subdirectories (see https://github.com/aspnet/FileSystem/blob/rel/1.1.1/src/Microsoft.Extensions.FileProviders.Physical/PhysicalFilesWatcher.cs#L52). This would explain the stack trace:

   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory parent, String directoryName)
   at System.IO.FileSystemWatcher.RunningInstance..ctor(FileSystemWatcher watcher, SafeFileHandle inotifyHandle, String directoryPath, Boolean includeSubdir                                         ectories, NotifyEvents notifyFilters, CancellationToken cancellationToken)
   at System.IO.FileSystemWatcher.StartRaisingEvents()

Try setting reloadOnChange: false to workaround it.

liugt34 commented 7 years ago

@natemcmaster thank you very much , i found the problem some images in wwwroot has name with chinese word, so linux can't resolve it this issue cost me more than 3 days, thank u again