locked
GetManifestResourceStream stopped working in Xamarin Studio 5.9.0? RRS feed

  • Question

  • User109396 posted

    I just took the latest downloads:

    • Mono Framework MDK 4.0.0.143
    • Xamarin Studio 5.9.0
    • Xamarin.Android 5.1.0.115
    • Xamaring.iOS 8.10.0.267

    I have this code, which was working previously: private void LoadGemsFromFile(string resource) { index = -1; Assembly assembly = this.GetType ().GetTypeInfo ().Assembly;

                        // TODO:  Need to read in a device agnostic fashion
                    // http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/files/
                    using (Stream stream = assembly.GetManifestResourceStream(resource)) {
                        using (StreamReader reader = new StreamReader (stream)) {
                            string line;
                            while ((line = reader.ReadLine ()) != null) {
                                index++;
                                string[] items = line.Split (DELIMITER, 2, StringSplitOptions.None);
                                if (items.Length > 0) {
                                    GemRecord record = new GemRecord ();
                                    record.Message = items [0].Trim (TRIM_CHARS);
                                    if (items.Length > 1) {
                                        record.Author = items [1].Trim (TRIM_CHARS);
                                    }
                                    record.GemIndex = index;
                                    theList.Add (record);
                                }
                            }
                        }
                    }
                }
    

    where resource = "HelloForms.GemPack1.txt"

    This used to work but now assembly.GetManifestResourceStream returns null.

    "HelloForms" is a PCL which references GemsModel, which is a shared project.

    In GemsModel, the structure is: GemsModel GemPacks GemPack1.txt

    I double checked that Build Action is still EmbeddedResource for GemPack1.txt.

    Can anyone tell me what is going wrong and how to fix it?

    Thursday, April 30, 2015 6:20 PM

Answers

  • User68062 posted

    The guy on our team who was first to update did some poking around. If you run 'monodis --manifest' on the DLL or EXE containing your resource, you'll see that the path of the resource has changed. At least on iOS, it now has a .Resources component in its path. For now, you'll need to update the name of your resource accordingly.

    We don't know if this is a bug in the Xamarin update, or if maybe we're doing something wrong with how we determined the correct name to use in the first place.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 4, 2015 6:40 PM

All replies

  • User68062 posted

    We are seeing this as well.

    Friday, May 1, 2015 6:39 PM
  • User109396 posted

    Update: I uploaded two projects, one built on Xamarin 5.8.3, then the same project rebuilt on Xamarin 5.9. If the project is not rebuilt on Xamarin 5.9 it runs just fine from Xamarin 5.9. But once it has been rebuilt in 5.9 it won't run. The exception is thrown from line 56 in the StartPage.cs file because assembly.GetManifestResourceStream(resource) returned null.

    Saturday, May 2, 2015 9:48 PM
  • User109396 posted

    Well, apparently I can't upload the zip file.

    Saturday, May 2, 2015 9:48 PM
  • User109396 posted

    The solution in TestHelloForms.zip works if built on Xamarin 5.8.3, but not if build on Xamarin 5.9 (trying to upload using Chrome instead of Safari)

    Monday, May 4, 2015 5:01 PM
  • User68062 posted

    The guy on our team who was first to update did some poking around. If you run 'monodis --manifest' on the DLL or EXE containing your resource, you'll see that the path of the resource has changed. At least on iOS, it now has a .Resources component in its path. For now, you'll need to update the name of your resource accordingly.

    We don't know if this is a bug in the Xamarin update, or if maybe we're doing something wrong with how we determined the correct name to use in the first place.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, May 4, 2015 6:40 PM
  • User109396 posted

    You are right Josh. Previously it worked if I didn't have the folder name in the path of the resource (my folder name is not Resource), but now it requires the folder name. I think that it is complicated because I am using Xamarin.Forms in a PCL, but it is accessing the files in a Shared Project.

    According to Charles Petzold's book: However, if you put an embedded resource into an SAP, the folder name is not part of the resource ID. It’s basically ignored. (This treatment of the folder name might change in the future.)

    He wasn't exactly referring to my case, but it seems that the treatment of the folder name has changed.

    Thank you Josh for following up!

    Monday, May 4, 2015 9:25 PM