{"record":{"id":"84e513a06a5f8b98","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-sourcepath","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'sourcePath')","messagePattern":"Value cannot be null\\. \\(Parameter 'sourcePath'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.EventHubs/ConfigFileAnnotation.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.EventHubs;\n\n/// <summary>\n/// Represents an annotation for a custom config file source.\n/// </summary>\ninternal sealed class ConfigFileAnnotation : IResourceAnnotation\n{\n    public ConfigFileAnnotation(string sourcePath)\n    {\n        SourcePath = sourcePath ?? throw new ArgumentNullException(nameof(sourcePath));\n    }\n\n    public string SourcePath { get; }\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.EventHubs/ConfigFileAnnotation.cs#L1-L20","documentation":"ConfigFileAnnotation records the source path of a custom emulator config file and rejects a null path in its constructor. A null SourcePath would produce an invalid container file mount later, so it fails fast at annotation creation.","triggerScenarios":"Calling the ConfigFileAnnotation constructor with a null string — typically via the RunAsEmulator WithConfigFile extension where the config file path argument is null.","commonSituations":"Passing a nullable path variable that was never resolved (config lookup failed); test code constructing the annotation directly; refactoring that changed the path to nullable.","solutions":["Ensure the path passed to WithConfigFile/ConfigFileAnnotation is a resolved, non-null string","Validate that the config file exists before annotating the resource","Fix the upstream code that produced a null path (e.g. failed configuration lookup)"],"exampleFix":"// before\nstring? configPath = ResolveConfigPath();\nemulator.WithConfigFile(configPath!); // NRE risk / ArgumentNullException here\n// after\nvar configPath = ResolveConfigPath();\nif (configPath is not null && File.Exists(configPath))\n{\n    emulator.WithConfigFile(configPath);\n}","handlingStrategy":"type-guard","validationCode":"if (string.IsNullOrEmpty(configFilePath)) throw new ArgumentException(\"Config file path must be provided.\");","typeGuard":"static bool IsValidConfigPath(string? path) => !string.IsNullOrWhiteSpace(path) && File.Exists(path);","tryCatchPattern":"try { emulator.WithConfigFile(configPath); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"sourcePath\") { /* resolve the config path first */ }","preventionTips":["Check File.Exists before annotating","Avoid nullable path variables reaching extension calls","Fail fast on missing config lookups at startup"],"tags":["eventhubs","emulator","null-argument","annotation"],"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"}