简体   繁体   English

Azure 应用服务 500 错误:值不能是 null。 (参数'containerId')

[英]Azure App Service 500 error: Value cannot be null. (Parameter 'containerId')

I have an app service which has been running ok, I added blob storage & got that working locally.我有一个运行正常的应用服务,我添加了 blob 存储并使其在本地工作。

When I published the app it is no longer running.当我发布应用程序时,它不再运行。 It's been difficult to track down logs but I found this in 'Availability & Performance' in Azure Portal.很难追踪日志,但我在 Azure 门户的“可用性和性能”中发现了这一点。

I thought maybe there was something wrong with the config but the appsettings file seems to have published ok.我认为配置可能有问题,但 appsettings 文件似乎已发布正常。 Been stuck with this issue for a while as I'm quite new to Azure由于我对 Azure 很陌生,因此一直被这个问题困扰了一段时间

Description: The process was terminated due to an unhandled exception.说明:进程因未处理的异常而终止。 Exception Info: System.ArgumentNullException: Value cannot be null.异常信息:System.ArgumentNullException:值不能是 null。 (Parameter 'containerId') at Microsoft.Azure.Cosmos.CosmosClient.GetContainer(String databaseId, String containerId) at xxx .Services.MemberService..ctor(CosmosClient dbClient, String databaseName, String containerName) in C: xxx \source\repos* xxx *\Services\MemberService.cs:line 16 at xxx .Startup.InitializeCosmosMemberClientInstanceAsync(IConfigurationSection configurationSection) in C: xxx \source\repos* xxx *\Startup.cs:line 99 at xxx .Startup.ConfigureServices(IServiceCollection services) in C: xxx \source\repos* xxx *\Startup.cs:line 54 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[ (参数 'containerId')在 Microsoft.Azure.Cosmos.CosmosClient.GetContainer(String databaseId, String containerId) at xxx .Services.MemberService..ctor(CosmosClient dbClient, String databaseName, String containerName) in Z0D61F8370CAD1\ D412F80ZB84 \ * xxx *\Services\MemberService.cs: 第 16 行在xxx .Startup.InitializeCosmosMemberClientInstanceAsync(IConfigurationSection configurationSection) in C: xxx \source\repos* xxx *\Startup.cs:line 99 at xxx .Startup.ConfigureServices(IServiceCollection services) in C: xxx \source\repos* xxx *\Startup.cs:line 54 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke (对象 obj,BindingFlags invokeAttr,Binder binder,Object[ ] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__0(HostBuilderContext context, IServiceCollection services) at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() at Microsoft.Extensions.Hosting.HostBuilder.Build() at xxx .Program.Main(String[] args) in Z0D61F8370CAD1D412 ] 参数,CultureInfo 文化)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(对象实例,IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder。<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection) 在 Microsoft.AspNetCore.Hosting。 Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(类型 startupType,HostBuilderContext 上下文,IServiceCollection 服务,Z497031794414A552435F90151AC3B54ZB 中的 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection 服务) ) 在 Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__0(HostBuilderContext context, IServiceCollection services) 在 Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() 在 Microsoft.Extensions.Hosting.HostBuilder.Build() 在xxx .Program Z0D61F8370CAD1D412 中的 .Main(String[] args) F80B84D143E1257Z: xxx \source\repos* xxx *\Program.cs:line 16 F80B84D143E1257Z: xxx \source\repos* xxx *\Program.cs: 第 16 行

The Service is initialized in startup like so服务在启动时初始化,如下所示

        private static async Task<FilesService> InitializeCosmosFilesClientInstanceAsync(IConfigurationSection configurationSection)
    {
        string databaseName = configurationSection.GetSection("DatabaseName").Value;
        string memberFilesContainer = configurationSection.GetSection("MemberFilesContainer").Value;

        string account = configurationSection.GetSection("Account").Value;
        string key = configurationSection.GetSection("Key").Value;

        Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
        FilesService filesService = new FilesService(client, databaseName, memberFilesContainer);
        Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);
        await database.Database.CreateContainerIfNotExistsAsync(memberFilesContainer, "/id");

        return filesService;
    }

And called in the ConfigureServices method like so并像这样在 ConfigureServices 方法中调用

                services.AddSingleton<IFilesService>(InitializeCosmosFilesClientInstanceAsync(Configuration.GetSection("CosmosDbProd")).GetAwaiter().GetResult());

The appsetting.json file has the following set appsetting.json文件有如下设置

"CosmosDbProd": {
"Account": "xxx",
"Key": "xxx",
"DatabaseName": "xxx-db-prod",
"ContainerName": "Member",
"MemberFilesContainer": "MemberFiles"

}, },

I found the bug.我发现了这个错误。 In appsettings.json I had a section named 'ContainerName' which should have been 'MemberContainer'.在 appsettings.json 我有一个名为“ContainerName”的部分,它应该是“MemberContainer”。 I think writing out in here helped me get to the answer我认为在这里写出来帮助我找到答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure函数失败,并且“值”不能为null的无用错误消息。 参数名称:值 - Azure function fails with unhelpful error message of Value cannot be null. Parameter name: value Azure 函数:值不能为空。 参数名称:来源 - Azure function: Value cannot be null. Parameter name: source PDF Checkbox Error:值不能为null。 参数名称:值 - PDF Checkbox Error : Value cannot be null. Parameter name: value WPF 设计器错误值不能为空。 参数名称:模式 - WPF designer error Value cannot be null. Parameter name: pattern 值不能是 null。 (参数“源”)Blazor 中的顶点图表错误 - Value cannot be null. (Parameter 'source') Error in Apex Chart in Blazor 如何调试这个“value cannot be null. Parameter name: password”错误? - How to debug this "value cannot be null. Parameter name: password" error? Watin错误:值不能为null。 参数名称:domContainer - Watin error: Value cannot be null. Parameter name: domContainer 反序列化错误:值不能为null。 参数名称:类型 - Deserialization error: value cannot be null. Parameter name: type 值不能为空。 错误 - Value cannot be null. Error 值不能为空。 参数名称:extent - Value cannot be null. Parameter name: extent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM