GetManifestResourceStream stopped working in Xamarin Studio 5.9.0?

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?

Best Answer

Answers

  • Josh.1093Josh.1093 USUniversity ✭✭

    We are seeing this as well.

  • SusandeJong.5231SusandeJong.5231 USMember ✭✭

    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.

  • SusandeJong.5231SusandeJong.5231 USMember ✭✭

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

  • SusandeJong.5231SusandeJong.5231 USMember ✭✭

    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)

  • SusandeJong.5231SusandeJong.5231 USMember ✭✭

    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!

Sign In or Register to comment.