Unfortunately, in our (legacy) code base there is a property of a class that has type object and can be either a int or a long.
When trying to cast it to a long like this:
long id = (long) dBLockTabellenOptionen.Id;
I get the following exception:
Exception: Fehler in DoOneWorkRound:
Specified cast is not valid. Specified cast is not valid. -> Specified cast is not valid.
--- Exception Liste ---
System.InvalidCastException: Specified cast is not valid.
How can I savely cast it to a long without getting an exception?
Disclaimer: I know, that this property is a big smell but at this moment, the refactoring of it would be too much and since this application is going to get rewritten soon we will do it right then
long id = Convert.ToInt64(dBlockTabellenOptionen.Id); should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With