xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 512 forks source link

Could not AOT the assembly #8944

Open danim-hub opened 4 years ago

danim-hub commented 4 years ago

I am getting this error compiling a Xamarin.Forms on Visual studio for Mac, targeting Release|iPhone /Users/danim/apps/logistics/Sales.iOS/MTOUCH: Error MT3001: Could not AOT the assembly '/Users/danim/apps/logistics/Sales.iOS/obj/iPhone/Release/mtouch-cache/3-Build/Logistics.Sales.dll' (MT3001) (Logistics.Sales.iOS)

It started happening with no apparent reason. This particular branch haven't had any commit since Jun 3rd, so I cannot tell exactly when it stopped compiling.

In Android it works fine.

It only happens in Release|iPhone mode. On Debug|iPhone it compiles, installs and runs fine.

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\Debug</OutputPath>
    <DefineConstants>DEBUG</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <MtouchArch>ARM64</MtouchArch>
    <CodesignKey>Apple Development: Daniel Montero (724P24NAB8)</CodesignKey>
    <MtouchDebug>true</MtouchDebug>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <MtouchLink>None</MtouchLink>
    <CodesignProvision>Logistic Development</CodesignProvision>
    <MtouchFastDev>
    </MtouchFastDev>
    <MtouchInterpreter>-all</MtouchInterpreter>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
    <DebugType>none</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\iPhone\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <MtouchArch>ARM64</MtouchArch>
    <ConsolePause>false</ConsolePause>
    <CodesignKey>Apple Development: Daniel Montero (724P24NAB8)</CodesignKey>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <MtouchEnableSGenConc>
    </MtouchEnableSGenConc>
    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
    <CodesignProvision>Logistic Development</CodesignProvision>
    <MtouchLink>SdkOnly</MtouchLink>
    <BuildIpa>true</BuildIpa>
    <MtouchExtraArgs>-v -v -v -v --optimize=experimental-xforms-product-type --linkskip=Microsoft.EntityFrameworkCore --linkskip=Microsoft.EntityFrameworkCore.Relational --linkskip=Microsoft.EntityFrameworkCore.Sqlite --linkskip=Microsoft.Extensions.Logging --linkskip=Microsoft.Extensions.Options --linkskip=Microsoft.Extensions.Caching.Memory --linkskip=System.Core --linkskip=Zebra.Printer.SDK</MtouchExtraArgs>
  </PropertyGroup>

I found online several workarounds for similar issues from 1 to 3 years old, but with no luck:

Steps to Reproduce

  1. Build my solution with Debug|iPhone - Builds OK
  2. Build my solution with Release|iPhone - Error appears
  3. Build from jenkins/msbuild (it was working on couple of weeks ago) - Also fails

Expected Behavior

The compiler generates an ipa

Actual Behavior

I get this error: /Users/danim/apps/logistics/Sales.iOS/MTOUCH: Error MT3001: Could not AOT the assembly '/Users/danim/apps/logistics/Sales.iOS/obj/iPhone/Release/mtouch-cache/3-Build/Logistics.Sales.dll' (MT3001) (Logistics.Sales.iOS)

Environment

Using visual studio 8.6.5 for mac, last updated today Jun 24 2020

Visual Studio Community 2019 for Mac
Version 8.6.5 (build 23)
Installation UUID: c1e6290b-93f3-440a-bdaa-127816ec1ea9
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

    Package version: 610000104

Mono Framework MDK
Runtime:
    Mono 6.10.0.104 (2019-12/5d03a6fe116) (64-bit)
    Package version: 610000104

Roslyn (Language Service)
3.6.0-3.20210.9+4eafdcb1bcbd8d3573f2ba6065e56d9b9ce4f8a3

NuGet
Version: 5.6.0.6591

Xamarin Designer
Version: 16.6.0.329
Hash: d4f8bcd13
Branch: remotes/origin/d16-6
Build date: 2020-04-24 02:16:02 UTC

.NET Core SDK
SDK: /usr/local/share/dotnet/sdk/3.1.301/Sdks
SDK Versions:
    3.1.301
    3.1.300
    3.1.200
    3.1.102
    3.0.100
    2.1.701
    2.1.505
    2.1.504
    2.1.302
    2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.10.0/lib/mono/msbuild/Current/bin/Sdks

.NET Core Runtime
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    3.1.5
    3.1.4
    3.1.2
    3.0.0
    2.1.19
    2.1.18
    2.1.16
    2.1.15
    2.1.13
    2.1.12
    2.1.9
    2.1.8
    2.1.2
    2.0.5

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

Updater
Version: 11

Apple Developer Tools
Xcode 11.5 (16139)
Build 11E608c

Xamarin.Mac
Version: 6.18.2.1 (Visual Studio Community)
Hash: 29c4ea731
Branch: d16-6
Build date: 2020-05-26 17:03:04-0400

Xamarin.iOS
Version: 13.18.2.1 (Visual Studio Community)
Hash: 29c4ea731
Branch: d16-6
Build date: 2020-05-26 17:03:05-0400

Xamarin.Android
Version: 10.3.1.4 (Visual Studio Community)
Commit: xamarin-android/d16-6/3a10de9
Android SDK: /Users/danim/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.2
SDK Build Tools Version: 28.0.3

