Does the function return type for the child type change binary compatibility?

Let's go straight to it:

Old code:

public interface IFoo {}
public class Foo : IFoo {}
...
public static IFoo Bar() { return new Foo(); }

      

New code:

public static Foo Bar() { return new Foo(); }

      

Obviously there shouldn't be any problem here, whatever you did with the old return type, you can still use the new return type, any is

, as

or cast should behave the same as before ...

So I broke binary compatibility, or can I just let it go as a minor version without bothering users?

+3


source to share


2 answers


This breaks binary compatibility, but not (most) compile-time compatibility issues, so this is usually a simple migration.



Note that it might even be a compile-time break if client code creates a delegate from a method.

+4


source


You may have problems with people who have created unit tests around your code. Since these are static people could create FooAdapater like this: -

public class FooAdapater(){ 
public IFoo GetFoo() { Return your static Bar; }
}

      



They could then create a mocking foo adapter than return fooed foo. Your code will break this scenario.

So no, this is not binary compatible :-)

-1


source







All Articles