Skip to content

Precompiling failed for C:\ProjectsVS2022Preview\xxxx\obj\Release\net7.0-android\android-arm\linked\System.Net.Requests.dll with exit code -1073741819. #8239

Closed

Description

@gmck

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 2022 17.7.0 Prev 6.0

Description

This issue is related to #8211 – could be viewed as a continuation of the issue, however, the error message is now obviously different.

In my comment in #8211, I said that when I added copyused I was able to successfully build a release build.

Since I was then able to create a release (albeit with a heap of Obsolete errors and warnings) I thought the best approach would be to get rid of all those warnings by rewriting the code containing the warnings.

I had several classes with PlatformNotSupported warnings (very old code) and many classes with Obsolete warnings. So since reporting #8211 and this issue, I’ve rewritten all those classes so that the project builds a debug build with no warnings. The build log of #8211 as compared to the one attached here would confirm that.

The most time-consuming changes were related to all my Google Subscriptions code due to the fact that I was using WebRequests rather than HttpClient. The code changes (13 HttpWebRequests) were simple enough, but the testing of each change takes forever because there are just so many features of Google’s Subscriptions that have to be tested to ensure they still gave the same results. A day or two ago, when I still had 3 or 4 of the HttpWebRequests to do, I created a release build because I was interested in comparing apk sizes between this build and the Xamarin.Android build. At that stage, the net7-android build apk was 45,711KB as compared to 27.3 (raw size) for the X.A. build. Note the X.A. build is measured using Android Studio’s Analyse Apk tool, as the release build in X.A. only shows the aab size. I did this so that I would have a comparison for when I did have a build completely free of warnings.

Now that I have achieved that I attempted a release build again. Unfortunately, even with copyused I now can’t build a release build.

This time it appears to be something to do with Aot. Could you please take a look at the logs and suggest what I can do?

The only change from the successful release build is that I’m now on Preview 6 instead of 4.

BuildLog243.zip

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Precompiling failed for C:\ProjectsVS2022Preview\OBDNowProsNet\OBDNowPros\obj\Release\net7.0-android\android-arm64\linked\System.Net.Requests.dll with exit code -1073741819.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Mono Ahead of Time compiler - compiling assembly C:\ProjectsVS2022Preview\OBDNowProsNet\OBDNowPros\obj\Release\net7.0-android\android-arm64\linked\System.Net.Requests.dll
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : AOTID 596985E0-D32E-492B-D5FD-A454827B9B2B
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\dotnet.aotprofile'
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Added 0 methods from profile.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Could not load signature of System.Net.HttpContinueDelegate:BeginInvoke due to: Could not load file or assembly 'System.Net.WebHeaderCollection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Precompiling failed for C:\ProjectsVS2022Preview\OBDNowProsNet\OBDNowPros\obj\Release\net7.0-android\android-arm\linked\System.Net.Requests.dll with exit code -1073741819.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Mono Ahead of Time compiler - compiling assembly C:\ProjectsVS2022Preview\OBDNowProsNet\OBDNowPros\obj\Release\net7.0-android\android-arm\linked\System.Net.Requests.dll
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : AOTID 5AEACC28-F979-2A0F-3754-ACF2A9A7EB21
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Using profile data file 'C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\dotnet.aotprofile'
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Added 0 methods from profile.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Could not load signature of System.Net.HttpContinueDelegate:BeginInvoke due to: Could not load file or assembly 'System.Net.WebHeaderCollection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Steps to Reproduce

N/A

Did you find any workaround?

No

Relevant log output

No response

