How to write in an file in MSIL code

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-05-27T08:37:32Z Indexed on 2010/05/27 8:41 UTC
Read the original article Hit count: 278

Filed under:
|

Hi all,

I have a aspx webpage which uses an assembly mine (which mades a custom authentification). I would like to modify MSIL code (so just with ILDASM/ILASM tools) of my assembly in order to log something in a file.

I have tried to add this at the end of the authentification method of my assembly :

IL_0034:  ldstr      "C:\\path_to_my_website\\log.txt"
IL_0039:  newobj     instance void [mscorlib]System.IO.StreamWriter::.ctor(string)
IL_003e:  stloc.1
IL_003f:  ldloc.1
IL_0040:  ldstr      "test"
IL_0045:  callvirt   instance void [mscorlib]System.IO.TextWriter::Write(string)
IL_004a:  nop
IL_004b:  ldloc.1
IL_004c:  callvirt   instance void [mscorlib]System.IO.TextWriter::Close()
IL_0051:  nop

ILASM does not find any error, and the CLR does not throw any exception at runtime, but the file is not created or modified ! :(

Any idea ?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about msil