{"record":{"id":"6fbfa5199c95cf8d","repo":"microsoft/aspire","slug":"innerresource","errorCode":null,"errorMessage":"innerResource","messagePattern":"innerResource","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusEmulatorResource.cs","lineNumber":19,"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=\"AzureServiceBusResource\" /> in a type that exposes container extension methods.\n/// </summary>\n/// <param name=\"innerResource\">The inner resource used to store annotations.</param>\npublic class AzureServiceBusEmulatorResource(AzureServiceBusResource innerResource) : ContainerResource(innerResource.Name), IResource\n{\n    // The path to the emulator configuration files in the container.\n    internal const string EmulatorConfigFilesPath = \"/ServiceBus_Emulator/ConfigFiles\";\n    // The path to the emulator configuration file in the container.\n    internal const string EmulatorConfigJsonFile = \"Config.json\";\n\n    private readonly AzureServiceBusResource _innerResource = innerResource ?? throw new ArgumentNullException(nameof(innerResource));\n\n    /// <inheritdoc />\n    public override ResourceAnnotationCollection Annotations => _innerResource.Annotations;\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusEmulatorResource.cs#L1-L24","documentation":"The AzureServiceBusEmulatorResource constructor stores the real (provisioned) AzureServiceBusResource it wraps and throws ArgumentNullException when the innerResource argument is null. The emulator resource delegates Annotations to the inner resource, so null is invalid by construction.","triggerScenarios":"Calling new AzureServiceBusEmulatorResource(null) — directly or via RunAsEmulator internals — instead of passing the AzureServiceBusResource returned by AddAzureServiceBus.","commonSituations":"Hand-constructing the emulator resource in tests or custom code and passing a null builder resource; reflection-based instantiation with missing arguments; refactor dropped the argument.","solutions":["Always construct via builder.RunAsEmulator() rather than new AzureServiceBusEmulatorResource(...) directly.","If constructing manually, pass the non-null AzureServiceBusResource from the resource builder (builder.Resource).","Guard with ArgumentNullException.ThrowIfNull in your own factory before calling the constructor."],"exampleFix":"// before\nvar emulator = new AzureServiceBusEmulatorResource(null!);\n// after\nvar emulator = new AzureServiceBusEmulatorResource(builder.Resource);","handlingStrategy":"validation","validationCode":"if (innerResource is null)\n{\n    throw new ArgumentNullException(nameof(innerResource), \"Provide the AzureServiceBusResource to wrap.\");\n}\nvar emulator = new AzureServiceBusEmulatorResource(innerResource);","typeGuard":"static AzureServiceBusResource? TryGetInnerResource(IResource? r) => r as AzureServiceBusResource;","tryCatchPattern":null,"preventionTips":["Prefer builder.RunAsEmulator() over direct construction of AzureServiceBusEmulatorResource.","Pass builder.Resource (never null) when constructing manually.","Null-check resources in test factories before constructing emulator resources."],"tags":["azure","servicebus","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-21T04:17:39.646Z"}