{"record":{"id":"610dc61f40cfaa43","repo":"dotnet/wpf","slug":"argumentnullexception-path","errorCode":null,"errorMessage":"ArgumentNullException: path","messagePattern":"ArgumentNullException: path","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs","lineNumber":35,"sourceCode":"using 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;\n\n            int commonLength = PathInternal.GetCommonPathLength(relativeTo, path, ignoreCase: comparisonType == StringComparison.OrdinalIgnoreCase);\n\n            // If there is nothing in common they can't share the same root, return the \"to\" path as is.\n            if (commonLength == 0)\n                return path;","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs#L17-L53","documentation":"ICollection<KeyValuePair<K,V>>.CopyTo is unimplemented in this internal ConcurrentDictionary and always throws NotImplementedException. Bulk-copying the dictionary's items into an array via the collection interface is not supported.","triggerScenarios":"Calling CopyTo(array, index) on the ICollection<KeyValuePair<K,V>> interface; ToArray-style helpers or serialization code that snapshot the collection through ICollection<T>.CopyTo.","commonSituations":"Debug dumps and logging that snapshot the collection; serializers that consume ICollection<T> generically; code copying dictionary contents for thread-safe reads.","solutions":["Enumerate the dictionary with foreach over the IEnumerable implementations and fill your array manually.","Use Keys/Values collections and their copy semantics if only keys or values are needed.","Write a small extension method that snapshots via enumeration instead of CopyTo.","Report to WPF if you require the interface member."],"exampleFix":"// before\n((ICollection<KeyValuePair<K,V>>)dict).CopyTo(arr, 0); // throws\n// after\nint i = 0;\nforeach (var kv in dict) arr[i++] = kv;","handlingStrategy":"fallback","validationCode":"// Snapshot via enumeration instead of CopyTo:\nvar snapshot = System.Linq.Enumerable.ToArray(dict);","typeGuard":null,"tryCatchPattern":"try { coll.CopyTo(arr, 0); } catch (NotImplementedException) { int i = 0; foreach (var kv in dict) arr[i++] = kv; }","preventionTips":["Never call ICollection<T>.CopyTo on this dictionary","Snapshot with foreach/ToArray for thread-safe reads","Use Keys/Values collections when only one dimension is needed","Encapsulate snapshotting in an extension method"],"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"}