Build Information: 
Mono: 165f4b0
Java.Interop: xamarin/java.interop/d16-6@2cab35c
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.31.1@49232bc
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-6@bfb66f3

Microsoft OpenJDK for Mobile
Java SDK: /Users/danim/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 16.6.0.50
Hash: 5901879
Branch: remotes/origin/d16-6
Build date: 2020-06-10 22:42:50 UTC

Android Device Manager
Version: 16.6.0.96
Hash: 6e8b80b
Branch: remotes/origin/d16-6
Build date: 2020-06-10 22:43:28 UTC

Build Information
Release ID: 806050023
Git revision: 5289d413b99fddfc20b4ecf3e445ccb822213427
Build date: 2020-06-18 12:08:30-04
Build branch: release-8.6
Xamarin extensions: 5289d413b99fddfc20b4ecf3e445ccb822213427

Operating System
Mac OS X 10.15.5
Darwin 19.5.0 Darwin Kernel Version 19.5.0
    Tue May 26 20:41:44 PDT 2020
    root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64

Build Logs

build.log

Example Project (If Possible)

Sorry no example minimum project yet. I am attaching the csproj for reference hope it helps

Logistics.Sales.iOS.csproj.txt

chamons commented 4 years ago

Would it be possible to attach Logistics.Sales.dll itself at least?

Without a sample, we can't dig into the AOT error.

danim-hub commented 4 years ago

I made a very simplified version of the project.

Please remove the .txt extension as the file is a tgz.

I think the offending line is in class InventoryReportTemplate:

            #line 6 ""

repro6.tgz.txt

chamons commented 4 years ago

I can reproduce the AOT issue with the provided sample.

It only happens first few times I build, after awhile it seems to fix itself even after a clean. Something strange is going on.

Redth commented 4 years ago

@jonathanpeppers this could be a bin/obj thing, could you have a look?

chamons commented 4 years ago

I think https://github.com/xamarin/xamarin-macios/issues/8957 might be a duplicate re-filed by the customer, or a related issue.

danim-hub commented 4 years ago

Hi Chris. That is another issue, although the scenario is very similar, it is not identical. When preparing the repro for this MT3001, I also got an MT5106 error, and the error message instructed to file an issue.

The repro is very similar but it has a couple of changes in a single file, and results in a different error code and message.

I hope this lets you catch two different bugs, but it is possible that both have the same cause

Thanks for your help

On Mon, Jun 29, 2020 at 10:25 AM Chris Hamons notifications@github.com wrote:

I think #8957 https://github.com/xamarin/xamarin-macios/issues/8957 might be a duplicate re-filed by the customer, or a related issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xamarin/xamarin-macios/issues/8944#issuecomment-651192282, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJTYGVFKMY4T7K7H7SHZPTRZCW7NANCNFSM4OGZVB3Q .

jonathanpeppers commented 4 years ago

I don't think this is a bin/obj problem, because the first build fails for me (or even Rebuild):

 % msbuild Sales.sln /p:Configuration=Release /p:Platform=iPhone /r /t:Rebuild
...
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk -Qunused-arguments -miphoneos-version-min=9.0 -arch arm64 -c -o /Users/jopepper/Downloads/logistics/Sales.iOS/obj/iPhone/Release/mtouch-cache/arm64/Xamarin.iOS.dll.o -x assembler /Users/jopepper/Downloads/logistics/Sales.iOS/obj/iPhone/Release/mtouch-cache/arm64/Xamarin.iOS.dll.s
MTOUCH : error MT3001: Could not AOT the assembly '/Users/jopepper/Downloads/logistics/Sales.iOS/obj/iPhone/Release/mtouch-cache/3-Build/Logistics.Sales.dll'

If I comment out one line in Sales.Share/Reports/InventoryReportTemplate.cs:

//#line 6 ""
this.Write("\r\n<Styl|Arial|50|Bold>\r\n<TexC|");

The problem goes away. I don't think I actually know how to fix this, @chamons could this be a problem with Mono AOT in general? I think it's probably something with this #line preprocessor:

https://docs.microsoft.com/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-line

I don't see how the problem could "fix itself" as described in: https://github.com/xamarin/xamarin-macios/issues/8944#issuecomment-650262812

There might be a second problem with incremental builds after a failure.

peppy commented 3 years ago

I'm not sure if I should open a new issue for this or not, but we're seeing this same issue on Microsoft.Diagnostics.Runtime version 2.0.222201

/Users/dean/Projects/osu/osu.iOS/MTOUCH: Error MT3001: Could not AOT the assembly '/Users/dean/Projects/osu/osu.iOS/obj/iPhone/Release/mtouch-cache/3-Build/Microsoft.Diagnostics.Runtime.dll' (MT3001) (osu.iOS)
rolfbjarne commented 3 years ago

@peppy

I'm not sure if I should open a new issue for this or not

When in doubt (and even when not too) always open a new issue. It's easy to merge two identical issues, but can turn out very confusing to have two separate problems in the same issue (and most likely one of them will end up not getting fixed).

So please file a new issue, and at the very least attach your diagnostic build log as the new issue template requests.