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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:47:52+00:00 2026-06-15T18:47:52+00:00

I have the following extension methods for my MessageBus : public static class MessageBusMixins

  • 0

I have the following extension methods for my MessageBus:

public static class MessageBusMixins
{
    public static IDisposable Subscribe<T>(
        this IObservable<T> observable,
        MessageBus bus)
    where T:class
    {
        ...
    }

    public static IDisposable Subscribe<T>( 
        this IObservable<Maybe<T>> observable,
        MessageBus bus)
    {
        ...
    }
}

which compiles fine. However when I try to use it:

IObservable<Maybe<string>> source = ...;
MessageBus bus = ...;

source.Subscribe(bus);

I get the error that neither of the two candidate methods
are most specific. However I thought that Maybe<T> would
be more specific than T or is that not correct?

EDIT

It gets curiouser because if I call the extension method
explicitly then:

MessageBus.SubscribeTo(source, bus);

Then it works and picks the correct method.

  • 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-15T18:47:54+00:00Added an answer on June 15, 2026 at 6:47 pm

    Well, you can fix it by specifying the type argument:

    source.Subscribe<string>(bus);
    

    … as that’s now only the second method is applicable.

    Otherwise, the compiler could call either of:

    source.Subscribe<string>(bus);
    source.Subscribe<Maybe<string>>(bus);
    

    If you think the first is more specific than the second, you’ll have to find the rule in the C# specification which says so 🙂 It’s not an unreasonable expectation, but I don’t think the normal “more specific” conversions apply to type parameters as well as regular parameters.

    So for example, in section 7.5.3.2 of the C# 4 spec (“Better Function Member”) there a rule about:

    • Otherwise if MP has more specific parameter types than MQ, then MP is better than MQ. [… lots of details about less/more specific …]

    … but there’s no similar point about type parameters. (The second about normal parameters talks about type arguments, but that’s within the parameter types themselves.)

    Another alternative is to simply give the methods different names. Do they have subtly different behaviour? If so, why not make that really obvious via the naming? You really don’t want someone to get the wrong behaviour just because they were surprised about which overload was called.

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

Sidebar

Related Questions

I have following extension method written: static public IQueryable<OutboundPattern> ByClientID(this IQueryable<OutboundPattern> qry, int clientID)
I have the following property definition: public static class Extensions { public static readonly
In C#, extension methods can be created by public static class MyExtensions { public
I have following LINQ statement and I want to rewrite it using extension methods.
I have a prototype model where I need to include the following extension methods
Update: This does work, I was being stupid :( i have the following extension
I have created the following extension of the observable list to mimic a readonly
I have a piece of code like the following: public class ActivityHelper { public
Here is my problem in C# : I have the following classes: public class
This extension method does not work on two separate development machines: public static string

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.