Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:36:29+00:00 2026-06-07T17:36:29+00:00

..and a side of fries. I have a codebase that I’m compiling for both

  • 0

..and a side of fries.

I have a codebase that I’m compiling for both Windows and MonoTouch. In the wee hours of the morning I coded something like this contrived example which compiles on MonoTouch but fails on Windows:

void Run()
{
    // okay on both
    exec("hello", 1);

    // okay on MonoTouch
    // compiler error on windows
    exec("hello");
}

interface IFace { void foo(); }

void exec(string s, int n=0) 
{ 
    Console.Write("A");  
}
void exec<T>(T t) where T:IFace
{ 
    Console.Write("B");
}

On MonoTouch, this compiles and runs, printing:

AA

On Windows, this example gives a compile-time error:

The type 'string' cannot be used as type parameter 'T' in the generic type or method 'App.Program.exec<T>(T)'. There is no implicit reference conversion from 'string' to 'App.Program.IFace'.

The C# spec on 7.4.2 Overload Resolution says that an 7.4.2.1 Applicable function member must have an identical number of arguments:

The number of arguments in A is identical to the number of parameters in the function member declaration. 7.4.2.1

So it would seem the MonoTouch compiler is considering default arguments when searching for applicable function members, but the Windows compiler is not. So the candidate function members are:

// exec with no default parameters. not applicable because no int supplied
void exec(string,int);

// exec with default value for the second parameter. 
// only considered on MonoTouch.
void exec(string,int=0);

// generic exec with string as the type, which is invalid
// due to the IFace constraint. Invalid on both platforms.
void exec<string>(string) : where T:IFace; 

So, is this a bug in the Applicable Function Member search on MonoTouch, or should the Windows compiler consider the default-parameterized non-generic method as valid?

Cheers,
cm

EDIT
After dlev‘s answer, I tested both the constrained and unconstrained generic methods, and it appears the Mono compiler chooses the correct method in the unconstrained case. In the constrained case, it appears that the Mono compiler is either considering the constraint or backtracking to find an alternative when the constraint fails.

The problem/bug reduces to:

void Run()
{
    foo(1);
    bar(1);
}

void foo(int a, int b = 0) { print("A"); }
void foo<T>(T t) { print("B"); }

void bar(int a, int b=0) { print("X"); }
void bar<T>(T t) where T : IFace { print("Y"); }

On both Windows and MonoTouch, foo correctly prints B. But bar fails to compile on Windows yet prints X on MonoTouch.

EDIT2
For those interested, my solution was to remove the default parameters and require explicit invoke. In my actual system, the type constraint specifies two interfaces, so I can’t easily change the generic call to exec(IFace t) { ... }. I suppose I could refactor, but this is the meat of my system and the following solves my current compile problems:

void exec(string a) { exec(a,0); }
void exec(string a, int b) { ... }
void exec<T>(T t) where T : IFace, IFace2 { ... }

Double Cheers, cm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:36:32+00:00Added an answer on June 7, 2026 at 5:36 pm

    This line, from section 7.5.3.2 in the spec suggests that this is a bug in the Mono compiler:

    Otherwise if all parameters of MP have a corresponding argument
    whereas default arguments need to be substituted for at least one
    optional parameter in MQ then MP is better than MQ.

    In other words, if you have to substitute a value for an optional parameter to make an applicable method call legal, then that method is considered a worse match then one that does not require such a substitution.

    Also, the MS C# compiler does not back-track. Once a method is determined to be the best per the overload resolution rules, compilation continues under that assumption. If later analysis determines that the selected method results in an error (say because the substituted generic argument violates a constraint) then you are told about that error.

    And yes, constraints are not part of the signature, so overload resolution does not consider the constraint on T.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DropDownList that fires off some server-side databinding in its OnSelectedIndexChanged event.
I have a drop down (dropdown2) that is required IF there is something in
It's Friday afternoon and my brain is fried. I have a unique server side
I am doing server-side javascript and i need to have a typed array of
While developer a client side application I ran into an error that I believe
I have an urgent problem..I am developing a windows mobile 6.0 application and the
I have a asp:textbox with a OnTextChanged event that I want to fire when
Do PHP5.3 have any known bug issue that makes non static variables in scope
I have a program that uses GLUT for its OpenGL rendering. Now I need
I've got a small linkbox on the side of my page that is rendered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.