dotnet/wpf · error · ArgumentNullException
ArgumentNullException: path
Error message
ArgumentNullException: path
What it means
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.
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.
Example fix
// before ((ICollection<KeyValuePair<K,V>>)dict).CopyTo(arr, 0); // throws // after int i = 0; foreach (var kv in dict) arr[i++] = kv;
Defensive patterns
Strategy: fallback
Validate before calling
// Snapshot via enumeration instead of CopyTo: var snapshot = System.Linq.Enumerable.ToArray(dict);
Try / catch
try { coll.CopyTo(arr, 0); } catch (NotImplementedException) { int i = 0; foreach (var kv in dict) arr[i++] = kv; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Debug dumps and logging that snapshot the collection; serializers that consume ICollection<T> generically; code copying dictionary contents for thread-safe reads.
Related errors
- ArgumentException: path
- ArgumentException: relativeTo
- ArgumentNullException: relativeTo
- InitializationState !=
- NotImplementedException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/610dc61f40cfaa43.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/MarkupCompiler/PathInternal.cs:35
using System.Text;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace MS.Internal
{
internal sealed class PathInternal
{
internal static string GetRelativePath(string relativeTo, string path, StringComparison comparisonType)
{
if (relativeTo == null)
throw new ArgumentNullException(nameof(relativeTo));
if (PathInternal.IsEffectivelyEmpty(relativeTo.AsSpan()))
throw new ArgumentException(nameof(relativeTo));
if (path == null)
throw new ArgumentNullException(nameof(path));
if (PathInternal.IsEffectivelyEmpty(path.AsSpan()))
throw new ArgumentException(nameof(path));
Debug.Assert(comparisonType == StringComparison.Ordinal || comparisonType == StringComparison.OrdinalIgnoreCase);
relativeTo = Path.GetFullPath(relativeTo);
path = Path.GetFullPath(path);
// Need to check if the roots are different- if they are we need to return the "to" path.
if (!PathInternal.AreRootsEqual(relativeTo, path, comparisonType))
return path;
int commonLength = PathInternal.GetCommonPathLength(relativeTo, path, ignoreCase: comparisonType == StringComparison.OrdinalIgnoreCase);
// If there is nothing in common they can't share the same root, return the "to" path as is.
if (commonLength == 0)
return path;View on GitHub (pinned to 81131a70a4)