-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assembly load error in Android app referencing another project referencing a DLL assembly #10154
Assembly load error in Android app referencing another project referencing a DLL assembly #10154
Comments
Hi @ist-22. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Are you sure this is a MAUI (The UI Framework) issue, or an issue with whatever device you're trying to target? Did you try doing this with a |
I don't think it's a device/target issue (if this implies architecture) since adding a reference to the assembly in the top MAUI app can act as a workaround. However, you are right about the MAUI/UI framework question and pointing to the Android project. Yes the issue happens in a project created with |
Could you please attach a project that exhibits this scenario? |
Hi @ist-22. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@jonpryor -- Updated the issue description with the repo link |
@jonpryor @jonathanpeppers thoughts? |
Does this problem go away if you use |
I have same issue with dynamic assembly loading.. |
@jonathanpeppers No, still happens. |
Can you update the repro? https://github.com/ist-22/10154-repro |
Hi @ist-22. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@jonathanpeppers -- repro updated. |
Should we move this to the Android repo? Does this happen with iOS or Windows? Or even a plain old net7.0 console app? |
It doesn't happen with a Windows or console app -- can't test iOS. |
In VS Windows, the above repro doesn't even build for me, unless I change <Reference Include="lib2">
<HintPath>..\lib2\bin\$(Configuration)\net7.0\lib2.dll</HintPath>
</Reference> To this instead: <ItemGroup>
<ProjectReference Include="..\lib2\lib2.csproj" />
</ItemGroup> If you have a If you are hitting this situation with a NuGet package, we can make suggestions on what to do there. Let me know, thanks! |
@jonathanpeppers The scenario in this issue is about a case where the user doesn't have access to the source code of the external library (i.e. lib2 in the repro), so adding a project reference is really not an option. I guess your build failed since lib2 hadn't been built first (this was in the original message but sorry if it wasn't clear enough). The source code of lib2 in the repro is not very relevant to the issue itself and it is only there so that someone who runs the repro doesn't have to call a random DLL. As I mentioned, this problem doesn't happen with a Windows or console app, also (as long as lib2 has been compiled) IntelliSense is also fine. In all cases (Windows, console and even Android) lib2.dll is copied into bin so I suspect it somehow is not packed into the APK properly. |
@ist-22 does the same problem happen in a console app? You would publish it such as So your options are:
Does that make sense? Let me know if I missed something here. |
Here is another case we saw the same behavior in the .NET SDK: #11364 (comment) |
@jonathanpeppers it does not happen in a console or Windows app, and Also:
I appreciate the options/workarounds (I believe the second one is what I suggested as a workaround in my original message) but considering that it works fine with other project types, it makes me think that the expected behaviour is that assembly references inside referenced projects should be OK. |
Can you share the console app you made? Is it on a branch of the original repro? Thanks. |
Repro updated;
|
Ok, I tracked this down to: In the console app we see: But in the Android app we see: Putting this in <PropertyGroup>
<_ResolveReferenceDependencies>true</_ResolveReferenceDependencies>
</PropertyGroup> Still figuring out what these settings are for, and how we can fix this. |
It appears we need this change in <Target Name="_ComputeFilesToPublishForRuntimeIdentifiers"
- DependsOnTargets="_FixupIntermediateAssembly;ResolveReferences;ComputeFilesToPublish;$(_RunAotMaybe)"
+ DependsOnTargets="BuildOnlySettings;_FixupIntermediateAssembly;ResolveReferences;ComputeFilesToPublish;$(_RunAotMaybe)"
Returns="@(ResolvedFileToPublish)"> The I need to write a regression test for this, but will have a PR shortly. |
Fixes: dotnet/maui#10154 If you have a solution setup with: * `ApplicationA` project reference -> * `LibraryB` reference -> * `LibraryC` The app will crash at runtime, due to a missing `LibraryC.dll`. You can solve the problem by changing `@(Reference)` to a `@(ProjectReference)`. However, it appears the same situation works in a .NET 7 self-contained console app: dotnet publish --self-contained -r win-x64 ... ls -n .\bin\Debug\net7.0\win-x64\publish\LibraryC.dll LibraryC.dll The underlying issue appears to be: https://github.com/dotnet/msbuild/blob/a2490dd3f78cce4abc8f9e6f1b5268437332818f/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2322 In the console app, `$(BuildingProject)` is `true` and `$(_FindDependencies)` is empty. In the android app, `$(BuildingProject)` is `false` and `$(_FindDependencies)` is `false`. It appears the `BuildOnlySettings` target *should* be running in Android apps when we do an "inner" build per `$(RuntimeIdentifier)`. Simply adding a dependency for the `_ComputeFilesToPublishForRuntimeIdentifiers` MSBuild target solves this issue. This likely might fix other issues, such as: dotnet/maui#11364 I added a test for this scenario.
) Fixes: dotnet/maui#10154 Context? dotnet/maui#11364 If you have a solution setup with: * `ApplicationA.csproj` has a `@(ProjectReference)` to `LibraryB.csproj`. * `LibraryB.csproj` which has a `@(Reference)` to `LibraryC.dll`, built by- * `LibraryC.csproj` The app will crash at runtime, due to a missing `LibraryC.dll`. The workaround is for `LibraryB.csproj` to use `@(ProjectReference)` to `LibraryC.csproj` instead of `@(Reference)` to `LibraryC.dll`. However, it appears the same situation works in a .NET 7 self-contained console app: % dotnet publish --self-contained -r win-x64 … % ls -1 .\bin\Debug\net7.0\win-x64\publish\LibraryC.dll LibraryC.dll The underlying issue appears to be due to [`$(_FindDependencies)`][0]: <_FindDependencies Condition="'$(BuildingProject)' != 'true' and '$(_ResolveReferenceDependencies)' != 'true'">false</_FindDependencies> In the console app, `$(BuildingProject)`=true and `$(_FindDependencies)` is empty. In the Android app, `$(BuildingProject)`=false and `$(_FindDependencies)` is `false`. It appears that the `BuildOnlySettings` target *should* be running in Android apps when we do an "inner" build per `$(RuntimeIdentifier)`. Simply updating `_ComputeFilesToPublishForRuntimeIdentifiers` so that the `BuildOnlySettings` target is in `DependsOnTargets` fixes this. However, this also causes satellite assemblies to now be automatically found by the .NET SDK. Update `@(_AndroidResolvedSatellitePaths)` so that `@(ReferenceSatellitePaths)` is only included on Classic builds, preventing duplicate entries. [0]: https://github.com/dotnet/msbuild/blob/a2490dd3f78cce4abc8f9e6f1b5268437332818f/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2322
…tnet#7642) Fixes: dotnet/maui#10154 Context? dotnet/maui#11364 If you have a solution setup with: * `ApplicationA.csproj` has a `@(ProjectReference)` to `LibraryB.csproj`. * `LibraryB.csproj` which has a `@(Reference)` to `LibraryC.dll`, built by- * `LibraryC.csproj` The app will crash at runtime, due to a missing `LibraryC.dll`. The workaround is for `LibraryB.csproj` to use `@(ProjectReference)` to `LibraryC.csproj` instead of `@(Reference)` to `LibraryC.dll`. However, it appears the same situation works in a .NET 7 self-contained console app: % dotnet publish --self-contained -r win-x64 … % ls -1 .\bin\Debug\net7.0\win-x64\publish\LibraryC.dll LibraryC.dll The underlying issue appears to be due to [`$(_FindDependencies)`][0]: <_FindDependencies Condition="'$(BuildingProject)' != 'true' and '$(_ResolveReferenceDependencies)' != 'true'">false</_FindDependencies> In the console app, `$(BuildingProject)`=true and `$(_FindDependencies)` is empty. In the Android app, `$(BuildingProject)`=false and `$(_FindDependencies)` is `false`. It appears that the `BuildOnlySettings` target *should* be running in Android apps when we do an "inner" build per `$(RuntimeIdentifier)`. Simply updating `_ComputeFilesToPublishForRuntimeIdentifiers` so that the `BuildOnlySettings` target is in `DependsOnTargets` fixes this. However, this also causes satellite assemblies to now be automatically found by the .NET SDK. Update `@(_AndroidResolvedSatellitePaths)` so that `@(ReferenceSatellitePaths)` is only included on Classic builds, preventing duplicate entries. [0]: https://github.com/dotnet/msbuild/blob/a2490dd3f78cce4abc8f9e6f1b5268437332818f/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2322
…ce)` (dotnet#7642)" This reverts commit 22f2001. .NET MAUI is hitting a build failure such as: Unable to open file 'obj\Release\net8.0-android\android-x64\aot\x86_64\Microsoft.Maui.Controls.resources\temp.s': Permission denied In 22f2001, we began passing satellite assemblies to the AOT compiler, on accident? I am unsure how a test in xamarin-android didn't catch this, but it may be something that only happens via a `@(ProjectReference)` as occurred in .NET MAUI. For now, let's revert the change and revisit later. We should reopen dotnet/maui#10154 after this is merged.
…ce)` (#7642)" (#7726) This reverts commit 22f2001. .NET MAUI is hitting a build failure such as: Unable to open file 'obj\Release\net8.0-android\android-x64\aot\x86_64\Microsoft.Maui.Controls.resources\temp.s': Permission denied In 22f2001, we began passing satellite assemblies to the AOT compiler, on accident? I am unsure how a test in xamarin-android didn't catch this, but it may be something that only happens via a `@(ProjectReference)` as occurred in .NET MAUI. For now, let's revert the change and revisit later. We should reopen dotnet/maui#10154 after this is merged.
The first attempt to fix this in xamarin/xamarin-android/main didn't work out. (It caused a different issue) Reopening to look into this further. |
Fixes: dotnet/maui#10154 This reverts commit c1efcb5. I added `.resx` files to the new test, but I'm not seeing the error we saw in dotnet/maui: Unable to open file 'obj\Release\net8.0-android\android-x64\aot\x86_64\Microsoft.Maui.Controls.resources\temp.s': Permission denied
Context: https://github.com/dotnet/msbuild/blob/c75672a6e7387bc5c1f99c166e9277351144b14c/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2327 Fixes: dotnet/maui#10154 This partially reverts c1efcb5. Previously, we removed this change because it broke .NET MAUI's build with: Unable to open file 'obj\Release\net8.0-android\android-x64\aot\x86_64\Microsoft.Maui.Controls.resources\temp.s': Permission denied The problem being that the .NET SDK was placing satellite assemblies in the `@(ResolvedFileToPublish)` item group. Let's apply our change from before, but also set `$(ResolveAssemblyReferencesFindRelatedSatellites)` to `false` for our "inner build" per `$(RuntimeIdentifier)`. This solves the original issue for dotnet/maui#10154 without changing behavior of satellite assemblies. I added `.resx` files in our new test, and assert that satellite assemblies make to apps for good measure.
) Context: https://github.com/dotnet/msbuild/blob/c75672a6e7387bc5c1f99c166e9277351144b14c/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2327 Fixes: dotnet/maui#10154 This partially reverts c1efcb5. Previously, we removed this change because it broke .NET MAUI's build with: Unable to open file 'obj\Release\net8.0-android\android-x64\aot\x86_64\Microsoft.Maui.Controls.resources\temp.s': Permission denied The problem being that the .NET SDK was placing satellite assemblies in the `@(ResolvedFileToPublish)` item group. Let's apply our change from before, but also set `$(ResolveAssemblyReferencesFindRelatedSatellites)` to `false` for our "inner build" per `$(RuntimeIdentifier)`. This solves the original issue for dotnet/maui#10154 without changing behavior of satellite assemblies. I added `.resx` files in our new test, and assert that satellite assemblies make to apps for good measure.
Description
If a MAUI Android project has a reference to a .NET Standard project in the same solution; and the .NET Standard project has a reference to a .NET Standard assembly, calling a code that eventually calls a code in the assembly fails to load the assembly.
Steps to Reproduce
i.e. The reference chain: MAUI csproj --> .NET Std. csproj --> .NET Std. DLL
Link to public reproduction project repository
https://github.com/ist-22/10154-repro
app has a project reference to lib1
lib1 has an assembly reference to lib2 (so lib2 needs to be compiled first)
Version with bug
6.0.400
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11
Did you find any workaround?
Add the .NET Standard assembly reference also to the MAUI app project.
In the repository uncomment lines 14..18 in app/app.csproj -- this adds an assembly reference to lib2 in app
Relevant log output
No response
The text was updated successfully, but these errors were encountered: