dotnet / dotnet/macios

Error MT4166 / MM4166 (Cannot register the method...) for generic property only in Release

Open
#15,709 7 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 13h
Merged PRs (30d)
96

Description

### Steps to Reproduce

1. Grab the test project [MT4166Repro.zip](https://github.com/xamarin/xamarin-macios/files/9380415/MT4166Repro.zip)
2. Build in **Release**
3. Observe build errors

### Expected Behavior
Project builds and works.

### Actual Behavior
A lot of build errors. The main is
```
/MT4166Repro/AppDelegate.cs(0,0): Error MM4166: Cannot register the method 'get_Test()' because the signature contains a type (MT4166Repro.EnumWrapper`1) that isn't a reference type. (MM4166) (MT4166Repro)
```

`get_Test() & EnumWrapper` are declared as following, so it is definitely `NSObject`-inherited reference type, so seems to be all should be compatible with registrar.
Moreover, it works in `Debug` without any issues.
```
[Export("Test")]
public EnumWrapper Test { get; } = EnumWrapper.Create(MyEnum.A);

public class EnumWrapper : NSObject
{
public static EnumWrapper Create(T value) where T : Enum => new EnumWrapper(value);
}

public class EnumWrapper : EnumWrapper where T:Enum
{
public T Value { get; }
public EnumWrapper(T value) => this.Value = value;
}
```

### Environment

Version information

```
Visual Studio Professional 2022 for Mac
Version 17.3.1 (build 411)
Installation UUID: 18b3b114-81b5-4a14-872e-231807c1b48b

Runtime
.NET 6.0.5 (64-bit)
Architecture: X64

Roslyn (Language Service)
4.3.0-3.22312.2+52adfb8b2dc71ed4278debcf13960f2116868608

NuGet
Version: 6.2.1.2

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/6.0.400/Sdks
SDK Versions:
6.0.400
3.1.422
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
6.0.8
3.1.28

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode 13.4.1 (20504)
Build 13F100

Xamarin.Mac
Version: 8.12.0.2 (Visual Studio Professional)
Hash: 87f98a75e
Branch: d17-3
Build date: 2022-07-25 20:18:54-0400

Xamarin.iOS
Version: 15.12.0.2 (Visual Studio Professional)
Hash: 87f98a75e
Branch: d17-3
Build date: 2022-07-25 20:18:55-0400

Xamarin Designer
Version: 17.3.0.208
Hash: 0de472ea0
Branch: remotes/origin/d17-3
Build date: 2022-08-11 21:29:58 UTC

Xamarin.Android
Not Installed

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.3.0.23
Hash: 965bf40
Branch: remotes/origin/d17-3
Build date: 2022-08-11 21:30:03 UTC

Android Device Manager
Version: 0.0.0.1169
Hash: fafb1d5
Branch: fafb1d5
Build date: 2022-08-11 21:30:03 UTC

Build Information
Release ID: 1703010411
Git revision: 22408f3ad66bf33ab9530b882011bed98ebf1503
Build date: 2022-08-11 21:28:07+00
Build branch: release-17.3
Build lane: release-17.3

Operating System
Mac OS X 12.4.0
Darwin 21.5.0 Darwin Kernel Version 21.5.0
Tue Apr 26 21:08:22 PDT 2022
root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Enabled user installed extensions
Log Monitor 0.7
.NET Core Extensions 0.4
```

### Build Logs

[msbuild.binlog.zip](https://github.com/xamarin/xamarin-macios/files/9380459/msbuild.binlog.zip)

### Example Project (If Possible)
[MT4166Repro.zip](https://github.com/xamarin/xamarin-macios/files/9380415/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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.