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#:
vb:
Error:
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?11 Replies
(P.S. I also can't understand how a variable can be assigned to one value OR another)
The C# code is using bitwise or operator, presumably the Or keyword in VB does the equivalent
It's possible the VB project is using checked and the C# is using unchecked
Looks like VB.NET doesn't have unchecked like C# does
https://github.com/dotnet/vblang/issues/494
GitHub
[Proposal]: VB New Feature Unchecked math · Issue #494 · dotnet/vbl...
This is to open a "Feature Specification" following the process "roslyn/docs/contributing/Developing a Language Feature.md" for PR VB Prototype "Checked expressions" d...
Whereas unchecked is the default in C#
yeah, you need to change the option in your project file
<RemoveIntegerChecks>true</RemoveIntegerChecks>
i don't remember what it is called in the project properties window
it is a global setting, indeed there is no way to apply it just to a few lines of code
if this is some kind of environment where you don't control the compilation options (i can't imagine a good reason to be doing this otherwise) you are kinda screwed thoughWondering why you can't keep the code as C# and have the VB code reference the C# project
if that's an option i very strongly agree with doing that instead
Sadly, not an option. Trying to integrate the existing c# code into a legacy vb library. I'm trying to render the final library as one dll, rather than two (the c# library is a single class).
Let me look into RemoveIntegerChecks
personally i would make sure i couldn't use something like ILMerge before resorting to this. it would allow you to combine the C# and VB outputs into one assembly
What's wrong with two dlls?
That did it reflectronic - brilliant - thanks.
Thanks to both of you for the quick analysis!