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(); } 

Gives an error message

Unhandled exception of type "System.ArgumentNullException" in mscorlib.dll

in line

 using (StreamReader reader = new StreamReader(stream)) 

The file is in the resources and with the parameter "Embedded resource", but it still gives an error when compiling.

  • after the first using it is necessary to remove; - Stack

1 answer 1

Do you know what the using statement does?
It clears resources after use (or rather, calls Dispose on an object).

The first using construct contains only an empty statement ; . And after its execution in the stream variable is already cleaned object.

I propose to replace the code with:

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

And this, I believe, is simply an inaccurate statement:

... but still gives an error when compiling.

So it can not be, Exception'y when compiled is not issued, they are issued only in the process of the program.