Skip to content

Can't build for release due to modreq from in #12656

Description

@hamarb123

Android framework version

net10.0-android

Affected platform version

.NET 10.0.400 SDK

Description

The build fails, due to not handling all edge cases here: https://github.com/dotnet/android/blob/main/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs#L84-L105.

Might be worth also handling any other similar cases, like IsSentinel, IsOptionalModifier, IsRequiredModifier, IsFunctionPointer, IsPointer (there may be others too). I can also repro with pointers, and haven't tried any others.

Steps to Reproduce

I used AI to help me get this relatively minimal repro.

  • Run dotnet new android -n Proj1
  • Run dotnet new androidlib -n Proj2
  • Add reference to Proj2 from Proj1
  • Add this code to MainActivity.cs:
        var renderer = new ConcreteRenderer();
        var context = new Context();
        renderer.Render(in context);
  • Edit Class1.cs in Proj2 to:
#nullable disable

namespace ReproLibrary;

public struct Context
{
    public int Value;
}

public interface IRenderer
{
    void Render(in Context context);
}

public abstract class Renderer : Java.Lang.Object, IRenderer
{
    public abstract void Render(in Context context);
}

public sealed class ConcreteRenderer : Renderer, IRenderer
{
    public override void Render(in Context context)
    {
    }
}
  • Build with dotnet build -c Debug (succeeds)
  • Build with dotnet build -c Release (fails)
  • If you build with -v diag you will see the error:
16:50:18.052   1:9>ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [C:\Users\Hamish\Projects\Tests\TestAndroidInMethod\Proj1\Proj1.csproj]
                     Fatal error in IL Linker (TaskId:81)
                     Unhandled exception. System.NotSupportedException: TypeDefinition cannot be resolved from 'Mono.Cecil.RequiredModifierType' type (TaskId:81)
                        at Mono.Linker.LinkContext.Resolve(TypeReference typeReference) (TaskId:81)
                        at MonoDroid.Tuner.FixAbstractMethodsStep.CompareTypes(TypeReference iType, TypeReference tType) (TaskId:81)
                        at MonoDroid.Tuner.FixAbstractMethodsStep.HaveSameSignature(TypeReference iface, MethodDefinition iMethod, MethodDefinition tMethod) (TaskId:81)
                        at MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods(TypeDefinition type) (TaskId:81)
                        at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessType(TypeDefinition type) (TaskId:81)
                        at MonoDroid.Tuner.FixAbstractMethodsStep.<Initialize>b__0_0(TypeDefinition type) (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, MessageOrigin origin) (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference, DependencyInfo reason, MessageOrigin& origin) (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction, MethodDefinition method, Boolean& requiresReflectionMethodBodyScanner, MessageOrigin& origin) (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.MarkAndCheckRequiresReflectionMethodBodyScanner(MethodIL methodIL, MessageOrigin origin) (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body, MessageOrigin origin) (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.ProcessPendingBodies() (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.Process() (TaskId:81)
                        at Mono.Linker.Steps.MarkStep.Process(LinkContext context) (TaskId:81)
                        at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) (TaskId:81)
                        at Mono.Linker.Pipeline.Process(LinkContext context) (TaskId:81)
                        at Mono.Linker.Driver.Run(ILogger customLogger) (TaskId:81)
                        at Mono.Linker.Driver.Main(String[] args) (TaskId:81)

Did you find any workaround?

Don't use in or ref readonly, pointers, etc., in any types that inherit from Object outside of the main app project.

Relevant log output

Additional Info

It also repros with

#nullable disable

namespace ReproLibrary;

public struct Context
{
    public int Value;
}

public interface IRenderer
{
    void Render(in Context context);
}

public class ConcreteRenderer : Java.Lang.Object, IRenderer
{
    public virtual void Render(in Context context)
    {
    }
}

I think, which is closer to my original setup.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: App+Library BuildIssues when building Library projects or Application projects.need-attentionA xamarin-android contributor needs to review

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions