2 years ago

#74294

test-img

Navaneeth

NSBundle.MainBundle.PathForResource returns null for png image included in the Resources folder

I have a Xamarin.Forms class library project that I refer to in a Xamarin.Forms application project. In the iOS project of the class library, I have included a png image in the Resources folder and set its "Build Action" to BundleResource.

When I try to load this image file in the library project using the below code, I get null value.

string imagePath = NSBundle.MainBundle.PathForResource("ImageFileName", "png");

I had also tried setting the "Copy To Output" property of the image file to all available values (Do not copy, Copy always, Copy if newer). No matter which value is set, the path is returned as null.

I am using the iOS 15.0 simulator. I navigated to the bundle location of the application in the simulator's location in the Mac. I could not see the image file in the application bundle.

Is there any solution to this problem?

xamarin.forms

xamarin.ios

0 Answers

Your Answer

Accepted video resources