-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error MT4166 / MM4166 (Cannot register the method...) for generic property only in Release #15709
Comments
As a workaround we can use dynamic registrar for Release. To do so, the following should be added into the csproj
Eventually I'm unsure if it is a bug or just a known limitations of the static registrar. |
The code in question before the error:
Introduced in 4371ea4. Hey @rolfbjarne - You got your test case :) |
It looks like this works in the dynamic registrar by accident. The generic signature for the Test property is not allowed according to: https://docs.microsoft.com/en-us/xamarin/ios/internals/api-design/nsobject-generics#generic-type-arguments-in-member-signatures I believe it should be possible to do this instead: [Export("Test")]
public EnumWrapperOfMyEnum Test { get; } = EnumWrapper.Create(MyEnum.A);
public class EnumWrapper : NSObject
{
public static EnumWrapper<T> Create<T>(T value) where T : Enum => new EnumWrapper<T>(value);
}
public class EnumWrapper<T> : EnumWrapper where T:Enum
{
public T Value { get; }
public EnumWrapper(T value) => this.Value = value;
}
public class EnumWrapperOfMyEnum : EnumWrapper<MyEnum>
{
} |
@rolfbjarne, could you please provide a little more details? I'm asking not out of idle curiosity, but would like to make pull request into documentation as the from current version I was almost sure that such a things are registrar-compatible. I clearly understand why the following is prohibited (
The ObjC does not know how to work with But for this one
it looks like all instances is PS: the workaround is clear, although it sadly produces a lot of boilerplate code. |
@snechaev I agree this is a case that we might be able to support, my point was really that according to the documentation, it seems it shouldn't be (although the documentation isn't 100% clear either because this case doesn't totally match). |
@rolfbjarne, yes, I understood your point. The question is exactly about how can I better explain this case in the documentation (https://github.com/MicrosoftDocs/xamarin-docs/blob/live/docs/ios/internals/api-design/nsobject-generics.md) to make it 100% clear about this case. Could you please advise if something like "This is not supported by registrar yet" will be enough or it will be mandatory to provide some more detailed/deep explanation? |
@snechaev it's not mandatory to provide a deeper explanation (you could just link back to this issue). |
Steps to Reproduce
Expected Behavior
Project builds and works.
Actual Behavior
A lot of build errors. The main is
get_Test() & EnumWrapper
are declared as following, so it is definitelyNSObject
-inherited reference type, so seems to be all should be compatible with registrar.Moreover, it works in
Debug
without any issues.Environment
Version information
Build Logs
msbuild.binlog.zip
Example Project (If Possible)
MT4166Repro.zip
Additional note: in the logs this error is called MM4166, but in the documentation (https://github.com/xamarin/xamarin-macios/blob/main/docs/website/mtouch-errors.md) it is called MT4166 with the same error message.
The text was updated successfully, but these errors were encountered: