WinRT vs C# Overload Resolution

Browsing the Application Compatibility notes for the new .NET Framework 4.5, I noticed a very odd entry concerning Math.Ceiling and Math.Floor:

Change: When you use .NET for Windows Store apps, C# may have difficulty with overload resolution when the Math.Ceiling or Math.Floor method is passed an integer.

Impact: Source code may not compile successfully, or the operation may suffer from a loss of precision. To prevent this, explicitly cast the integer to a Decimal.

Math.Ceiling and Math.Floor only provide Decimal and Double overloads, and certainly Int64 values can exceed the range that is exactly representable by Double. But this applies to all .NET platforms, not just to “Windows Store” which I take to mean WinRT.

Testing on VS2010, I simply get a compiler error when attempting to supply an integer – of any size – to Math.Ceiling. An explicit cast is always required.

CS0121: The call is ambiguous between the following methods or properties: ‘System.Math.Ceiling(decimal)’ and ‘System.Math.Ceiling(double)’

But CS0121 is missing from the VS2012 list of C# Compiler Errors. So does VS2012 instead silently convert integer arguments to potentially inexact Double representations? And does this change really only apply to WinRT, as the compatibility note claims, or also to Win32, as the missing error code would seem to indicate?

In either case, that would be a significant change for the worse impacting all C# overload resolution, not just these two methods. I don’t have VS2012 installed myself, but I suggest early adopters should try immediately whether calls such as Math.Ceiling(123456) still result in a CS0121 compiler error.

edit: Michael Stum and Tim Anderson were kind of enough to test this behavior on VS2012. A compiler error still results on all systems, Win32 on Windows 7 as well as WinRT on Windows 8, so the strange compatibility note appears to be baseless.

5 thoughts on “WinRT vs C# Overload Resolution”

    1. And to add, there is no “error code” given, so no CS0121. But clicking “Error Help” leads to a website that has CS0121 in the URL:;k(TargetFrameworkMoniker-.NETFramework

        1. Right, I see. So I can only guess this check may be disabled for WinRT compilation, although why that would be I can’t imagine.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.