question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IDE0049 should be updated to suggest converting IntPtr to nint and UIntPtr to nuint.

See original GitHub issue

Brief description:

As mentioned in https://github.com/dotnet/runtime/issues/72348 with the numeric IntPtr feature, nint is now an alias for System.IntPtr and nuint is alias for System.UIntPtr, the analyzer IDE0049 should be updated to suggest converting IntPtr to nint and UIntPtr to nuint. Preferably default to “Info” level.

Languages applicable:

C# only

Additional information:

Related to https://github.com/dotnet/runtime/issues/72348

Documentation requirements:

When this analyzer is updated, the Documentation for IDE0049 analyzers could be updated accordingly.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cstoncommented, Aug 16, 2022

The compiler treats nint / nuint as aliases for System.IntPtr / System.UIntPtr when compiling with a corlib that includes System.Runtime.CompilerServices.RuntimeFeature.NumericIntPtr. Otherwise, the pairs of types are considered distinct.

0reactions
buyaa-ncommented, Aug 23, 2022

This also should consider @jkotas suggestion in the original issue:

It would be nice for the code-fixer to suggest replacing IntPtr with actual pointer types where the code is actually operating on pointers.

Blank replacing IntPtr with nint will often make code harder to understand. See discussion in https://github.com/dotnet/runtime/pull/70297

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I convert IntPtr to UIntPtr?
According to the site: "Changed IntPtr to UIntPtr: When invoking with IntPtr for the handles, you will run into an Overflow. UIntPtr is...
Read more >
CA2020: Prevent behavioral change caused by built-in ...
This rule fires when it detects a behavioral change between .NET 6 and .NET 7 introduced by the new built-in operators of IntPtr...
Read more >
C# Tutorial For Beginners: Native Sized Integers C# 9 | IntPtr C#
It can be converted to and from other pointer types, ... Beginners: Native Sized Integers C# 9 | IntPtr C# | UIntPtr C#...
Read more >
Converting from an Integer to an IntPtr - Duncan Mackenzie
A friend of mine at work just asked me this VB question, and it is an interesting one to me because it isn't...
Read more >
Introducing C# 11: Numeric IntPtr and UIntPtr
Here is the specification from C# 9 (source: Microsoft): “The types nint and nuint are represented by the underlying types System.IntPtr and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found