top of page

Temporärer Dateiname / temporary file name

(alle Versionen/all versions)

Mittwoch, 29. Januar 2020

Deutsch

Fehlermeldung / Situation

Ursache

Lösungsoptionen


English

Error message / situation

Reason

Possible solutions


Deutsch

Fehlermeldung / Situation

Das Abrufen eines neuen temporären Dateinamens mit dem .net-Befehl "System.IO.Path.GetTempFileName" schlägt fehl.

Das Problem ist uns vor allem aufgefallen, wenn mehrere Prozesse auf älteren Maschinen liefen, die neue temporäre Dateinamen benötigen (teils ist es uns auch auf neueren Maschinen aufgefallen).

Quintessenz:

In diversen Situationen hat der .net-Befehl "System.IO.Path.GetTempFileName" keinen neuen temporären Dateinamen zurückgeliefert und das, obwohl die Limits von "System.IO.Path.GetTempFileName" scheinbar nicht überschritten wurden.


Ursache

Es ist bekannt, dass "System.IO.Path.GetTempFileName" Limitierungen aufweist:

MSDN-Dokumentation zu "GetTempFileName"

The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.

Auf älteren Maschinen kann auch ein Bug seitens Microsoft ein Problem bereiten:

The "GetTempFileName" function fails together with an access denied error in Windows 7 or in Windows Server 2008 R2

Verstärkt sind die Probleme jedoch aufgefallen, wenn auf einer Maschine zeitgleich mehrere unterschiedliche Prozesse in schneller Folge den "System.IO.Path.GetTempFileName" Befehl verwendet haben (unabhängig von den zuvor genannten Limitierungen).


Lösungsoptionen

Wir haben in den betreffenden Projekten folgenden Ansatz zum Generieren von temporären Dateinamen verwendet und seit dem keine Probleme mehr:

var tempFileName = System.IO.Path.Combine( System.IO.Path.GetTempPath() , Guid.NewGuid().ToString( "N" ) + "." + "xyz" );

English

Error message / situation

Getting a new temporary filename with the .net command "System.IO.Path.GetTempFileName" fails.

We noticed the problem especially if several parallel processes were running on older machines and those processes request new temporary file names (sometimes we noticed the problem also on newer machines).

Bottom line:

In various situations, the .net command "System.IO.Path.GetTempFileName" did not return new temporary file name, even though the limits of "System.IO.Path.GetTempFileName" were seemingly not exceeded.


Reason

It is known that the command "System.IO.Path.GetTempFileName" got certain limitations:

MSDN documentation of "GetTempFileName"

The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.

On older machines, a Microsoft bug can also cause a problem:

The "GetTempFileName" function fails together with an access denied error in Windows 7 or in Windows Server 2008 R2

However, the problems became more noticeable when several different processes used the command "System.IO.Path.GetTempFileName" in quick succession on a machine at the same time (regardless of the limitations mentioned above).


Possible solutions

We used the following approach to generate temporary file names in the projects concerned and have had no more problems since:

var tempFileName = System.IO.Path.Combine( System.IO.Path.GetTempPath() , Guid.NewGuid().ToString( "N" ) + "." + "xyz" );

bottom of page