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

CallerArgumentExpression No Longer Working When Targeting net6.0 #291

Closed
msfreed opened this issue Aug 11, 2023 · 9 comments · Fixed by #303
Closed

CallerArgumentExpression No Longer Working When Targeting net6.0 #291

msfreed opened this issue Aug 11, 2023 · 9 comments · Fixed by #303

Comments

@msfreed
Copy link

msfreed commented Aug 11, 2023

Targeting net6.0, as of v4.1.0 the optional parameterName is no longer available. This works in v4.0.1.

image

  • .NET SDK Version: net6.0

Steps to Reproduce:

  1. Create a net6.0 project
  2. Use extension NullOrWhiteSpace (for example)
public void MyMethod(string id)
{
    Guard.Against.NullOrWhiteSpace(id);
}
@Marvin-Brouwer
Copy link
Contributor

Marvin-Brouwer commented Aug 15, 2023

This seems related to #282, looking at the files: https://github.com/ardalis/GuardClauses/pull/282/files, they just simply changed the build target to net7, forcing net6 to use netstandard2.0 which doesn't have the CallerArgumentExpression implementations.

@Marvin-Brouwer
Copy link
Contributor

I guess it's up to the maintainers to decide whether they want to support net6, perhaps having a netstandard2.1 version for older versions that support CallerArgumentExpression.
@ardalis, what do you think?

@ardalis
Copy link
Owner

ardalis commented Aug 15, 2023

One possible fix: https://stackoverflow.com/a/70034587/13729

Does netstandard2.1 have support for CallerArgumentExpression? I don't really want to drop netstandard2.0 support since I know many projects leverage that, but maybe it's worth adding another target for 2.1.

@ardalis
Copy link
Owner

ardalis commented Aug 15, 2023

Of course I expect most folks on net6 to jump to net8 quickly which will also eliminate this issue, I think.

@Marvin-Brouwer
Copy link
Contributor

Marvin-Brouwer commented Aug 16, 2023

One possible fix: https://stackoverflow.com/a/70034587/13729

Does netstandard2.1 have support for CallerArgumentExpression? I don't really want to drop netstandard2.0 support since I know many projects leverage that, but maybe it's worth adding another target for 2.1.

Don't really know. In fact now you question it, I don't think so. It's supported bij netcore3.1 so probably not.

About the possible fix, I've used similar things to this in a library of mine. It works fine, however I'm not sure it'll make it through outside of your code base.
I'm happy to test with an alpha build.

@Marvin-Brouwer
Copy link
Contributor

Of course I expect most folks on net6 to jump to net8 quickly which will also eliminate this issue, I think.

Well, with the speed of how some people upgrade I'm not planning to drop net6 from my library yet.
I'm probably not the only one, and it'll probably have a domino effect.

@dstretch
Copy link

I won't be quickly jumping to .Net 8 until it's been out and proven for a while. We still have support for .Net 6 for a bit longer and it would be great to fix this!

@mwasson74
Copy link

Is this related/the same as my question #290?

@Marvin-Brouwer
Copy link
Contributor

@ardalis I decided to try out your suggestion.
It worked locally so I made a PR: #303. Please have a look.

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

Successfully merging a pull request may close this issue.

5 participants