why Null value returns & crashes GetManifestResourceStream
-
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
-
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
what is the error?
The difficult we do right away... ...the impossible takes slightly longer.
-
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
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
-
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
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.
-
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.
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 asString.ToString()
. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
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
-
My mistake, sorry. :-O
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
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