xamarin-macios
xamarin-macios copied to clipboard
UIImage.FromFile returns null even the image exists in the resource folder
Steps to Reproduce
- Create a .net 8 ios project
- Add .net 8 ios class library project and add a image to the resources folder
- Add reference of this library project to the main ios project
- add <UseMaui>true</UseMaui> in both csporj file
- In the class library project try to use UiImage.FromFile for the image you have added
Expected Behavior
UIImage.FromFile should return the image
Actual Behavior
UIImage.FromFile return null
Environment
Version information
Visual studio 2022 in Windows Paired to sonma mac with xcode 15 installed
This does not happen in Visual Studio for Mac.
Example Project (If Possible)
Workaround Installing Maui nuget pacakges and removing the UseMaui tag in the library project fixed the problem. this way we can use the native embedding.
Your project works fine for me, both in the simulator and on device.
Can you check if the image is in the app bundle (the bin/Debug/net8.0-ios/ios-*/iOSAppImageTest.app/Backgrounds directory) after the build?
Also, could you get a binlog from the build and attach it here?
@rolfbjarne Thank you for the reply.
Can you check if the image is in the app bundle (the
bin/Debug/net8.0-ios/ios-*/iOSAppImageTest.app/Backgroundsdirectory) after the build?
It did not end up there. It is missing. This is happening only in Visual studio 202 for windows.
I will post the binlogs soon.
I tried fresh install Visual Studio 2022 in WIndows and i am still facing the issues
Here are hte binlogs iOSAppImageTest_Debug_AnyCPU_Build_2023-11-27T20_11_27.5039944+00_00.zip
OK, I can reproduce, I'll have a look.
The reason for the failure is that the library project is built locally, even if a remote connection is established.
Binlog: CentralNode_devenv_PID=13216_x64_BuildManager_Default.binlog.zip
@emaf @mauroa is that the expected behavior (to build a referenced library project with IsMacEnabled=false, even if a remote connection is available)?
The reason for the failure is that the library project is built locally, even if a remote connection is established.
Just to expand a bit: the way this is supposed to work is:
- The library project's PackLibraryResources target is executed, embedding the resources into the library assembly.
- The executable project's UnpackLibraryResources target will then detect, unpack and remove any such resources from any referenced libraries.
The problem is that 1. doesn't happen, because:
After talking with @emaf and @mauro, the current behavior is indented (referenced library projects aren't built remotely) because otherwise the build speed would suffer greatly for everybody for the relatively few projects that would not build correctly.
One option we discussed was to add support for a MSBuild property that could be added to the library project to indicate that it needs to build remotely.
Another option is to pack the library resources on the Windows machine without the need for a Mac. This would probably be the best option if we could make it work, but it's a much bigger effort (see https://github.com/xamarin/xamarin-macios/issues/19028).
Same issue as OP, slightly different situation. .Net Maui app in .Net 8, Visual Studio 2022 for Windows (17.8.3). Same symptoms, my file is located in Resources/Images yet UIImage.FromFile returns null. Same call works fine on the dotnet_bot.png file, which displays in the simulator.
C:\Dev\LaundryWatcher\LaundryWatcher\bin\Debug\net8.0-ios\ iossimulator-arm64 \LaundryWatcher.app does have the file I need, but C:\Dev\LaundryWatcher\LaundryWatcher\bin\Debug\net8.0-ios\ iossimulator-x64 \LaundryWatcher.app does not have the file.
I note that the PNG files I see in these folders are all zero-length anyway, including the dotnet_bot.png which FromFile appears to find nonetheless.
This would be a good one to fix. I need it for drag images.
@billn6 does the missing image come from a referenced library project, or is it included in the executable project?
Hi @rolfbjarne - It is included in the executable project itself. Pretty stock .Net Maui app project with the image in question in Resources/Images.
Hi @rolfbjarne - It is included in the executable project itself. Pretty stock .Net Maui app project with the image in question in Resources/Images.
OK, then it's a different problem than the one reported here. Could you file a new issue and attach a test project we can use to reproduce the problem?