none
sn.exe creating leftover .tmp files?

    Question

  • We've seen on two machines here, using sn.exe to re-sign a delay-signed assembly (sn.exe -R <filename> <private.key>) creates a tmp*.tmp file in the system's %TEMP% folder that doesn't get deleted. The temp file filename expands with a 4 digit hex number in it, so once you hit 65536 of them, .Net is unable to create more and many system calls start failing (such as Path.GetTempFileName ()).

    Has anyone else seen this?
    Thursday, February 14, 2008 6:02 PM

All replies

  • Could you please clarify the version of .net framework you're talking about?

    --The temp file filename expands with a 4 digit hex number in it, so once you hit 65536 of them, .Net is unable to create more and many system calls start failing (such as Path.GetTempFileName ()
    Could you please clarify what exactly you mean by this text?

    Monday, February 18, 2008 5:55 AM
  • Whoops, I'd completely forgotten to paste in the version. Sn.exe Version 2.0.50727.42.

    What I end up with is something like the following:
    tmp.tmp
    tmp1.tmp
    tmp2.tmp
    through tmpFFFF.tmp, at which point the routine can't create any more tmp files and fails. They're 0-byte files.


    Tuesday, February 19, 2008 9:30 PM
  • --.Net is unable to create more and many system calls start failing (such as Path.GetTempFileName ()).

    Could you please clarify what exactly you mean by this?

    And I've tested the sn.exe using the command switches like you said, but I cannot reproduce the problem. Is there anymore information you can provide?
    Wednesday, February 20, 2008 8:23 AM
  • Here's what I'm seeing:

     

     

    Code Snippet

    C:\Documents and Settings\cweiss\Local Settings\Temp>dir tmp*.tmp
     Volume in drive C has no label.
     Volume Serial Number is FCAA-E2ED

     Directory of C:\Documents and Settings\cweiss\Local Settings\Temp

    File Not Found

    C:\Documents and Settings\cweiss\Local Settings\Temp>sn -R C:\delay-signed-file.dll C:\mykey.snk

    Microsoft (R) .NET Framework Strong Name Utility  Version 2.0.50727.42
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Assembly 'C:\delay-signed-file.dll' successfully re-signed

    C:\Documents and Settings\cweiss\Local Settings\Temp>dir tmp*.tmp
     Volume in drive C has no label.
     Volume Serial Number is FCAA-E2ED

     Directory of C:\Documents and Settings\cweiss\Local Settings\Temp

    02/21/2008  10:30 AM                 0 Tmp2730.tmp
                   1 File(s)              0 bytes
                   0 Dir(s)  47,482,695,680 bytes free

    C:\Documents and Settings\cweiss\Local Settings\Temp>


     

     

     

    If I repeat that a whole lot of times, I'll get the files Tmp.tmp through TmpFFFF.tmp.

    On the advice of one of the folks in the NANT forum (I ran across this when a NANT script entered a race condition and signed all the assemblies in the source path), they suggested I see what happens when I try a call to Path.GetTempFileName() and see what happens. I grabbed a sample from MSDN:

    Code Snippet

    string path1 = @"c:\temp\MyTest.txt";

    string path2 = @"c:\temp\MyTest";

    string path3 = @"temp";

    if (Path.HasExtension(path1))

    {

    Console.WriteLine("{0} has an extension.", path1);

    }

    if (!Path.HasExtension(path2))

    {

    Console.WriteLine("{0} has no extension.", path2);

    }

    if (!Path.IsPathRooted(path3))

    {

    Console.WriteLine("The string {0} contains no root information.", path3);

    }

    Console.WriteLine("The full path of {0} is {1}.", path3, Path.GetFullPath(path3));

    Console.WriteLine("{0} is the location for temporary files.", Path.GetTempPath());

    Console.WriteLine("{0} is a file available for use.", Path.GetTempFileName());

     

     

    and ran that after filling the temp folder:


    Code Snippet

    C:\pathgettempfilenametest.exe
    c:\temp\MyTest.txt has an extension.
    c:\temp\MyTest has no extension.
    The string temp contains no root information.

    Unhandled Exception: System.IO.IOException: The file exists.

       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.__Error.WinIOError()
       at System.IO.Path.GetTempFileName()
       at Test.Main() in C:\pathgettempfilenametest\Program.cs:line 28

     

     

    What other information would help in troubleshooting this?

    Thursday, February 21, 2008 6:43 PM
  • Hi,

    The tmp files may sometimes persist after the application that has created them terminates. This is normally because the application itself is unable to delete the files as they are locked by other processes. This can happen in following scenarios:

    1. You have a roaming profile which is synchronized regularly.
    2. Indexing or search service (windows desktop seach) is running.
    3. Anti-virus is scanning and locking the file.

    I have ran into similar problem when deleting my own temp files so maybe sn.exe is having same issues in your environment.

    HTH
    Imran
    Friday, February 22, 2008 10:12 AM