{"record":{"id":"bbf70cbb5ad110de","repo":"dotnet/wpf","slug":"argumentnullexception-relativeto","errorCode":null,"errorMessage":"ArgumentNullException: relativeTo","messagePattern":"ArgumentNullException: relativeTo","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs","lineNumber":29,"sourceCode":"//   current platform (StringComparison.OrdinalIgnoreCase for Windows.)\n//\n//---------------------------------------------------------------------------\n\nusing System;\nusing System.IO;\nusing System.Text;\n\nusing System.Diagnostics;\nusing System.Runtime.CompilerServices;\n\nnamespace MS.Internal\n{\n    internal sealed class PathInternal \n    {\n        internal static string GetRelativePath(string relativeTo, string path, StringComparison comparisonType)\n        {\n            if (relativeTo == null)\n                throw new ArgumentNullException(nameof(relativeTo));\n\n            if (PathInternal.IsEffectivelyEmpty(relativeTo.AsSpan()))\n                throw new ArgumentException(nameof(relativeTo));\n\n            if (path == null)\n                throw new ArgumentNullException(nameof(path));\n\n            if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))\n                throw new ArgumentException(nameof(path));\n\n            Debug.Assert(comparisonType == StringComparison.Ordinal || comparisonType == StringComparison.OrdinalIgnoreCase);\n\n            relativeTo = Path.GetFullPath(relativeTo);\n            path = Path.GetFullPath(path);\n\n            // Need to check if the roots are different- if they are we need to return the \"to\" path.\n            if (!PathInternal.AreRootsEqual(relativeTo, path, comparisonType))\n                return path;","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs#L11-L47","documentation":"The ICollection<KeyValuePair<K,V>>.Add member of this internal ConcurrentDictionary is explicitly unimplemented and always throws NotImplementedException. Mutation of the collection is expected to go through the indexer setter or Add(K,V)-style members instead of the interface method.","triggerScenarios":"Calling Add(new KeyValuePair<K,V>(k,v)) directly, or passing the dictionary to code that uses ICollection<T>.Add (e.g. collection initializers like new ConcurrentDictionary<K,V> { { k, v } }).","commonSituations":"Collection-initializer syntax on the dictionary; generic algorithms written against ICollection<T>; LINQ-style bulk-insert helpers that call Add on the interface.","solutions":["Use the indexer assignment dict[key] = value instead of ICollection<T>.Add.","Replace collection-initializer syntax ({ { k, v } }) with explicit indexer assignments.","If a generic ICollection<T> consumer must work, adapt it to use the indexer via a small wrapper.","Report to WPF if you depend on the interface contract; the member is a stub by design."],"exampleFix":"// before\nvar d = new ConcurrentDictionary<string, object> { { \"k\", v } }; // NotImplementedException\n// after\nvar d = new ConcurrentDictionary<string, object>();\nd[\"k\"] = v;","handlingStrategy":"validation","validationCode":"// Avoid ICollection<T>.Add entirely; assert before use:\nif (dict is ICollection<KeyValuePair<K,V>>) throw new NotSupportedException(\"Use indexer assignment, Add is a NotImplementedException stub\");","typeGuard":null,"tryCatchPattern":"try { coll.Add(pair); } catch (NotImplementedException) { dict[pair.Key] = pair.Value; }","preventionTips":["Use dict[key] = value instead of interface Add","Avoid collection-initializer syntax on this type","When writing generic ICollection<T> code, special-case dictionaries","Read the class source before relying on interface members of internal collections"],"tags":["not-implemented","dictionary","wpf","xaml"],"backgroundTag":"method-not-implemented","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}