How is it possible for no overload of ToString to take zero arguments? The zero-argument ToString is part of System.Object!
Edit in response to the close vote: Since I'm not in a position to upgrade my build server to .NET 4.5, is there any way to make this code work with the .NET 4.0/VS 2010 compilers? Short of giving my overload a completely different name, which is just not cool.
- The object in question is an F# Discriminated Union that overrides the ToString method inherited from System.Object.
- The overridden ToString is being called by code in a C# project that's part of the same solution.
- This all worked fine until I added an extra overload of ToString to my discriminated union, which takes one argument.
- It all builds and runs perfectly on my local machine (VS 2012, all projects targeting .NET 4.0)
- It fails on the build server (.NET 4.0) - the C# compiler error in the title showed up as soon as I added the 1-argument overload of ToString to my discriminated union.
I guess the simplest workaround would be to rename my ToString overload to something else, but this is bizarre.
Here's a simple reproduction. You can download a zip file of a solution containing this code here: http://dl.dropbox.com/u/1742470/CS1501_Repro.zip
Compiling that solution in VS 2010 will fail with "CS1501: No overload for method 'ToString' takes 0 arguments". Compiling it in VS 2012 will work just fine. In both cases we're targeting .NET Framework 4.
F#
namespace CS1501_Repro.FSharp
open System
[<Serializable>]
type MyDiscriminatedUnion =
| Foo of int list
| Bar of string
| Baz of int
| Fizz of float
| Buzz of DateTimeOffset
override this.ToString() =
"Zero Arguments"
member this.ToString(lookup:Func<int,string>) =
"One Argument"
C#
using System;
using CS1501_Repro.FSharp;
namespace CS1501_Repro.CSharp
{
public class Caller
{
private MyDiscriminatedUnion _item;
public Caller(MyDiscriminatedUnion item)
{
_item = item;
}
public string DoThing()
{
return _item.ToString();
}
public string DoOtherThing()
{
return _item.ToString(i => i.ToString());
}
}
}