© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
18 replies
stigzler

Something getting lost in C# to VB.net conversion

For reasons too annoying to go into, I'm having to convert some code from an original library written in c# to one written in vb.net. I've used an automatic code converter and whilst it compiles, I'm getting an error at run time on one particular line:

c#:
dest[i] = (int)((uint)(newAlpha[i] << 24) | (uint)(newRed[i] << 16) | (uint)(newGreen[i] << 8) | (uint)newBlue[i]);
dest[i] = (int)((uint)(newAlpha[i] << 24) | (uint)(newRed[i] << 16) | (uint)(newGreen[i] << 8) | (uint)newBlue[i]);

vb:
dest(i) = CInt(CUInt(newAlpha(i) << 24) Or CUInt(newRed(i) << 16) Or CUInt(newGreen(i) << 8) Or CUInt(newBlue(i)))
dest(i) = CInt(CUInt(newAlpha(i) << 24) Or CUInt(newRed(i) << 16) Or CUInt(newGreen(i) << 8) Or CUInt(newBlue(i)))


Error:
System.OverflowException: 'Arithmetic operation resulted in an overflow.'
System.OverflowException: 'Arithmetic operation resulted in an overflow.'


Code works fine in c#. I haven't used bitshifts in my code before, so struggling to deconstruct what the problem might be. Any ideas?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

using serilog (c#) in a vb.net
C#CC# / help
3y ago
vb.net
C#CC# / help
3y ago
❔ VB.Net
C#CC# / help
4y ago
Dapper to c# decimal conversion fail
C#CC# / help
4mo ago