Activity

  1. added
    Area: App+Library Build
    needs-triage
    on Aug 5, 2023
  2. gmck commented on Aug 8, 2023

    @gmck
    Author

    @dellis1972

    Some more work with the above.

    Because it was failing at the Aot stage and since if you leave the Aot stuff blank, you then automatically get Aot, I thought it worthwhile explicitly turning it off as a test.

    So I added the Aot stuff as false.

    <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
    <AndroidLinkTool>r8</AndroidLinkTool>
    
    <RunAOTCompilation>false</RunAOTCompilation>
    <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
    <PublishTrimmed>true</PublishTrimmed>
    <TrimMode>copyused</TrimMode> 
    
    

    That now builds with an apk of 39,195kb - somewhat smaller than the 45,711kb above when I wasn't completely finished with getting rid of the HttpWebRequests and their obsolete warnings.

    The point though is why do I now need to remove the Aot part compared to before? Obviously, there were no Aot errors before, but now there are. Could not load file or assembly 'System.Net.WebHeaderCollection. WebHeaderCollection is in Microsoft.NETCore.App in the Frameworks folder. I just don't understand why that error.

    So now turning off Aot and still using "copyused" results in a successful build. The app does run but is it extremely sluggish compared to the XA app.

    Next, remove the copyused and build again and now I'm back to the original problem Failed to resolve System.Security.Permissions.FileIOPermissionAccess. There is no using System.Security.Permissions in any file in the code.

    I'm going around in circles - getting nowhere. I'm back where I was 2 weeks ago. Hope you guys can help here.

    The XA app could go into production right now, but what is the point with Android 14 knocking on the door?

  3. dellis1972 commented on Aug 8, 2023

    @dellis1972
    Contributor

    I think we are going to need someone from the runtime team to take a look at this. @jonathanpeppers any idea who the test person to take a look would be?

  4. jonathanpeppers commented on Aug 9, 2023

    @jonathanpeppers
    Member

    It looks like the failure is due to using CopyUsed:

    1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\33.0.68\targets\Microsoft.Android.Sdk.Aot.targets(91,5): error : Could not load signature of System.Net.HttpContinueDelegate:BeginInvoke due to: Could not load file or assembly 'System.Net.WebHeaderCollection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
    

    The AOT compiler needs a complete closure of all used assemblies, and CopyUsed explicitly drops assemblies that are unused -- however the assembly references remain. Since nothing is trimmed the AOT compiler fails.

    We have seen issues with this setting in the past: #6625

    Our idea was to emit a build warning saying not to use it.

    The solution here is to somehow get your app to use System.Net.WebHeaderCollection.dll, so maybe simply defining an unused method like this would work around this issue:

    void Unused()
    {
        typeof(System.Net.WebHeaderCollection).ToString();
    }
  5. gmck commented on Aug 10, 2023

    @gmck
    Author

    @jonathanpeppers, @dellis1972 - Thanks for looking into this.

    I added your unused method and then removed all the lines I had added in the project file (as above), so now it is defaulting to a normal release build. However, the build failed and I'm back to where I started as per #8211 with ILLink : error IL1040: Failed to resolve System.Security.Permissions.FileIOPermissionAccess.

    I don't have any System.Security.Permissions using statements anywhere in the app. The closest I get is System.Security.Cryptography in Aes.cs. That was one of the classes I had to rewrite because the constructor I had used for Rfc2898DeriveBytes is now obsolete, so I swapped it to a non-obsolete ctor. Have tested it and it gives the same results as before, so I presumed that was all ok.

    I'm presuming because it is now an ILLink error, that the aot part of the build must now be ok.

    I'm very much a novice when it comes to aot and linking. I know that linking gets rid of used methods etc so you end up with a much smaller apk, but I don't even know what the linker was that Xamarin.Android used. I remember you wrote a blog about aot some time ago and I think that my really great start-up times (sub 1/2 sec) (displayed in Logcat) are due to the work you put into aot profiles. But that's about it for I really didn't have a need to look into it further other than fine-tuning with proguard when methods got stripped that shouldn't have.

    Attaching the latest build log.

    Buildlog20230810.zip

  6. jonathanpeppers commented on Aug 10, 2023

    @jonathanpeppers
    Member

    Are you able to narrow down which NuGet package causes the problem in #8211?

    Some of the questionable ones are:

    1>            -reference "C:\Users\youruser\.nuget\packages\google.apis\1.61.0\lib\netstandard2.0\Google.Apis.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\google.apis.androidpublisher.v3\1.61.0.3106\lib\netstandard2.0\Google.Apis.AndroidPublisher.v3.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\google.apis.auth\1.61.0\lib\netstandard2.0\Google.Apis.Auth.PlatformServices.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\google.apis.auth\1.61.0\lib\netstandard2.0\Google.Apis.Auth.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\google.apis.core\1.61.0\lib\netstandard2.0\Google.Apis.Core.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\microsoft.appcenter\5.0.2\lib\net6.0-android29.0\Microsoft.AppCenter.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\microsoft.appcenter.analytics\5.0.2\lib\net6.0-android29.0\Microsoft.AppCenter.Analytics.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\microsoft.appcenter.crashes\5.0.2\lib\net6.0-android29.0\Microsoft.AppCenter.Crashes.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\oxyplot.core\1.0.0\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1+Xamarin.iOS10\OxyPlot.dll"
    1>            -reference "C:\Users\youruser\.nuget\packages\oxyplot.xamarin.android\1.0.0\lib\MonoAndroid10\OxyPlot.Xamarin.Android.dll"
    

    It does make sense that a monoandroid library could run into a linker problem like this. The net6.0-android29 one seems very odd. Was it built with an early beta/alpha of .NET 6? The netstandard2.0 ones should work, these were just ones that jumped out.

    If you can figure out the package or create a sample app with the same issue, it would help us get to the bottom of this.

  7. gmck commented on Aug 10, 2023

    @gmck
    Author

    @jonathanpeppers . Thanks for the quick reply.

    I updated all packages before I made the new project. I made sure they were working first with the Xamarin.Android version of the app and then imported everything from the XA app into the net7 app.

    It looks like it is picking up previous versions of those packages. android29.0 - that's Android10 hell!

    I've never even looked at where they go. What is with the c:\users\youruser\ path where are you getting that from? I can see them in the log I sent but they are at c:\users\gmcke...etc.

    Just looking at C:\Users\gmcke.nuget\packages\microsoft.appcenter\5.0.2\lib\net6.0-android29.0, the content files are dated 19 May 2023 but the net6.0-android29.0 folder is dated 9 July 2023 as well as all the other folders in that lib folder.

    I assume that is how they are installed when I do an upgrade of VS 2022.

    Are you saying that you think my installation is screwed up? I just got a notification about 17.8.0 prev 1.0 being available. Do you think I should uninstall VS 2022 Preview and then reinstall? I'm on 17.7.0 P 6.0

    I've got no idea what is wrong - but surely other users use appcenter nugets and they'd be hitting a similar problem. I know App Center is working because I know from the debug build I've got a weird crash I can see in AppCenter with Bluetooth (bt socket closed) that I don't have in the X.A. version. I can avoid it easily, so I haven't checked it out yet.

    What do you get on a machine there? Are your App Center nugets any different to what I have?

    This is not looking good!!

  8. gmck commented on Aug 10, 2023

    @gmck
    Author

    @jonathanpeppers

    I used dotpeek to load net6.0-android29.0\Microsoft.AppCenter.dll and then searched for System.Security.Permissions.FileIOPermissionAccess and it is found there.

    So it looks like AppCenter is the culprit, but what is required to fix it?

  9. dellis1972 commented on Aug 10, 2023

    @dellis1972
    Contributor

    @gmck I suspected it was one of those (see #8211 (comment))
    use dotpeek to see what References Microsoft.AppCenter has, there might be an assembly reference which you have to add manaully to your app project.

    Based on https://learn.microsoft.com/en-us/dotnet/api/system.security.permissions.fileiopermissionaccess?view=dotnet-plat-ext-7.0&viewFallbackFrom=net-7.0. You might need to add System.Security.Permissions v7.0.0.
    See https://www.nuget.org/packages/System.Security.Permissions/7.0.0#supportedframeworks-body-tab.

  10. dellis1972 commented on Aug 10, 2023

    @dellis1972
    Contributor

    @gmck v7.0.0 will depend on the TargetFramework you are using. If you are targeting .net 7 then v7.0.0 might work. If you are targeting .net 8 then you might need to use a different version.

  11. gmck commented on Aug 11, 2023

    @gmck
    Author

    @dellis1972, @jonathanpeppers

    Good news. Added Security.System.Permissions 7.0.0 Nuget and that fixed the release build. Thank you both for your help.

    I haven't had time yet to do much testing but thought the following might be of interest as comparisons.

    Net7 Build
    aab size 29,110
    apk size 31,379
    Build Time 02:46:611
    Start Time(displayed ms) 480 429 467 436

    XA Build
    aab size 28,603
    apk size 27.3MB (measured with AS's Analyse APK tool
    Build Time 01:02:287
    Start Time(displayed ms) 434 453 459 478

    Test device Pixel 7.

    I've always been super impressed by what Aot can do re start-up times, because my app does plenty at start-up, in that it starts a bound service, which includes displaying a permanent notification, that ensures that the Bluetooth connection between a vehicle's ecu and the device is always maintained even when the app is forced into the background, because obviously if your aim is to continually collect the ecu information you don't want that flow of data (can be up to over 100+ pids per sec on a modern vehicle) interrupted by something as simple as an incoming call.

    However, after this particular exercise, I've come to the conclusion that I don't actually know what Aot and linking is all about. I was under the impression that Aot came after linking. I thought that you wouldn't bother trying to build a profile until the linker had resolved what was needed by the app. Once resolved, (i.e. unused code removed) you would then work with what was left to provide/figure out the fastest possible start-up.

    Since I have this concept so screwed up, I was wondering if you could point me to more information about how the process of linking and Aot are combined.

    Is it expected that the problem created by AppCenter will be corrected by them, or are we expected as developers to know that we may need to upgrade components of AppCenter? I've been using AppCenter for a long time now and I don't ever recall at any other time when its use has caused me problems, outside of using App Center functionality.

  12. gmck commented on Aug 12, 2023

    @gmck
    Author

    @jonathanpeppers, @dellis1972

    I forgot to mention that I was able to remove your suggestion below, as when I commented it out, it still built successfully without that error.

    The solution here is to somehow get your app to use System.Net.WebHeaderCollection.dll, so maybe simply defining an unused method like this would work around this issue:

    void Unused()
    {
    typeof(System.Net.WebHeaderCollection).ToString();
    }

  13. removed
    needs-triage
    on Jan 9, 2024
  14. jpobst commented on May 3, 2024

    @jpobst
    Contributor

    Good news. Added Security.System.Permissions 7.0.0 Nuget and that fixed the release build. Thank you both for your help.

    Sounds like this has been resolved.

  15. locked and limited conversation to collaborators on Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library Build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions