Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. why Null value returns & crashes GetManifestResourceStream

why Null value returns & crashes GetManifestResourceStream

Scheduled Pinned Locked Moved C#
xmlquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xchezhd
    wrote on last edited by
    #1

    Hello, Win 7 - 64-bit Windows Form App Did a clean and rebuild on the sln but the program crashes on the StreamReader line. The file is definitely there and in the correct place. Anything wrong with this call?

    public static class BOBroker
    {
    public static string GetClassDefsXml()
    {

        StreamReader classDefStream = new StreamReader(
            typeof(BOBroker).Assembly.GetManifestResourceStream("WCM.BO.ClassDefs.xml"));
    
        // Read the file to a string and close reader
        string \_classDefsXML = classDefStream.ReadToEnd();
        classDefStream.Close();
    
        return \_classDefsXML;
    }
    

    Thanks, DKH

    Richard Andrew x64R L J 3 Replies Last reply
    0
    • X xchezhd

      Hello, Win 7 - 64-bit Windows Form App Did a clean and rebuild on the sln but the program crashes on the StreamReader line. The file is definitely there and in the correct place. Anything wrong with this call?

      public static class BOBroker
      {
      public static string GetClassDefsXml()
      {

          StreamReader classDefStream = new StreamReader(
              typeof(BOBroker).Assembly.GetManifestResourceStream("WCM.BO.ClassDefs.xml"));
      
          // Read the file to a string and close reader
          string \_classDefsXML = classDefStream.ReadToEnd();
          classDefStream.Close();
      
          return \_classDefsXML;
      }
      

      Thanks, DKH

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      what is the error?

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • X xchezhd

        Hello, Win 7 - 64-bit Windows Form App Did a clean and rebuild on the sln but the program crashes on the StreamReader line. The file is definitely there and in the correct place. Anything wrong with this call?

        public static class BOBroker
        {
        public static string GetClassDefsXml()
        {

            StreamReader classDefStream = new StreamReader(
                typeof(BOBroker).Assembly.GetManifestResourceStream("WCM.BO.ClassDefs.xml"));
        
            // Read the file to a string and close reader
            string \_classDefsXML = classDefStream.ReadToEnd();
            classDefStream.Close();
        
            return \_classDefsXML;
        }
        

        Thanks, DKH

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Furthermore, I don't understand why people tend to code several lines to read all of a text file, when there is a single-line solution in

        string allTheFilesText=File.ReadAllText(path);

        :doh:

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        Richard Andrew x64R B 2 Replies Last reply
        0
        • L Luc Pattyn

          Furthermore, I don't understand why people tend to code several lines to read all of a text file, when there is a single-line solution in

          string allTheFilesText=File.ReadAllText(path);

          :doh:

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Luc Pattyn wrote:

          I don't understand why people tend to code several lines to read all of a text file

          With respect, Luc, you once admonished a poster that he was supposed use a loop to read all of a file because "that's what streams are for."

          The difficult we do right away... ...the impossible takes slightly longer.

          L 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            Luc Pattyn wrote:

            I don't understand why people tend to code several lines to read all of a text file

            With respect, Luc, you once admonished a poster that he was supposed use a loop to read all of a file because "that's what streams are for."

            The difficult we do right away... ...the impossible takes slightly longer.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            I'm all in favor of streaming data, especially when the amount of data can be large and there really is no need to have it all in memory at once; streaming then means having an explicit loop of input-process-output, dealing with a fraction of the data at a time. When the amount of data is known to be really small, or there is a need to have it all at once, then one can rightfully decide not to stream, and to read or write all in one go; but then I insist on taking the easiest way to do that, which is by using a single File method. Using a stream class to not stream the data just does not make any sense. StreamReader.ReadToEnd() gets abused over and over, almost as much as String.ToString(). :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            1 Reply Last reply
            0
            • L Luc Pattyn

              Furthermore, I don't understand why people tend to code several lines to read all of a text file, when there is a single-line solution in

              string allTheFilesText=File.ReadAllText(path);

              :doh:

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              It's a resource, not a file, in this case.

              L 1 Reply Last reply
              0
              • B BobJanova

                It's a resource, not a file, in this case.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                My mistake, sorry. :-O

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                1 Reply Last reply
                0
                • X xchezhd

                  Hello, Win 7 - 64-bit Windows Form App Did a clean and rebuild on the sln but the program crashes on the StreamReader line. The file is definitely there and in the correct place. Anything wrong with this call?

                  public static class BOBroker
                  {
                  public static string GetClassDefsXml()
                  {

                      StreamReader classDefStream = new StreamReader(
                          typeof(BOBroker).Assembly.GetManifestResourceStream("WCM.BO.ClassDefs.xml"));
                  
                      // Read the file to a string and close reader
                      string \_classDefsXML = classDefStream.ReadToEnd();
                      classDefStream.Close();
                  
                      return \_classDefsXML;
                  }
                  

                  Thanks, DKH

                  J Offline
                  J Offline
                  JimmeP
                  wrote on last edited by
                  #8

                  Have you added the file to the project as an embedded resource? Best regards

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups