exception streamwriter.writeline

Hi all, i dont know why this exception occurs can some body throw light

tia

sahridhayan

i checked the following, but still error occurs

1. i checked whether the string value is null or empty string, if so i add a default "NO message"

2. i am doing a concatenation of System.Environment.NewLine inside my logger code is below.

wSW.Write(message + System.Environment.NewLine);

Message: Server was unable to process request. --->

System.ArguementOutofRangeException

Count cannot be less than zero.

Parameter name: count

at System.String.CopyTo(Int32 sourceIndex,Char[] destination,Int32 destinationIndex,Int32 Count)

at System.IO.StreamWriter.WriteLine(String value)

at SI.Logger.WebLogger.WriteLine(String messag)

-----

----



Answer this question

exception streamwriter.writeline

  • Bilberry71

    Please show some more code. How do you create wSW. What calls do you execute on wSW

    --
    SvenC


  • jmurray_mi

    Hmmm, You know what This code works 100% smooth I tested it and it worked fine on my computer using .Net 2.0

    string message = "Hello";

    FileStream fs = new FileStream("C:\\hello.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);

    StreamWriter wSW = new StreamWriter(fs);

    wSW.BaseStream.Seek(0, SeekOrigin.End);

    wSW.Write(message + System.Environment.NewLine);

    wSW.Close();

    fs.Close();

    Try the exact copy in your application and see what happens. I did not mody your code except hardcoded the file path!

    Best Regards,

    Rizwan!



  • Aaron Leiby

    Hi

    Apologise for the wrong stack trace, please find the correct one here

    let me know you need more info

    Thank you

    sahridhayan

    Message: Server was unable to process request. --->

    System.ArguementOutofRangeException

    Count cannot be less than zero.

    Parameter name: count

    at System.String.CopyTo(Int32 sourceIndex,Char[] destination,Int32 destinationIndex,Int32 Count)

    at System.IO.StreamWriter.Write(String value)

    at SI.Logger.WebLogger.WriteLine(String messag)

    -----

    ----


  • search and deploy

    FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);

    wSW = new StreamWriter(fs);

    wSW.BaseStream.Seek(0, SeekOrigin.End);

    wSW.Write(message + System.Environment.NewLine);

    Hope it helps.

    regs

    sahridhayan


  • marina B.

    Please show a bit of surrounding code. You use the Write method but the stack trace shows WriteLine. Are you sure your code fits the exception stack trace

    --
    SvenC


  • nishanttheone

    try to pass string by using string.format function .

    Like first format string like thsi

    string mess = string.format("No messge {0}",System.Environment.NewLine);

    wSW.Write(mess);

    Try this and let me know



  • vtortola

    Bizarre problem. I poked around with Reflector a bit and see StreamWriter.Write using String.Copy to break up the string you write into chunks that fit its buffer. String.Copy would fail if the buffer pointer is past the end-of-buffer. I don't see how that could happen. All I can suggest is to play around with the StreamWriter constructor and use the StreamWriter(stream, Encoding, Int32) version to change the buffer size...


  • exception streamwriter.writeline