When developing .NET Core 2.0 applications, I'm having issues with conditional breakpoints, watch evaluations, and immediate window evaluations. I'm receiving the following error:
modifiers.GroupBy(c => c.Modifier.Group).ToList()
threw an exception of type 'System.ArgumentException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147024809
HelpLink: null
InnerException: null
Message: "Cannot evaluate a security function."
ParamName: null
Source: null
StackTrace: null
TargetSite: null
What may cause this issue? Is there a workaround? This works just fine in a .NET Framework 4.x application.
Edit: Adding code sample
Using the following class:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Group { get; set; }
}
In a normal console application, targeting .NET Core 2.0:
static void Main(string[] args)
{
var people = new List<Person>
{
new Person { Age = 17, Name = "Person A", Group = "Group A" },
new Person { Age = 20, Name = "Person B", Group = "Group A" },
new Person { Age = 23, Name = "Person C", Group = "Group A" },
new Person { Age = 17, Name = "Person D", Group = "Group B" },
new Person { Age = 25, Name = "Person E", Group = "Group B" },
new Person { Age = 40, Name = "Person F", Group = "Group B" },
};
// Make sure that System.Linq gets loaded
people.Where(c => c.Name == "Person A").First();
}
Set a breakpoint after the initialization of the List<Person>. In the immediate window, trying to evaluate a GroupBy or a Where which is not a simple equality check, it will throw an ArgumentException with the message "Cannot evaluate a security function."
A couple of examples would be:
people.Where(c => c.Name.Contains("F")).ToList()
people.GroupBy(c => c.Group).ToList()
Note: The watch statements seems to be working in Visual Studio Code, but not in Visual Studio 2017 Preview 3.