System.Linq.Dynamic.Core
System.Linq.Dynamic.Core copied to clipboard
Error accessing values in DynamicClass - fails on second attempt
This is broken in version 1.2.20. Version 1.2.19 is working.
1. Description
With this statement:
var result = DataContext.Users
.Where(u => u.Id == id)
.Select($"new {{{"Name,Email"}}}")
.ToDynamicList()
.FirstOrDefault();
The result variable has two properties: Name and Email.
On first access to a property, it works. On second access to any property it fails with the exception shown.
For example:
var a = result["Name"]; // okay
var b = result["Name"]; // crashes with exception
2. Exception
'result["Name"]' threw an exception of type 'System.ArgumentException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147024809
HelpLink: null
InnerException: null
Message: "An item with the same key has already been added."
ParamName: null
Source: "mscorlib"
StackTrace:
" at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Linq.Dynamic.Core.DynamicClass.get_Properties() in C:\\Dev\\GitHub\\System.Linq.Dynamic.Core\\src\\System.Linq.Dynamic.Core\\DynamicClass.cs:line 36
at CallSite.Target(Closure , CallSite , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)"
TargetSite: {Void ThrowArgumentException(System.ExceptionResource)}