{"record":{"id":"15a110e0209b4f6b","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-innerresource","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'innerResource')","messagePattern":"Value cannot be null\\. \\(Parameter 'innerResource'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBEmulatorResource.cs","lineNumber":15,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nusing Aspire.Hosting.ApplicationModel;\n\nnamespace Aspire.Hosting.Azure;\n\n/// <summary>\n/// Wraps an <see cref=\"AzureCosmosDBResource\" /> in a type that exposes container extension methods.\n/// </summary>\n/// <param name=\"innerResource\">The inner resource used to store annotations.</param>\npublic class AzureCosmosDBEmulatorResource(AzureCosmosDBResource innerResource)\n    : ContainerResource(innerResource.Name)\n{\n    internal AzureCosmosDBResource InnerResource { get; } = innerResource ?? throw new ArgumentNullException(nameof(innerResource));\n\n    /// <inheritdoc />\n    public override ResourceAnnotationCollection Annotations => InnerResource.Annotations;\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBEmulatorResource.cs#L1-L20","documentation":"AzureCosmosDBEmulatorResource wraps an AzureCosmosDBResource in InnerResource and throws ArgumentNullException('innerResource') when given null. The wrapper gets its name and its entire annotation collection from the inner resource, so it cannot function without one.","triggerScenarios":"Calling new AzureCosmosDBEmulatorResource(null) directly, or invoking RunAsEmulator/RunAsClassicEmulator on a builder whose Resource is null.","commonSituations":"Manual instantiation in tests or custom tooling instead of using AddAzureCosmosDB(...).RunAsEmulator(); reflection-based construction passing default values.","solutions":["Use the fluent API: builder.AddAzureCosmosDB(\"cosmos\").RunAsEmulator(), which always supplies the inner resource.","If constructing manually, pass the AzureCosmosDBResource instance returned from AddAzureCosmosDB.","Guard the resource variable for null before creating the wrapper."],"exampleFix":"// before\nvar emulator = new AzureCosmosDBEmulatorResource(null!);\n// after\nvar cosmos = builder.AddAzureCosmosDB(\"cosmos\");\nvar emulator = new AzureCosmosDBEmulatorResource(cosmos.Resource);","handlingStrategy":"validation","validationCode":"if (innerResource is null) throw new InvalidOperationException(\"Emulator wrapper requires a non-null AzureCosmosDBResource.\");","typeGuard":"static bool IsWrapped(Builder b) => b.Resource is AzureCosmosDBResource;","tryCatchPattern":"try { var emulator = new AzureCosmosDBEmulatorResource(cosmos.Resource); } catch (ArgumentNullException ex) when (ex.ParamName == \"innerResource\") { /* create resource via AddAzureCosmosDB first */ }","preventionTips":["Prefer AddAzureCosmosDB(...).RunAsEmulator() over manual construction.","Never pass a possibly-null resource into the wrapper.","In tests, build the resource via the extension API first."],"tags":["cosmosdb","emulator","null-argument"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}