File-based configuration of App Service throws System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/site/wwwroot/auth.json'.

skedi 1 Reputation point
2020-12-17T13:48:35.24+00:00

Hi,

while trying to configure an openid identity provider like it was described in this article ( https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-openid-connect ) and the follow up article ( https://learn.microsoft.com/en-us/azure/app-service/app-service-authentication-how-to#config-file ) via file-based configuration the easyauth middleware throws the exception mentioned in the title, with this stacktrace:

2020-12-17T13:14:47.757051954Z [41m [1m [37mcrit [39m [22m [49m: Microsoft.AspNetCore.Hosting.Diagnostics[6]
2020-12-17T13:14:47.757077454Z Application startup exception
2020-12-17T13:14:47.757083154Z System.TypeInitializationException: The type initializer for 'Microsoft.Azure.AppService.Middleware.ModuleUtils' threw an exception.
2020-12-17T13:14:47.757086854Z ---> System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/site/wwwroot/auth.json'.
2020-12-17T13:14:47.757090054Z at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
2020-12-17T13:14:47.757092454Z at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
2020-12-17T13:14:47.757094854Z at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
2020-12-17T13:14:47.757097254Z at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
2020-12-17T13:14:47.757099754Z at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
2020-12-17T13:14:47.757101954Z at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks)
2020-12-17T13:14:47.757104554Z at System.IO.File.InternalReadAllText(String path, Encoding encoding)
2020-12-17T13:14:47.757106754Z at System.IO.File.ReadAllText(String path)
2020-12-17T13:14:47.757109254Z at Microsoft.Azure.AppService.Middleware.Modules.DefaultAppServiceConfigurationHelper.GetJsonConfiguration() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/DefaultAppServiceConfigurationHelper.cs:line 61
2020-12-17T13:14:47.757112754Z at Microsoft.Azure.AppService.Middleware.Modules.ConfigFactory.GenerateMiddlewareModuleConfig(ConfigurationHelper configHelper) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/ConfigFactory.cs:line 80
2020-12-17T13:14:47.757115354Z at Microsoft.Azure.AppService.Middleware.Modules.ConfigFactory.GetCorsConfig(ConfigurationHelper configHelper, Boolean forceRegeneration) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/ConfigFactory.cs:line 43
2020-12-17T13:14:47.757117854Z at Microsoft.Azure.AppService.Cors.CorsModule.SetConfig(ConfigFactory configFactory, Boolean emitTelemetry) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/Cors/CorsModule.cs:line 55
2020-12-17T13:14:47.757120854Z at Microsoft.Azure.AppService.Cors.CorsModule..ctor(ConfigFactory configFactory) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/Cors/CorsModule.cs:line 25
2020-12-17T13:14:47.757123354Z at Microsoft.Azure.AppService.Middleware.ModuleUtils..cctor() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/ModuleUtils.cs:line 49
2020-12-17T13:14:47.757125654Z --- End of inner exception stack trace ---
2020-12-17T13:14:47.757155854Z at Microsoft.Azure.AppService.Middleware.ModuleConfig.ForceLoadConfig() in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/ModuleConfig.cs:line 103
2020-12-17T13:14:47.757160754Z at Microsoft.Azure.AppService.Middleware.ModuleConfig.EnsureConfigLoaded(HttpContextBase context, Boolean enableLegacyTracing, IConfiguration config) in /EasyAuth/Microsoft.Azure.AppService.Middleware.Modules/ModuleConfig.cs:line 90
2020-12-17T13:14:47.757163855Z at Microsoft.Azure.AppService.Middleware.AspNetCoreMiddleware.AppServiceMiddleware..ctor(RequestDelegate next, String configFileLocation, CryptoHelper cryptoHelper) in /EasyAuth/Microsoft.Azure.AppService.Middleware.NetCore/AppServiceMiddleware.cs:line 30
2020-12-17T13:14:47.757166655Z at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
2020-12-17T13:14:47.757169155Z at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2020-12-17T13:14:47.757171655Z at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
2020-12-17T13:14:47.757173955Z at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
2020-12-17T13:14:47.757176455Z at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,959 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 26,146 Reputation points Microsoft Employee
    2020-12-17T17:35:30.647+00:00

    Hi @skedi ,

    Verify that authFilePath matches the path you placed your config file under Microsoft.Web/sites/<siteName>/config/authsettings in https://resources.azure.com. In the exception, it shows it's looking for your file-based config at '/home/config/auth.json'.

    Regards,
    Ryan