diff --git a/src/CommandLine/CommandLine.csproj b/src/CommandLine/CommandLine.csproj
index b5bdb6ff..7b791726 100644
--- a/src/CommandLine/CommandLine.csproj
+++ b/src/CommandLine/CommandLine.csproj
@@ -84,6 +84,7 @@
+
diff --git a/src/CommandLine/Core/TokenPartitioner.cs b/src/CommandLine/Core/TokenPartitioner.cs
index 75919cc8..ebe6c0ca 100644
--- a/src/CommandLine/Core/TokenPartitioner.cs
+++ b/src/CommandLine/Core/TokenPartitioner.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using CommandLine.Infrastructure;
using CSharpx;
namespace CommandLine.Core
@@ -23,11 +24,11 @@ public static
var scalars = Scalar.Partition(tokenList, typeLookup).Memorize();
var sequences = Sequence.Partition(tokenList, typeLookup).Memorize();
var nonOptions = tokenList
- .Where(t => !switches.Contains(t))
- .Where(t => !scalars.Contains(t))
- .Where(t => !sequences.Contains(t)).Memorize();
+ .Where(t => !switches.Contains(t, ReferenceEqualityComparer.Default))
+ .Where(t => !scalars.Contains(t, ReferenceEqualityComparer.Default))
+ .Where(t => !sequences.Contains(t, ReferenceEqualityComparer.Default)).Memorize();
var values = nonOptions.Where(v => v.IsValue()).Memorize();
- var errors = nonOptions.Except(values).Memorize();
+ var errors = nonOptions.Except(values, (IEqualityComparer)ReferenceEqualityComparer.Default).Memorize();
return Tuple.Create(
KeyValuePairHelper.ForSwitch(switches)
diff --git a/src/CommandLine/Infrastructure/ReferenceEqualityComparer.cs b/src/CommandLine/Infrastructure/ReferenceEqualityComparer.cs
new file mode 100644
index 00000000..2f6f4c2c
--- /dev/null
+++ b/src/CommandLine/Infrastructure/ReferenceEqualityComparer.cs
@@ -0,0 +1,24 @@
+// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace CommandLine.Infrastructure
+{
+ internal sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer