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

Unable to extract constants from static field accesses #36

Open
andrewlock opened this issue Jul 30, 2019 · 2 comments
Open

Unable to extract constants from static field accesses #36

andrewlock opened this issue Jul 30, 2019 · 2 comments
Assignees
Milestone

Comments

@andrewlock
Copy link

I've been using this library without issue for some time, including in .NET Core 2.x apps, so thanks for that 🙂

However, I've just come across an issue with standard constants exposed as static fields like Guid.Empty and string.Empty. Basically, they are ignored during URL generation in ExpressionRouteHelper, in the MemberAccess branch:

else if (expressionArgument.NodeType == ExpressionType.MemberAccess
&& ((MemberExpression)expressionArgument).Member is FieldInfo)
{
// Expression of type c => c.Action(id)
// Value can be extracted without compiling.
var memberAccessExpr = (MemberExpression)expressionArgument;
var constantExpression = (ConstantExpression)memberAccessExpr.Expression;
if (constantExpression != null)
{
var innerMemberName = memberAccessExpr.Member.Name;
var compiledLambdaScopeField = constantExpression.Value.GetType().GetField(innerMemberName);
value = compiledLambdaScopeField.GetValue(constantExpression.Value);
}

As they're not a ConstantExpression, that branch returns null, no value is generated for the parameter, and link generation completely fails.

@ivaylokenov
Copy link
Owner

Hi, thank you for your issue. Since I am overwhelmed with my other project https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc, I did not have a lot of time to support this one. Will try to publish a new package during the weekend. Thank you for your patience!

@ivaylokenov ivaylokenov self-assigned this Sep 10, 2019
@ivaylokenov ivaylokenov added this to the Version 2.0.0 milestone Sep 10, 2019
@Piedone
Copy link

Piedone commented May 31, 2020

Would you be able to publish an updated package @ivaylokenov? Yours is a really great project and the best library for this purpose but not really usable with ASP.NET Core MVC 3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants