Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error accessing values in DynamicClass - fails on second attempt #629

Closed
glittle opened this issue Sep 10, 2022 · 1 comment
Closed

Error accessing values in DynamicClass - fails on second attempt #629

glittle opened this issue Sep 10, 2022 · 1 comment
Labels

Comments

@glittle
Copy link

glittle commented Sep 10, 2022

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)}
BBreiden pushed a commit to BBreiden/System.Linq.Dynamic.Core that referenced this issue Sep 19, 2022
@StefH StefH added the bug label Oct 1, 2022
@StefH
Copy link
Collaborator

StefH commented Oct 20, 2022

Maybe also related to #634 ?

StefH pushed a commit that referenced this issue Oct 23, 2022
* Init field only on first execution

* Test demonstrating issue #629

Co-authored-by: Boris Breidenbach <boris.breidenbach@aquantec.de>
@StefH StefH closed this as completed Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants