spring-projects / spring-net

Spring Framework for .NET
http://www.springframework.net
Apache License 2.0
846 stars 375 forks source link

ReferenceNode throws KeyNotFoundException when CurrentObjectFactory wasn't provided in variables. #219

Closed kamilpitula closed 2 years ago

kamilpitula commented 2 years ago

After a change that replaced IDictionary with generic IDictionary<string, object> in EvaluationContext class, ReferenceNode throws KeyNotFoundException instead of using default context (non generic dictionaries return null when key does not exsist). I came across this bug when i was trying to resolve Spring expression like this: expression.GetValue(arg.ExpressionContext, arg.ExpressionVariables), where expressionis of type IExpression. This forced me to add a line like this: arg.ExpressionVariables[Expression.ReservedVariableNames.RESERVEDPREFIX + "CurrentObjectFactory"] = ContextRegistry.GetContext(); in my code as a workaround.

I have added a check in ReferenceNode that verifies whether key is present in dictionary, and uses default context when it's not (as was initially intended I guess). I have also created some additional unit tests that cover cases I mentioned above.

kamilpitula commented 2 years ago

@lahma Hi, it seems that there is a problem with MSBuild in build-windows pipeline. Could you please take a look?

lahma commented 2 years ago

@kamilpitula I'll have a look probably this evening, seems that build infra needs some updates.

kamilpitula commented 2 years ago

@kamilpitula I'll have a look probably this evening, seems that build infra needs some updates.

Thanks!

lahma commented 2 years ago

@kamilpitula if you rebase against main you should have latest build infra which is green against main.

lahma commented 2 years ago

Thank you!