0

I am trying to follow this thread:
How to read embedded resource text file

However I am not able to make it work.

Goal: From a txt file that it is embed on the project which has a list of names. Read all the entries, store them on an array list of strings.

Current set up of the file: enter image description here

Current code based on the linked thread:

            var assembly = Assembly.GetExecutingAssembly();

            using (Stream stream = assembly.GetManifestResourceStream(TownGame.Properties.Resources.m_names))
            using (StreamReader reader = new StreamReader(stream))
            {
                string result = reader.ReadToEnd();
            }

Which is the best way to fill out:

public string[] names_list = new string[20];  //list of names

With the content of the embed m_names.txt file?


Changed the original code for this: This is in a debugging, The streamer is NULL still the file has content as shown with the mouse over the n_names.txt

enter image description here

Community
  • 1
  • 1
dracebus
  • 21
  • 7
  • 1
    Why not use what you're getting with your StreamReader..? As its name suggests, it's reading the file. So instead of reading it all at one with `ReadToEnd`, read it line by line and put that in you array. – Broots Waymb Nov 07 '16 at 16:31
  • sorry not sure how to do it, the problem is that: using (StreamReader reader = new StreamReader(stream)) is not working at all, I am not sure how to use properly, the getManifiestResourceStream @DangerZone – dracebus Nov 07 '16 at 16:47
  • What do you mean it is not working? Are you getting an error or exception? What is happening? – Broots Waymb Nov 07 '16 at 16:50
  • An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll Additional information: Value cannot be null. it is failing this: Stream stream = assembly.GetManifestResourceStream(TownGame.Properties.Resources.m_names) any idea why? – dracebus Nov 07 '16 at 17:03
  • If you debug the program, at that line is `TownGame.Properties.Resou‌​rces.m_names` null? – Broots Waymb Nov 07 '16 at 17:11
  • Please share the exception stack trace and also show on which line this occurs. – Mohd Ismail Siddiqui Nov 07 '16 at 17:18
  • changed the original code a little bit, still having problem with streamer as null – dracebus Nov 07 '16 at 18:43

0 Answers0