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 6556437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:56:41+00:00 2026-05-25T12:56:41+00:00

namespace TestLibrary { [TestFixture] public class Class1 { public delegate T Initializer<T>(); public static

  • 0
namespace TestLibrary
{
    [TestFixture]
    public class Class1
    {
        public delegate T Initializer<T>();

        public static T MyGenericMethod<T>(Initializer<T> initializer) where T : class
        {
            return initializer != null ? initializer() : null;
        }

        [Test]
        public void Test()
        {
            var result = MyGenericMethod(MyInitializer);
            Assert.IsNotNull(result);
        }

        private object MyInitializer()
        {
            return new object();
        }
    }
}

This is a functioning piece of code when running in Visual Studion 2010. If I try to build this using MSBUILD from command line…

"c:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe" Solution1.sln

… I get very familiar error message:

The type arguments for method ‘Method name’ cannot be inferred from
the usage. Try specifying the type arguments explicitly.

Any ideas?

  • 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-05-25T12:56:42+00:00Added an answer on May 25, 2026 at 12:56 pm

    This appears to be a difference between the compiler versions used by VS 2010 and MSBuild 3.5. This makes sense as type inference was improved a lot in later compiler versions.

    If you need to use MSBuild 3.5, you’ll need to correct your code:

    var result = MyGenericMethod<object>(MyInitializer);

    However, you should be able to use MSBuild v4 and target the 3.5 framework. You can also target this framework in VS 2010. Based on the fact that when targeting 3.5 using VS 2010 the code compiles, I think it will likely work via MSBuild v4.

    Courtesy of Radex in the comments:

    c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" Solution1.sln /p:TargetFrameworkVersion=v3.5

    Just to clarify, this is my educated-guess answer based on the comments.

    Not sure if this is relevant, but I found this on MSDN: http://msdn.microsoft.com/en-us/library/ee855831.aspx

    Method group type inference

    The compiler can infer both generic and non-generic delegates for
    method groups, which might introduce ambiguity.

    In C# 2008, the compiler cannot infer generic delegates for method
    groups. Therefore, it always uses a non-generic delegate if one
    exists.

    In C# 2010, both generic and non-generic delegates are inferred for
    method groups, and the compiler is equally likely to infer either.
    This can introduce ambiguity if you have generic and non-generic
    versions of a delegate and both satisfy the requirements. For example,
    the following code complies in C# 2008 and calls a method that uses a
    non-generic delegate. In C# 2010, this code produces a compiler error
    that reports an ambiguous call.

    Further reading:

    http://togaroga.com/2009/11/smarter-type-inference-with-c-4/

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

Sidebar

Related Questions

API: namespace ClassLibrary1 { public class Class1 { public static string Test(string input) {
namespace MoqSample.Test { [TestFixture] public class GivenCustomerServiceTest { private ICustomerService customerService; private CustomerModel customer;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string word =
using namespace std; class WINDOW { protected: GtkWidget *window; public: WINDOW(); GtkWidget* get_window(); void
Example: namespace MyProgram.Testing { public class Test1 { public void TestMethod() { String actualType
namespace extractDB { class ConsoleApp2 { static void Main(string[] args) { string dog =fancy;
namespace MyNamespace { static void foo1() { } } using namespace MyNamespace; class MyClass
I have the following: namespace Test { public class Location { public string city
namespace X{ public static class URLs { public static TabController tabIdLookUp = new TabController();
using namespace std; class A { public: A() {} ~A() {} map<int, string*>& getMap()

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.