Search code examples
c#asp.netvisual-studiolong-integeruint64

Cannot declare any signed Integer types in C#


I'm working on an ASP.NET application in Visual Studio 2019. I'm running into a problem I've never encountered with C# before. I seemingly cannot declare any integer types other than UInt64.

Trying to declare an Int64 or a long gives me errors, because it says I'm trying to convert a UInt64 (or ulong) into one of those types.

The particular errors are as follows (the Azure tenant ids shown are dummy values, don't panic):

The line

Int64 tenantInt = 11132432026456784806;

gives the following error

Error   CS0266  Cannot implicitly convert type 'ulong' to 'long'. An explicit conversion exists (are you missing a cast?)

and then the following line of code

long TenantID = -11132432026456784806;

gives the following error

Error   CS0023  Operator '-' cannot be applied to operand of type 'ulong'

Here is an image of the very same errors: HERE

I've never encountered this when working in C# before. Normally these declarations work fine. Is there something wrong with Visual Studio? It keeps reading the numbers as UInt64, and trying to cast them using (Int64) or (long) is met with another error, that a UInt64 (or ulong) cannot be cast to those types.


Solution

  • Kalten is correct. The numbers I'm trying to assign are too big for Int64 and long. Essentially, the person I got this API from purposefully made the number too big so the line would throw an error so I would see the line and realize I need to replace it with my own ID.