最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Has IsNullOrEmpty been removed from Microsoft.Identity.Web? - Stack Overflow

programmeradmin2浏览0评论

Im upgrading my work project to .Net9 - we were using Microsoft.Identity.Web version 1.25.10 which supported the IsNullOrEmpty() method for JObjects, Ilists/Arrays/Ienumerables etc, but after updating to 3.7.0 it gives me a load of errors?

Has this been removed on one of the releases and if it has does someone have a link? ive tried to find some information online but cant seem to find anything.

 if (!FormData.IsNullOrEmpty()) //FormData is JObject - this works in v 1.25.10 but not in 3.7.0
 {

 }

Im upgrading my work project to .Net9 - we were using Microsoft.Identity.Web version 1.25.10 which supported the IsNullOrEmpty() method for JObjects, Ilists/Arrays/Ienumerables etc, but after updating to 3.7.0 it gives me a load of errors?

Has this been removed on one of the releases and if it has does someone have a link? ive tried to find some information online but cant seem to find anything.

 if (!FormData.IsNullOrEmpty()) //FormData is JObject - this works in v 1.25.10 but not in 3.7.0
 {

 }
Share Improve this question edited Apr 12 at 16:43 Lex Li 63.5k11 gold badges124 silver badges161 bronze badges asked Feb 11 at 12:04 A.s0392A.s0392 611 silver badge5 bronze badges 5
  • 5 IsNullOrEmpty never included in Microsoft.Identity.Web in the first learn.microsoft/en-us/dotnet/api/… – Hady Salah Commented Feb 11 at 12:16
  • 1 did you try a clean build? – jdweng Commented Feb 11 at 13:12
  • 1 hi @jdweng yes i attempted a clean build and it still gives me a load of errors. After upgrading to .Net9 and all the packages it no longer seems to be available for Ilists/Ienumberables etc – A.s0392 Commented Feb 11 at 14:56
  • 3 This sounds like it might be an extension method – Hans Kesting Commented Feb 11 at 16:24
  • 1 See Breaking changed under Windows Forms. There are a few issues with Null items : learn.microsoft/en-us/dotnet/core/compatibility/9.0 – jdweng Commented Feb 11 at 18:00
Add a comment  | 

1 Answer 1

Reset to default 7

I had the same issue, where I have code that was using List<T>.IsNullOrEmpty(). Turns out that it was a breaking change from the Microsoft.IdentityModel.Tokens library when it updated to version 8.0.

I initially found this article that describes how Microsoft.IdentityModel.Tokens exposed the method IEnumerable<T>.IsNullOrEmpty() as public incorrectly.

I then found another StackOverflow post where that explains that this public method was made internal "hopefully in version 8" of the package.

That entry links to the github issue thread where the developers of the package hesitated to change it earlier, and then decide to make the breaking change in version 8.0.0-preview2. This was then released with version 8.0.0 of the package as noted in the changelog under Breaking Changes.

As a result, you will likely need to develop your own extension method to add an IsNullOrEmpty() method that works for IEnumerable<T>. My project needed a simple re-implementation, which I built as follows:

public static bool IsNullOrEmpty<T>(this IEnumerable<T> value)
{
    return value == null || !value.Any();
}
发布评论

评论列表(0)

  1. 暂无评论