[iOS] [.NET 8] Binding library source generator does not use interface for protocols · Issue #19612 · dotnet/macios (original) (raw)

Hello,

I'm trying to update my iOS binding library from .NET 7.0 to 8.0, but I believe the code behind source generator is not generating the correct code. When I define a protocol, it's not using the generated interface causing the object to try to inherit from both the NSObject and the protocol class. This results in compiler error CS1721 (cannot have multiple base classes).

This was working correctly in .NET 7.0, could I be missing a breaking change?

Steps to Reproduce

Create a new binding library and add the following code to the ApiDefinition.cs in a namespace of your choosing.

using System; using ObjCRuntime; using Foundation; using UIKit;

[Protocol] [BaseType(typeof(NSObject))] public interface ReaderProtocol { // @required -(NSString *)firstName; [Abstract] [Export("firstName")] string FirstName { get; } }

// @interface Reader : NSObject [BaseType(typeof(NSObject))] public interface Reader : ReaderProtocol { // -(id)initWithPreferredReader:(NSString *)name; [Export("initWithPreferredReader:")] IntPtr Constructor(string name); }

Expected Behavior

The generated Reader.g.cs file should have a Reader class with the following signature (net7.0-ios behavior):

[Register("Reader", true)] public unsafe partial class Reader : NSObject, IReaderProtocol { ... }

Actual Behavior

The generated Reader.g.cs file contains a Reader class with the following signature (net8.0-ios behavior):

[Register("Reader", true)] public unsafe partial class Reader : NSObject, ReaderProtocol { ... }

This causes the compiler to throw error CS1721 "Class 'Reader' cannot have multiple base classes: 'NSObject' and 'ReaderProtocol'.

Environment

Version information

Build Logs

Example Project (If Possible)