Null, reading the file from resources



  • File Reading Code:

        Stream stream;
        string external_js;
    
    using (stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("vldb.js")) ;
    
    using (StreamReader reader = new StreamReader(stream))
    {
         external_js = reader.ReadToEnd();
    }
    

    Makes a mistake.

    Unprocessed System.ArgumentNullException
    mscorlib.dll

    in line

    using (StreamReader reader = new StreamReader(stream))

    The file is resourced with the "External Resource" parameter, but still makes a mistake in the compilation.



  • You know what the operator does. using?
    It cleans resources after use (and, more specifically, causes the method Dispose at the site).

    First design using contains only an empty operator ;♪ And after it's done in the variable. stream There's a cleared object.

    I suggest that the code be replaced by:

    string external_js;
    

    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("vldb.js"))
    using (StreamReader reader = new StreamReader(stream))
    {
    external_js = reader.ReadToEnd();
    }

    And this, I suppose, is just an inaccurate statement:

    ...but still makes a mistake in the compilation.

    This is not the case, the Exceptions are not published in the compilation, they are issued only in the programme process.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2