{"record":{"id":"bf1b3155ad0d8a56","repo":"dotnet/wpf","slug":"argumentexception-relativeto","errorCode":null,"errorMessage":"ArgumentException: relativeTo","messagePattern":"ArgumentException: relativeTo","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs","lineNumber":32,"sourceCode":"\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;\n\n            int commonLength = PathInternal.GetCommonPathLength(relativeTo, path, ignoreCase: comparisonType == StringComparison.OrdinalIgnoreCase);\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs#L14-L50","documentation":"ICollection<KeyValuePair<K,V>>.Contains on this internal ConcurrentDictionary is a stub that always throws NotImplementedException. Membership testing of a KeyValuePair against the collection interface was never implemented; use key-based lookups instead.","triggerScenarios":"Calling Contains(pair) on the ICollection<KeyValuePair<K,V>> interface, or LINQ/Contains-extension paths that bind to the interface member.","commonSituations":"Generic code checking whether a dictionary 'contains' a pair; test helpers asserting collection membership; code ported from Dictionary<K,V> where Contains worked via other members.","solutions":["Test membership with ContainsKey(key) and then compare the value from the indexer if a pair comparison is needed.","Replace interface-level Contains calls with key-based checks.","Wrap the dictionary in your own adapter implementing Contains via ContainsKey + value equality.","File a WPF issue if the interface contract is required for your scenario."],"exampleFix":"// before\nbool has = ((ICollection<KeyValuePair<K,V>>)dict).Contains(pair); // throws\n// after\nbool has = dict.ContainsKey(pair.Key) && EqualityComparer<V>.Default.Equals(dict[pair.Key], pair.Value);","handlingStrategy":"validation","validationCode":"bool contains = dict.ContainsKey(pair.Key) && EqualityComparer<V>.Default.Equals(dict[pair.Key], pair.Value);","typeGuard":null,"tryCatchPattern":"try { coll.Contains(pair); } catch (NotImplementedException) { /* use ContainsKey-based check */ }","preventionTips":["Do membership tests with ContainsKey plus value comparison","Avoid LINQ methods that dispatch to ICollection<T>.Contains on this type","Keep pair-comparison logic at the call site","Pin to key-based APIs only"],"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"}