Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB -> C#: Late bound implicit conversion creates compile error #636

Closed
VetrivelDevOps opened this issue Sep 29, 2020 · 4 comments
Closed
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion

Comments

@VetrivelDevOps
Copy link

Input code

txtTotal.Text = Math.Round(sqlDT.Rows(0)("Expr1"), 2)

Erroneous output

txtTotal.Text = Conversions.ToString(Math.Round(sqlDT.Rows[0]["Expr1"], (object)2));

the stack trace.
Error	CS1503	Argument 1: cannot convert from 'object' to 'double'

Expected output

txtTotal.Text = Conversions.ToString(Math.Round(double.Parse(sqlDT.Rows[0]["Expr1"].ToString()), 2));

In C#, Math.Round function expecting 'double' datatype.

Details

  • Product in use: e.g. codeconverter.icsharpcode.net / VS extension / both
  • Version in use: e.g. 5.6.3 or a commit hash (if it's a 3rd party tool using this library, try one of the above)
  • Did you see it working in a previous version, which?
  • Any other relevant information to the issue, or your interest in contributing a fix.
@VetrivelDevOps VetrivelDevOps added the VB -> C# Specific to VB -> C# conversion label Sep 29, 2020
@VetrivelDevOps VetrivelDevOps changed the title VB -> C#: _Add a short description_ VB -> C#: Math.Round conversion issue Sep 29, 2020
@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Oct 3, 2020

Thanks, I can reproduce the issue so I think that's enough information to fix the issue. Hopefully I'll have some time to look at this in the next few weeks

@GrahamTheCoder
Copy link
Member

Ah, now I've looked closer, I see that the difficulty with this case is that there are multiple overloads (e.g. decimal or double) available, and it can't be known until runtime which will be used.
You can see the full details of what the VB compiler emits in this decompilation...it's not pretty.
It's possible to make the code converter to generate code like that...but I'm not convinced that's a particularly good solution to the issue. This will need more thought so is unlikely to be fixed very soon (if at all!) I'm sad to say

@GrahamTheCoder GrahamTheCoder changed the title VB -> C#: Math.Round conversion issue VB -> C#: Late bound implicit conversion creates compile error Oct 3, 2020
@GrahamTheCoder GrahamTheCoder added the compilation error A bug where the converted output won't compile label Oct 3, 2020
GrahamTheCoder added a commit that referenced this issue Oct 4, 2020
@GrahamTheCoder
Copy link
Member

Closing as known limitation

@GrahamTheCoder
Copy link
Member

Related to #782, #783, #786. Since the original report, I've realized that some cases may be solveable by careful use of dynamic in the output in the place of object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilation error A bug where the converted output won't compile VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants