ardalis / GuardClauses

A simple package with guard clause extensions.
MIT License
3.06k stars 270 forks source link

CallerArgumentExpression No Longer Working When Targeting net6.0 #291

Closed msfreed closed 11 months ago

msfreed commented 1 year ago

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

image

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Marvin-Brouwer commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Marvin-Brouwer commented 1 year ago

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