Skip to content

ILLink : error IL1040: Failed to resolve System.Security.Permissions.FileIOPermissionAccess. #8211

Closed

Description

@gmck

Android application type

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

Affected platform version

VS 2022 17.7.0 Prev 3.0

Description

I’m in the process of converting one of my Xamarin.Android apps to Net7. The app is successfully converted. It does have a number of warnings about using obsolete classes unrelated to Android which have to be corrected but that doesn’t stop it from building and running fine in debug mode. The obsolete classes are not affecting run time behaviour, the code is still executing as previously.

However, it fails to build in release with IILink error
ILLink : error IL1040: Failed to resolve System.Security.Permissions.FileIOPermissionAccess.
It does suggest - Optimization can be disabled by setting the PublishTrimmed property to false. However, I’d prefer not to do that on a release build at this stage.

As part of this upgrade process, I had previously updated all NuGet packages including BillingClient6 in the Xamarin.Android version and would like to establish that the billing code in the Net7 build still works as it does in the Xamarin.Android version.

I’ve got no idea why ILLink is failing with that error. Could it be related to the warnings that I now get in my AES class? The default hash algorithm and iteration counts in Rfc2898DeriveBytes constructors are outdated and insecure. That code is very old, so obviously needs to be rewritten.

If that is not the reason for the ILLink error can you suggest what maybe is causing it?

As part of the conversion process, I decided to update the Xamarin.Android version first using nullable enable in each file, thinking it would make the upgrade process more manageable. After fixing 195 files in the old version, I was then surprised to find that there were still plenty more nullable warnings in the Net7 version. I presume that is due to the C# 11 compiler as compared to the older version. I can’t find any documentation of the version of the compiler used in Xamarin.Android. Can you please indicate what version it uses? I know that we can’t change it in the build properties window, but the reference included there doesn’t actually mention what version is in use for Xamarin.Android project.

After doing all that tedious nullable work, the obvious question is why can’t that be automated? If the compiler can figure out all those warnings, surely it could on the fly correct them? Or a conversion-type tool that manually asks Yes/No for each warning.

Attaching the build log and csproj in buildgmk.zip

Buildgmk.zip

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 Jul 23, 2023
  2. dellis1972 commented on Jul 24, 2023

    @dellis1972
    Contributor

    @gmck looking at the API surface of System.Security.Permisisons in .net 6+ it looks like that type does not exist. https://learn.microsoft.com/en-us/dotnet/api/system.security.permissions?view=net-7.0.

    That suggests that the library you are trying to use (if it uses that type) won't work under .net 6+.
    The linker will try to resolve all the types used by the app as part of the link process. This is how it decides what to safely keep and what it can remove.

    I'm not sure what to suggest except try to find the code using the FileIOPermissionAccess type and remove it.
    If its in a NuGet perhaps contact the author and ask if they plan to upgrade to .net 6+

  3. gmck commented on Jul 25, 2023

    @gmck
    Author

    @dellis1972
    As you can see from the proj file all the Nugets are standard Android stuff except for one called OxyPlot.Xamarin.Android which is a package that allows me to create graphs of my data and I can't imagine anything like that being concerned with System.Security.Permissions.

    I tried false, but that didn't help because it still wouldn't build without the same error. I was hoping to be at least able to run something and see when it crashed if I could see anything that points to the problem.

    I don't understand why ILLink is not more specific. For example, when you use proguard you know what causes the crash for a missing method and you get text files generated like seeds and usage to help you out. "does not exist" is not the same as obsolete. Why provide an error message such as Optimization can be disabled by setting the PublishedTrimmed property to false, if it still won't build?

    When you do a file search of the whole solution there is nothing returned for FileIOPermissionAccess.

    Update: Glad I didn't hit the Comment button earlier. I tried adding <TrimMode>copyused</TrimMode> and that allowed it to build successfully, short test seems to be running the same as the Xmarin.Android version. The only downer is that the aab is about 10KB bigger than the Xamarin.Android one.

    Now have bumped the Preview from 3 to 4.

  4. dellis1972 commented on Jul 25, 2023

    @dellis1972
    Contributor

    @gmck

    It might be pulled in from these packages

    Microsoft.AppCenter.Analytics
    Microsoft.AppCenter.Crashes
    Google.Apis.AndroidPublisher.v3

    or even Mono.Data.Sqlite. Some of those might well be built against mono/full .net rather than .net6+. The only way to really know ifs to check which frameworks the Nuget Packages support.

    For questions regarding the ILLink task you'd need to ask the dotnet runtime team over at https://github.com/dotnet/runtime. I'm sure they would appriciate the feedback on how to improve the error messages they produce (like telling you which assembly the type is being pulled in from).

  5. gmck commented on Jul 25, 2023

    @gmck
    Author

    @dellis1972

    I ended up signing it and uploaded it to Google Play. GP spat the dummy about how big it was as compared to the Xamarin.Android version I'd uploaded earlier in the day. GP reports the size for the new installs is now 32MB as compared to 20MB. Something else must be going on because the X.A version is SDK only too, but the code in both versions is now exactly the same, other than the extra newer nullable stuff I found in the net7 version. I remember some time ago having to change from SDK and User Assemblies to just SDK but now can't remember the reason why. Maybe I'll remember in the morning. I may have to go backwards and change the X.A version back to check what was the reason.

    Wouldn't @jpobst know about AndroidPublisher.V3. I actually thought he wrote it, maybe I'm wrong, but I thought I saw his name in the code in a comment at one stage. Could be I'm just getting mixed up with all the Jonathons.

    The code I referred to above, the AES class, is just encrypt and decrypt stuff for internet traffic and is really old, it sure isn't net6. I took it from my Window's app probably when it was on Windows 7.

    I'll contact the dotnet runtime team when I feel a bit more confident about what I'm dealing with. The problem with the ILLink documentation is that it is written for people who are already ILLink specialists. It sort of needs one of you guys to explain at the Xamarin.Android level with examples of what it is actually doing. We probably all know what it does, gets rid of unused code, but it's by some magic we don't really understand well. Needs someone like Jonathan Peppers to explain the finer points with examples etc.

    Look at the latest issue #8212 the one above mine - looks like a similar problem. My guess - it is only going to get worse here as more X.A apps get converted to net7, net8 etc.

    Now that I do have a release build log is it of any value to you guys to upload it?

  6. dellis1972 commented on Jul 25, 2023

    @dellis1972
    Contributor

    If its a diagnostic build log then that is always helpful 😃

  7. gmck commented on Jul 26, 2023

    @gmck
    Author

    @dellis1972 .

    Release build log attached

    Buildgmk1.zip

  8. dellis1972 commented on Jul 26, 2023

    @dellis1972
    Contributor

    @gmck thanks for the log, however it does not have the ILLink error in it?

  9. gmck commented on Jul 26, 2023

    @gmck
    Author

    @dellis1972

    Sorry for the misunderstanding.

    That was a release build, but with copyused so it was a successful build. No ILLink error, but a very large aab. I wasn't suggesting that was the way to fix it.

  10. jpobst commented on May 3, 2024

    @jpobst
    Contributor

    This appears to have been fixed in version 7.0.0 of System.Security.Permissions: #8239 (comment).

  11. 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 Buildneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions