-
Notifications
You must be signed in to change notification settings - Fork 27
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
System.InvalidOperationException: 'Couldn't find a value for that key' #221
Comments
Hi, Thanks for letting me know about this - it looks like it's being caused by your constructor parameters having the same name as your properties - if you change the constructor parameter names to lower case, it works. Obviously that shouldn't be happening, so I'll look into it and sort it out. Cheers, Steve |
This was a simple repro of an issue we're facing in our actual project. After making the constructor parameters lower case in our project we get past that error and instead get 'an item with the same key has already been added'. We haven't got a simple repro for that yet, but I thought I'd FYI in case it's related. |
We have now removed WhenMapping.ThrowIfAnyMappingPlanIsIncomplete() from the config and now the 'an item with the same key has already been added' error is gone and the mapping works. Not sure if that's expected or not? |
Interestingly if we leave in WhenMapping.ThrowIfAnyMappingPlanIsIncomplete() and add SwallowAllExceptions() on the problem mapping we still get this 'an item with the same key has already been added' error when using that mapping. |
That's all good info, thanks very much for letting me know. I'll sort out each of those issues :) |
Hi, I've fixed the initial issue with the same-named, same-casing constructor parameters, but have been unable to reproduce the 'an item with the same key has already been added' exception with To offer a couple of notes - and I understand the code you've shared is an incomplete snippet from a larger project, so this might not be relevant:
mapper.WhenMapping.ThrowIfAnyMappingPlanIsIncomplete();
// and
mapper.WhenMapping.UseConfigurations.From<MapperConfig>(); ...rather than: Mapper.WhenMapping.ThrowIfAnyMappingPlanIsIncomplete();
// and
Mapper.WhenMapping.UseConfigurations.From<MapperConfig>();
All the best, Steve |
Ah yes the capital M was typo on the repro, though the behaviour is the same either way. Can we use WhenMapping.ThrowIfAnyMappingPlanIsIncomplete(); in the configuration class or does it have to be applied to the instance? |
@SteveWilkes If you can publish the change for the initial issue we can test it and maybe it will resolve the others. |
@SteveWilkes What is the correct way to clear the cache? We are often getting stuck with this error when calling GetPlanFor and undoing a change doesn't always clear it: System.InvalidProgramException: 'Common Language Runtime detected an invalid program.' |
For 'Common Language Runtime detected an invalid program' - that's probably being thrown when the code is attempting to compile a mapping Func, but it's hard to say why. Do you have more of a stack trace? |
at System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo method) |
@SteveWilkes I made a debug build of AgileMapper and pulled out the mappingLambda debug view. I had to anonymize it a bit but hopefully it's close enough to give you an idea of what's going on:
|
Thanks! I'll see what I can figure out... |
Ello, Looking at the callstack - the error is being thrown when the mapper is trying to create a function to map one of the recursive relationships - either Thanks, |
Adding IgnoreTargetMembersOfType() to the mapping config stops the exception so I think that's where the problem lies. I'll try and get a simple repro for it. |
@SteveWilkes Attached is a small solution that reproduces the invalid runtime exception. FYI I think there is possibly more than one cause. |
Excellent, thank you very much! |
Ok, that was an interesting one - the problem came from the mapper trying to map the I've pushed a fix to the releases/next branch - the mapper now ignores these types of properties. |
…efault values, re: #221 / Performance improvements
I've now pushed a further fix which adds support for mapping VB.NET named, indexed properties, provided all the indexes have default values, which will be used when mapping the member. |
Thanks, I'll check it out. |
@SteveWilkes The updated AgileMapper does get past the issues we were having but then hits another. I've added a little more to one of the methods and the signature is now what we have in our solution. New repro project: |
Thanks again, I'll take a look. |
I hadn't handled the default value for an optional index being |
Great, I'll give that a go and let you know if there's any further issues. |
@SteveWilkes FYI, we are still very interested in pushing on with integrating AgileMapper but unfortunately it looks like any further work on it is going to be a couple of sprints away so it might be a while before I can come back to you with any further issues.. |
No problem @C-Wal - thanks for all your feedback so far :) |
* Fixing mapping of ctor parameters named eactly the same as members, re: #211 / Moving LangVersion to Build.Directory.props / Performance tweaks / Updating NuGet packages * Renames for clarity * Handling named, indexed VB.NET properties, re: #221 * Support for VB.NET named, indexed properties where all indexes have default values, re: #221 / Performance improvements * Fixing cache concurrency * Switching .NET Core test projects to LTS versions * Adding .NET 5 + 6 test projects * Updating release notes * Handling named, indexed property null optional default index values, re: #211 * Tweak * Updating to v1.8.1 * Removing NuGet pack bat file * Add v1.8.1 NuGet package
The defects we found in this issue are fixed as of v1.8.1, which is now available on NuGet - please feel free to open another issue here if you find more! All the best, |
Why does this simple set-up result in an exception? I am using .Net Framework 4.6.2 and AgileMapper 1.8.
The exception and message are returned from the call to ToANew().
If I remove the constructor with parameters from the Item class then there is no exception thrown.
If I use Over() with a new instance of Item then there is no exception thrown.
The text was updated successfully, but these errors were encountered: