If this is happening to you on a production environment or with an app that you can’t change, the quick fix is to empty the Temp folder.
Depending on the user that is running the application you should either
- Empty
C:WindowsTemp
(for IIS or services running underLocalSystem
account) - Or
%temp%
for locally logged on users (which for me isC:UsersMyUserNameAppDataLocalTemp
).
On the other side, if your own code is throwing this, and you want to prevent this from happening ever again:
- Do not use System.IO.Path.GetTempFileName()!
GetTempFileName()
is a wrapper of the two decades old Win32 Api. It generate file names that will very easily collide. It circumvents those collitions by heavily looping on the file system, iterating possible file names from "%temp%tmp0000.tmp"
to "tmpFFFF.tmp"
and skipping already existing ones. This is a I/O intensive, slow, and frankly terrible algorithm. Also using only 4 hex characters is what makes the artificial limit of 65536 files before failing.
The alternative is to generate file names that will not collide. For example, lets reuse GUID's
logic: 32 hex digits will almost never collide.
private string GetTempFileName()
{
return Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
}
// Sample: c:WindowsTemp2e38fe87-f6bb-4b0d-90b3-2d07016324c1
This expands the limit from 65k to 4k millions files max (theoretically)… Of course, having leaked 65k files is already terrible, so…
- Do not leak temp files!
Double check your app for all happy and unhappy paths (like unexpected exceptions). Ensure it’s correctly disposing each FileStream and deleting the temp files in Finally blocks .
- Clean the temp folder
Clean it now, and educate the system administrator to clean it periodically, because you can’t trust every app in the wild.
On my own servers I would automate this task using:
- For global WindowsTemp
schtasks /Create /TR "cmd /c call DEL /F /S /Q %^TEMP%" /TN "Delete Global Temp Files" /sc WEEKLY /ST 12:00 /ru system
- For current user:
schtasks /Create /TR "cmd /c call DEL /F /S /Q %^TEMP%" /TN "Delete %username% Temp Files" /sc WEEKLY /ST 12:00
Содержание
- System.IO.IOException: «The file exists» when using System.IO.Path.GetTempFileName() — resolutions?
- The «GetTempFileName» function fails together with an access denied error in Windows 7 or in Windows Server 2008 R2
- Symptoms
- Cause
- Resolution
- Hotfix information
- Prerequisites
- Restart requirement
- Hotfix replacement information
- File information
- System.IO.IOException: The file exists #2305
- Comments
- ##[section]Starting: Publish Artifact: Artifacts
- Task : Publish Build Artifacts Description : Publish build artifacts to Azure Pipelines/TFS or a file share Version : 1.142.2 Author : Microsoft Corporation Help : More Information
- GetTempFileName function (winbase.h)
- Syntax
- Parameters
- Return value
- Remarks
- Blog JTB FlexReport the FlexNet/FLEXlm license report and monitoring tool
- About
- Software
- Resources
- Subscribe To
- Wednesday, December 17, 2008
- System.IO.IOException: The file exists and GetTempFileName solution and explanation
System.IO.IOException: «The file exists» when using System.IO.Path.GetTempFileName() — resolutions?
If this is happening to you on a production environment or with an app that you can’t change, the quick fix is to empty the Temp folder.
Depending on the user that is running the application you should either
- Empty C:WindowsTemp (for IIS or services running under LocalSystem account)
- Or %temp% for locally logged on users (which for me is C:UsersMyUserNameAppDataLocalTemp ).
On the other side, if your own code is throwing this, and you want to prevent this from happening ever again:
- Do not use System.IO.Path.GetTempFileName()!
GetTempFileName() is a wrapper of the two decades old Win32 Api. It generate file names that will very easily collide. It circumvents those collitions by heavily looping on the file system, iterating possible file names from «%temp%tmp0000.tmp» to «tmpFFFF.tmp» and skipping already existing ones. This is a I/O intensive, slow, and frankly terrible algorithm. Also using only 4 hex characters is what makes the artificial limit of 65536 files before failing.
The alternative is to generate file names that will not collide. For example, lets reuse GUID’s logic: 32 hex digits will almost never collide.
This expands the limit from 65k to 4k millions files max (theoretically). Of course, having leaked 65k files is already terrible, so.
- Do not leak temp files!
Double check your app for all happy and unhappy paths (like unexpected exceptions). Ensure it’s correctly disposing each FileStream and deleting the temp files in Finally blocks .
- Clean the temp folder
Clean it now, and educate the system administrator to clean it periodically, because you can’t trust every app in the wild. On my own servers I would automate this task using:
schtasks /Create /TR «cmd /c call DEL /F /S /Q %^TEMP%» /TN «Delete Global Temp Files» /sc WEEKLY /ST 12:00 /ru system
schtasks /Create /TR «cmd /c call DEL /F /S /Q %^TEMP%» /TN «Delete %username% Temp Files» /sc WEEKLY /ST 12:00
As I mentioned in my last comment I think your only safe way to do this is to ask the user if they want you to delete files and try again. It is imperative that you get the users input into this, this way it is at their own peril. In my head its something similar to.
Источник
The «GetTempFileName» function fails together with an access denied error in Windows 7 or in Windows Server 2008 R2
Symptoms
On a computer that is running Windows 7 or Windows Server 2008 R2, an application calls the GetTempFileName function to create a temporary file. However, the GetTempFileName function fails, and you receive some transient errors that resemble the following:
Access to the path is denied.
You do not have access to filepath>.
Cause
This issue occurs because the GetTempFileName function handles a duplicated file name incorrectly.
When the GetTempFileName function tries to create a temporary file name, it checks whether a duplicate file name already exists. If the GetTempFileName function finds a duplicated file name and the file is pending for deletion, the GetTempFileName function handles the duplicated file name incorrectly and fails altogether with the «ERROR_ACCESS_DENIED» error code.
The expected behavior is that the function retries to create another temporary file name.
Resolution
Hotfix information
A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing the problem described in this article. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.
If the hotfix is available for download, there is a «Hotfix download available» section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.
Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=supportNote The «Hotfix download available» form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.
Prerequisites
No prerequisites are required.
Restart requirement
You must restart the computer after you apply this hotfix.
Hotfix replacement information
This hotfix does not replace a previously released hotfix.
File information
The global version of this hotfix installs files that have the attributes that are listed in the following tables. The dates and the times for these files are listed in Coordinated Universal Time (UTC). The dates and the times for these files on your local computer are displayed in your local time together with your current daylight saving time (DST) bias. Additionally, the dates and the times may change when you perform certain operations on the files.
Windows 7 and Windows Server 2008 R2 file information notes
Important Windows 7 hotfixes and Windows Server 2008 R2 hotfixes are included in the same packages. However, hotfixes on the Hotfix Request page are listed under both operating systems. To request the hotfix package that applies to one or both operating systems, select the hotfix that is listed under «Windows 7/Windows Server 2008 R2» on the page. Always refer to the «Applies To» section in articles to determine the actual operating system that each hotfix applies to.
The MANIFEST files (.manifest) and the MUM files (.mum) that are installed for each environment are listed separately in the «Additional file information for Windows Server 2008 R2 and for Windows 7» section. MUM and MANIFEST files, and the associated security catalog (.cat) files, are extremely important to maintaining the state of the updated component. The security catalog files, for which the attributes are not listed, are signed with a Microsoft digital signature.
Источник
System.IO.IOException: The file exists #2305
The publish task is failing with this error
##[section]Starting: Publish Artifact: Artifacts
Task : Publish Build Artifacts
Description : Publish build artifacts to Azure Pipelines/TFS or a file share
Version : 1.142.2
Author : Microsoft Corporation
Help : More Information
##[section]Async Command Start: Upload Artifact
Uploading 1 files
Total file: 1 —- Processed file: 0 (0%)
Fail to upload ‘E:Agent08_work2aUI.WebAPI.zip’ due to ‘The file exists’.
System.IO.IOException: The file exists
at System.IO.Path.GetTempFileName()
at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.UploadFileAsync(Int64 containerId, String itemPath, Stream fileStream, Guid scopeIdentifier, CancellationToken cancellationToken, Int32 chunkSize, Boolean uploadFirstChunk, Object userState, Boolean compressStream)
at Microsoft.VisualStudio.Services.Agent.Worker.Build.FileContainerServer.UploadAsync(IAsyncCommandContext context, Int32 uploaderId, CancellationToken token)
1 files failed to upload, retry these files after a minute.
Retry file upload after 60 seconds.
Retry file upload after 55 seconds.
Retry file upload after 50 seconds.
Retry file upload after 45 seconds.
Retry file upload after 40 seconds.
Retry file upload after 35 seconds.
Retry file upload after 30 seconds.
Retry file upload after 25 seconds.
Retry file upload after 20 seconds.
Retry file upload after 15 seconds.
Retry file upload after 10 seconds.
Retry file upload after 5 seconds.
Start retry 1 failed files upload.
Total file: 1 —- Processed file: 0 (0%)
Fail to upload ‘E:Agent08_work2aUI.WebAPI.zip’ due to ‘The file exists’.
System.IO.IOException: The file exists
at System.IO.Path.GetTempFileName()
at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.UploadFileAsync(Int64 containerId, String itemPath, Stream fileStream, Guid scopeIdentifier, CancellationToken cancellationToken, Int32 chunkSize, Boolean uploadFirstChunk, Object userState, Boolean compressStream)
at Microsoft.VisualStudio.Services.Agent.Worker.Build.FileContainerServer.UploadAsync(IAsyncCommandContext context, Int32 uploaderId, CancellationToken token)
##[section]Async Command End: Upload Artifact
##[error]File upload failed even after retry.
##[section]Finishing: Publish Artifact: Artifacts
The text was updated successfully, but these errors were encountered:
Источник
GetTempFileName function (winbase.h)
Creates a name for a temporary file. If a unique file name is generated, an empty file is created and the handle to it is released; otherwise, only a file name is generated.
Syntax
Parameters
The directory path for the file name. Applications typically specify a period (.) for the current directory or the result of the GetTempPath function. The string cannot be longer than MAX_PATH–14 characters or GetTempFileName will fail. If this parameter is NULL, the function fails.
The null-terminated prefix string. The function uses up to the first three characters of this string as the prefix of the file name. This string must consist of characters in the OEM-defined character set.
An unsigned integer to be used in creating the temporary file name. For more information, see Remarks.
If uUnique is zero, the function attempts to form a unique file name using the current system time. If the file already exists, the number is increased by one and the functions tests if this file already exists. This continues until a unique filename is found; the function creates a file by that name and closes it. Note that the function does not attempt to verify the uniqueness of the file name when uUnique is nonzero.
A pointer to the buffer that receives the temporary file name. This buffer should be MAX_PATH characters to accommodate the path plus the terminating null character.
Return value
If the function succeeds, the return value specifies the unique numeric value used in the temporary file name. If the uUnique parameter is nonzero, the return value specifies that same number.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The following is a possible return value.
Return value | Description |
---|---|
ERROR_BUFFER_OVERFLOW | The length of the string pointed to by the lpPathName parameter is more than MAX_PATH–14 characters. |
The GetTempFileName function creates a temporary file name of the following form:
The following table describes the file name syntax.
Component | Meaning |
---|---|
Path specified by the lpPathName parameter | |
First three letters of the lpPrefixString string | |
Hexadecimal value of uUnique |
В
If uUnique is zero, GetTempFileName creates an empty file and closes it. If uUnique is not zero, you must create the file yourself. Only a file name is created, because GetTempFileName is not able to guarantee that the file name is unique.
Only the lower 16 bits of the uUnique parameter are used. This limits GetTempFileName to a maximum of 65,535 unique file names if the lpPathName and lpPrefixString parameters remain the same.
Due to the algorithm used to generate file names, GetTempFileName can perform poorly when creating a large number of files with the same prefix. In such cases, it is recommended that you construct unique file names based on GUIDs.
Temporary files whose names have been created by this function are not automatically deleted. To delete these files call DeleteFile.
To avoid problems resulting when converting an ANSI string, an application should call the CreateFile function to create a temporary file.
In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.
Источник
Blog JTB FlexReport the FlexNet/FLEXlm license report and monitoring tool
AutoCAD, AutoCAD Architecture (ACA/ADT), Revit Architecture, Revit MEP, Revit Structure, BIM, CAD, AutoLISP, VBA, VB, VB.NET, C#, databases, Access, SQL Server, FlexNet (FLEXlm), license usage reporting, software design, development, customization, integration.
About
Software
JTB FlexReport
graphic license reports for applications using FlexNet/FLEXlm,IBM LUM, 12D, SLM/Sentinel or LM-X
JTB SmartBatch
Batch script DWG
SSMPropEditor
edit Sheet Set Properties on multiple sheets at a time. Works both with AutoCAD’s Sheet Set Manager (SSM) and AutoCAD Architecture’s Project Navigator (PN)
JTB CAD Automation Tools
Batch create and update drawings
ACAD_db
Sync AutoCAD block attributes with database
JTB BatchAttEdit
Batch Attribute Editor app for AutoCAD
DWG Columns
Show DWG properties in Explorer Columns
ACA_db
Sync Property Sets with a database
OffsetInXref for AutoCAD
Better Offset for AutoCAD.
DimensionPatrol for AutoCAD
Highlight edited dimensions for AutoCAD.
Batch Publish for AutoCAD
Plot sets of drawings to DWF and/or PDF.
JTB Align Plus
Align objects quickly.
JTB Current Folder
Improves AutoCAD file dialog boxes.
JTB Text Bubble Plus
Text bubbles for AutoCAD.
JTB Steel
Steel shapes for AutoCAD.
DwgNotes
add and edit notes in drawings
DimNotes
Automate dimension notes in AutoCAD
XClipClean
Delete excessive xclipped objects in AutoCAD
TimberTool
For timber/structural shapes in ADT/ACA
HVACPAC for AutoCAD
AutoCAD plug-in for HVAC and Piping work
JTB Sheet Set Creator
Create Sheet Sets with all included based on Excel templates.
and more found here.
Subscribe to our product Newsletters
Resources
Subscribe To
JTB World on Twitter
Wednesday, December 17, 2008
System.IO.IOException: The file exists and GetTempFileName solution and explanation
I was researching a problem in JTB FlexReport that a couple of customers had and the error log gave this error message.
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()
It was pretty obvious that the file did not exist as the message said and thanks to this post I got the explanation as there also where “many” empty temp files (0 KB) in the c:windowstemp folder.
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.
Eventually I found the problem and the solution will be included in the next release. It seems to affect very few customers but a hotfix is available in the meantime.
Источник
Symptoms
On a computer that is running Windows 7 or Windows Server 2008 R2, an application calls the GetTempFileName function to create a temporary file. However, the GetTempFileName function fails, and you receive some transient errors that resemble the following:
Access to the path is denied.
You do not have access to <filepath>.
Cause
This issue occurs because the GetTempFileName function handles a duplicated file name incorrectly.
When the GetTempFileName function tries to create a temporary file name, it checks whether a duplicate file name already exists. If the GetTempFileName function finds a duplicated file name and the file is pending for deletion, the GetTempFileName function handles the duplicated file name incorrectly and fails altogether with the «ERROR_ACCESS_DENIED» error code.
The expected behavior is that the function retries to create another temporary file name.
Resolution
Hotfix information
A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing the problem described in this article. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.
If the hotfix is available for download, there is a «Hotfix download available» section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.
Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=supportNote The «Hotfix download available» form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.
Prerequisites
No prerequisites are required.
Restart requirement
You must restart the computer after you apply this hotfix.
Hotfix replacement information
This hotfix does not replace a previously released hotfix.
File information
The global version of this hotfix installs files that have the attributes that are listed in the following tables. The dates and the times for these files are listed in Coordinated Universal Time (UTC). The dates and the times for these files on your local computer are displayed in your local time together with your current daylight saving time (DST) bias. Additionally, the dates and the times may change when you perform certain operations on the files.
Windows 7 and Windows Server 2008 R2 file information notes
Important Windows 7 hotfixes and Windows Server 2008 R2 hotfixes are included in the same packages. However, hotfixes on the Hotfix Request page are listed under both operating systems. To request the hotfix package that applies to one or both operating systems, select the hotfix that is listed under «Windows 7/Windows Server 2008 R2» on the page. Always refer to the «Applies To» section in articles to determine the actual operating system that each hotfix applies to.
-
The MANIFEST files (.manifest) and the MUM files (.mum) that are installed for each environment are listed separately in the «Additional file information for Windows Server 2008 R2 and for Windows 7» section. MUM and MANIFEST files, and the associated security catalog (.cat) files, are extremely important to maintaining the state of the updated component. The security catalog files, for which the attributes are not listed, are signed with a Microsoft digital signature.
For all supported x86-based versions of Windows 7
File name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Kernelbase.dll |
6.1.7600.20693 |
288,256 |
16-Apr-2010 |
07:20 |
x86 |
For all supported x64-based versions of Windows 7 and of Windows Server 2008 R2
File name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Kernelbase.dll |
6.1.7600.20693 |
420,352 |
16-Apr-2010 |
07:29 |
x64 |
Kernelbase.dll |
6.1.7600.20693 |
269,824 |
16-Apr-2010 |
07:18 |
x86 |
For all supported IA-64-based versions of Windows Server 2008 R2
File name |
File version |
File size |
Date |
Time |
Platform |
---|---|---|---|---|---|
Kernelbase.dll |
6.1.7600.20693 |
717,824 |
16-Apr-2010 |
05:59 |
IA-64 |
Kernelbase.dll |
6.1.7600.20693 |
269,824 |
16-Apr-2010 |
07:18 |
x86 |
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the «Applies to» section.
More Information
For more information about the GetTempFileName function, visit the following Microsoft Developer Network (MSDN) website:
General information about the «GetTempFileName» functionFor more information about the NTSTATUS values, visit the following MSDN website:
824684 Description of the standard terminology that is used to describe Microsoft software updates
Additional file information
Additional file information for Windows 7 and for Windows Server 2008 R2
Additional files for all supported x86-based versions of Windows 7
File name |
Update.mum |
File version |
Not applicable |
File size |
1,674 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
X86_566758896d090f85fc8cb5f95c849a86_31bf3856ad364e35_6.1.7600.20693_none_211a4e5218931dcf.manifest |
File version |
Not applicable |
File size |
698 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
X86_microsoft-windows-kernelbase_31bf3856ad364e35_6.1.7600.20693_none_27559e8e2f0f2966.manifest |
File version |
Not applicable |
File size |
2,734 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
07:56 |
Platform |
Not applicable |
Additional files for all supported x64-based versions of Windows 7 and of Windows Server 2008 R2
File name |
Amd64_2194916ab24431d6bfd9fcb71de794de_31bf3856ad364e35_6.1.7600.20693_none_f1446242783acb06.manifest |
File version |
Not applicable |
File size |
702 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
Amd64_e30a797d077054280de565e75a8a3ce6_31bf3856ad364e35_6.1.7600.20693_none_c448767cdfc8c3cb.manifest |
File version |
Not applicable |
File size |
702 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
Amd64_microsoft-windows-kernelbase_31bf3856ad364e35_6.1.7600.20693_none_83743a11e76c9a9c.manifest |
File version |
Not applicable |
File size |
2,738 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
08:50 |
Platform |
Not applicable |
File name |
Update.mum |
File version |
Not applicable |
File size |
2,328 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
Wow64_microsoft-windows-kernelbase_31bf3856ad364e35_6.1.7600.20693_none_8dc8e4641bcd5c97.manifest |
File version |
Not applicable |
File size |
2,746 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
07:50 |
Platform |
Not applicable |
Additional files for all supported IA-64-based versions of Windows Server 2008 R2
File name |
Ia64_aa7e5d6fa743c1b1b31a1f9acbe9f961_31bf3856ad364e35_6.1.7600.20693_none_237f9d709bce10d3.manifest |
File version |
Not applicable |
File size |
700 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
Ia64_e30a797d077054280de565e75a8a3ce6_31bf3856ad364e35_6.1.7600.20693_none_682b7eef27695b91.manifest |
File version |
Not applicable |
File size |
701 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
Ia64_microsoft-windows-kernelbase_31bf3856ad364e35_6.1.7600.20693_none_275742842f0d3262.manifest |
File version |
Not applicable |
File size |
2,736 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
08:50 |
Platform |
Not applicable |
File name |
Update.mum |
File version |
Not applicable |
File size |
1,684 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
10:25 |
Platform |
Not applicable |
File name |
Wow64_microsoft-windows-kernelbase_31bf3856ad364e35_6.1.7600.20693_none_8dc8e4641bcd5c97.manifest |
File version |
Not applicable |
File size |
2,746 |
Date (UTC) |
16-Apr-2010 |
Time (UTC) |
07:50 |
Platform |
Not applicable |
Need more help?
The publish task is failing with this error
##[section]Starting: Publish Artifact: Artifacts
Task : Publish Build Artifacts
Description : Publish build artifacts to Azure Pipelines/TFS or a file share
Version : 1.142.2
Author : Microsoft Corporation
Help : More Information
##[section]Async Command Start: Upload Artifact
Uploading 1 files
Total file: 1 —- Processed file: 0 (0%)
Fail to upload ‘E:Agent08_work2aUI.WebAPI.zip’ due to ‘The file exists’.
System.IO.IOException: The file exists
at System.IO.Path.GetTempFileName()
at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.UploadFileAsync(Int64 containerId, String itemPath, Stream fileStream, Guid scopeIdentifier, CancellationToken cancellationToken, Int32 chunkSize, Boolean uploadFirstChunk, Object userState, Boolean compressStream)
at Microsoft.VisualStudio.Services.Agent.Worker.Build.FileContainerServer.UploadAsync(IAsyncCommandContext context, Int32 uploaderId, CancellationToken token)
1 files failed to upload, retry these files after a minute.
Retry file upload after 60 seconds.
Retry file upload after 55 seconds.
Retry file upload after 50 seconds.
Retry file upload after 45 seconds.
Retry file upload after 40 seconds.
Retry file upload after 35 seconds.
Retry file upload after 30 seconds.
Retry file upload after 25 seconds.
Retry file upload after 20 seconds.
Retry file upload after 15 seconds.
Retry file upload after 10 seconds.
Retry file upload after 5 seconds.
Start retry 1 failed files upload.
Total file: 1 —- Processed file: 0 (0%)
Fail to upload ‘E:Agent08_work2aUI.WebAPI.zip’ due to ‘The file exists’.
System.IO.IOException: The file exists
at System.IO.Path.GetTempFileName()
at Microsoft.VisualStudio.Services.FileContainer.Client.FileContainerHttpClient.UploadFileAsync(Int64 containerId, String itemPath, Stream fileStream, Guid scopeIdentifier, CancellationToken cancellationToken, Int32 chunkSize, Boolean uploadFirstChunk, Object userState, Boolean compressStream)
at Microsoft.VisualStudio.Services.Agent.Worker.Build.FileContainerServer.UploadAsync(IAsyncCommandContext context, Int32 uploaderId, CancellationToken token)
##[section]Async Command End: Upload Artifact
##[error]File upload failed even after retry.
##[section]Finishing: Publish Artifact: Artifacts
If this is happening to you on a production environment or with an app that you can’t change, the quick fix is to empty the Temp folder.
Depending on the user that is running the application you should either
- Empty
C:WindowsTemp
(for IIS or services running underLocalSystem
account) - Or
%temp%
for locally logged on users (which for me isC:UsersMyUserNameAppDataLocalTemp
).
On the other side, if your own code is throwing this, and you want to prevent this from happening ever again:
- Do not use System.IO.Path.GetTempFileName()!
GetTempFileName()
is a wrapper of the two decades old Win32 Api. It generate file names that will very easily collide. It circumvents those collitions by heavily looping on the file system, iterating possible file names from "%temp%tmp0000.tmp"
to "tmpFFFF.tmp"
and skipping already existing ones. This is a I/O intensive, slow, and frankly terrible algorithm. Also using only 4 hex characters is what makes the artificial limit of 65536 files before failing.
The alternative is to generate file names that will not collide. For example, lets reuse GUID's
logic: 32 hex digits will almost never collide.
private string GetTempFileName()
{
return Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
}
// Sample: c:WindowsTemp2e38fe87-f6bb-4b0d-90b3-2d07016324c1
This expands the limit from 65k to 4k millions files max (theoretically)… Of course, having leaked 65k files is already terrible, so…
- Do not leak temp files!
Double check your app for all happy and unhappy paths (like unexpected exceptions). Ensure it’s correctly disposing each FileStream and deleting the temp files in Finally blocks .
- Clean the temp folder
Clean it now, and educate the system administrator to clean it periodically, because you can’t trust every app in the wild.
On my own servers I would automate this task using:
- For global WindowsTemp
schtasks /Create /TR "cmd /c call DEL /F /S /Q %^TEMP%" /TN "Delete Global Temp Files" /sc WEEKLY /ST 12:00 /ru system
- For current user:
schtasks /Create /TR "cmd /c call DEL /F /S /Q %^TEMP%" /TN "Delete %username% Temp Files" /sc WEEKLY /ST 12:00
As I mentioned in my last comment I think your only safe way to do this is to ask the user if they want you to delete files and try again. It is imperative that you get the users input into this, this way it is at their own peril. In my head its something similar to.
public Stream GetStream(Stream cursorStream)
{
try
{
//getting stream
}
catch(IOE)
{
MessageBox.Show(this, "Unable to get stream, your temporary
folder may be full, do you want to try deleting
some and try again?");
if(yes)
try
{
//delete and try again
return GetStream(cursorStream);
}
catch(IOE)
{
//no luck
}
else
return null;
}
}
An optional check to make sure could be,
Directory.EnumerateFiles(Path.GetTempPath(), "*", SearchOption.TopLevelOnly)
.Count() == ushort.MaxValue;
Here’s the code I used in the end, and put early in my app’s initialization code-path, before any calls to Cursor.LoadFromStream
might occur:
private void WarnUserIfTempFolderFull()
{
string tempFile = null;
try
{
tempFile = Path.GetTempFileName();
}
catch (IOException e)
{
string problem = "The Temporary Folder is full.";
string message = "{ProductName} has detected that the Windows Temporary Folder is full. n" +
"This may prevent the {ProductName} from functioning correctly.n" +
"Please delete old files in your temporary folder (%TEMP%) and try again.";
Logger.Warn(problem);
MessageBox.Show(message, caption: problem);
}
finally
{
if (tempFile != null) File.Delete(tempFile);
}
}
GetTempFileName function (winbase.h)
Creates a name for a temporary file. If a unique file name is generated, an empty file is created and the handle to it is released; otherwise, only a file name is generated.
Syntax
Parameters
The directory path for the file name. Applications typically specify a period (.) for the current directory or the result of the GetTempPath function. The string cannot be longer than MAX_PATH–14 characters or GetTempFileName will fail. If this parameter is NULL, the function fails.
The null-terminated prefix string. The function uses up to the first three characters of this string as the prefix of the file name. This string must consist of characters in the OEM-defined character set.
An unsigned integer to be used in creating the temporary file name. For more information, see Remarks.
If uUnique is zero, the function attempts to form a unique file name using the current system time. If the file already exists, the number is increased by one and the functions tests if this file already exists. This continues until a unique filename is found; the function creates a file by that name and closes it. Note that the function does not attempt to verify the uniqueness of the file name when uUnique is nonzero.
A pointer to the buffer that receives the temporary file name. This buffer should be MAX_PATH characters to accommodate the path plus the terminating null character.
Return value
If the function succeeds, the return value specifies the unique numeric value used in the temporary file name. If the uUnique parameter is nonzero, the return value specifies that same number.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The following is a possible return value.
Return value | Description |
---|---|
ERROR_BUFFER_OVERFLOW | The length of the string pointed to by the lpPathName parameter is more than MAX_PATH–14 characters. |
Remarks
The GetTempFileName function creates a temporary file name of the following form:
The following table describes the file name syntax.
Component | Meaning |
---|---|
Path specified by the lpPathName parameter | |
First three letters of the lpPrefixString string | |
Hexadecimal value of uUnique |
В
If uUnique is zero, GetTempFileName creates an empty file and closes it. If uUnique is not zero, you must create the file yourself. Only a file name is created, because GetTempFileName is not able to guarantee that the file name is unique.
Only the lower 16 bits of the uUnique parameter are used. This limits GetTempFileName to a maximum of 65,535 unique file names if the lpPathName and lpPrefixString parameters remain the same.
Due to the algorithm used to generate file names, GetTempFileName can perform poorly when creating a large number of files with the same prefix. In such cases, it is recommended that you construct unique file names based on GUIDs.
Temporary files whose names have been created by this function are not automatically deleted. To delete these files call DeleteFile.
To avoid problems resulting when converting an ANSI string, an application should call the CreateFile function to create a temporary file.
In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.
Источник
Blog JTB FlexReport the FlexNet/FLEXlm license report and monitoring tool
AutoCAD, AutoCAD Architecture (ACA/ADT), Revit Architecture, Revit MEP, Revit Structure, BIM, CAD, AutoLISP, VBA, VB, VB.NET, C#, databases, Access, SQL Server, FlexNet (FLEXlm), license usage reporting, software design, development, customization, integration.
About
Software
JTB FlexReport
graphic license reports for applications using FlexNet/FLEXlm,IBM LUM, 12D, SLM/Sentinel or LM-X
JTB SmartBatch
Batch script DWG
SSMPropEditor
edit Sheet Set Properties on multiple sheets at a time. Works both with AutoCAD’s Sheet Set Manager (SSM) and AutoCAD Architecture’s Project Navigator (PN)
JTB CAD Automation Tools
Batch create and update drawings
ACAD_db
Sync AutoCAD block attributes with database
JTB BatchAttEdit
Batch Attribute Editor app for AutoCAD
DWG Columns
Show DWG properties in Explorer Columns
ACA_db
Sync Property Sets with a database
OffsetInXref for AutoCAD
Better Offset for AutoCAD.
DimensionPatrol for AutoCAD
Highlight edited dimensions for AutoCAD.
Batch Publish for AutoCAD
Plot sets of drawings to DWF and/or PDF.
JTB Align Plus
Align objects quickly.
JTB Current Folder
Improves AutoCAD file dialog boxes.
JTB Text Bubble Plus
Text bubbles for AutoCAD.
JTB Steel
Steel shapes for AutoCAD.
DwgNotes
add and edit notes in drawings
DimNotes
Automate dimension notes in AutoCAD
XClipClean
Delete excessive xclipped objects in AutoCAD
TimberTool
For timber/structural shapes in ADT/ACA
HVACPAC for AutoCAD
AutoCAD plug-in for HVAC and Piping work
JTB Sheet Set Creator
Create Sheet Sets with all included based on Excel templates.
and more found here.
Subscribe to our product Newsletters
Resources
Subscribe To
JTB World on Twitter
Wednesday, December 17, 2008
System.IO.IOException: The file exists and GetTempFileName solution and explanation
I was researching a problem in JTB FlexReport that a couple of customers had and the error log gave this error message.
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()
It was pretty obvious that the file did not exist as the message said and thanks to this post I got the explanation as there also where “many” empty temp files (0 KB) in the c:windowstemp folder.
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.
Eventually I found the problem and the solution will be included in the next release. It seems to affect very few customers but a hotfix is available in the meantime.
Источник
The «GetTempFileName» function fails together with an access denied error in Windows 7 or in Windows Server 2008 R2
Symptoms
On a computer that is running Windows 7 or Windows Server 2008 R2, an application calls the GetTempFileName function to create a temporary file. However, the GetTempFileName function fails, and you receive some transient errors that resemble the following:
Access to the path is denied.
You do not have access to filepath>.
Cause
This issue occurs because the GetTempFileName function handles a duplicated file name incorrectly.
When the GetTempFileName function tries to create a temporary file name, it checks whether a duplicate file name already exists. If the GetTempFileName function finds a duplicated file name and the file is pending for deletion, the GetTempFileName function handles the duplicated file name incorrectly and fails altogether with the «ERROR_ACCESS_DENIED» error code.
The expected behavior is that the function retries to create another temporary file name.
Resolution
Hotfix information
A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing the problem described in this article. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.
If the hotfix is available for download, there is a «Hotfix download available» section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.
Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=supportNote The «Hotfix download available» form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.
Prerequisites
No prerequisites are required.
Restart requirement
You must restart the computer after you apply this hotfix.
Hotfix replacement information
This hotfix does not replace a previously released hotfix.
File information
The global version of this hotfix installs files that have the attributes that are listed in the following tables. The dates and the times for these files are listed in Coordinated Universal Time (UTC). The dates and the times for these files on your local computer are displayed in your local time together with your current daylight saving time (DST) bias. Additionally, the dates and the times may change when you perform certain operations on the files.
Windows 7 and Windows Server 2008 R2 file information notes
Important Windows 7 hotfixes and Windows Server 2008 R2 hotfixes are included in the same packages. However, hotfixes on the Hotfix Request page are listed under both operating systems. To request the hotfix package that applies to one or both operating systems, select the hotfix that is listed under «Windows 7/Windows Server 2008 R2» on the page. Always refer to the «Applies To» section in articles to determine the actual operating system that each hotfix applies to.
The MANIFEST files (.manifest) and the MUM files (.mum) that are installed for each environment are listed separately in the «Additional file information for Windows Server 2008 R2 and for Windows 7» section. MUM and MANIFEST files, and the associated security catalog (.cat) files, are extremely important to maintaining the state of the updated component. The security catalog files, for which the attributes are not listed, are signed with a Microsoft digital signature.
Источник
The GetTempFileName function fails and you receive an access denied error in Windows Vista or in Windows Server 2008
Symptoms
When an application calls the GetTempFileName function to create a temporary file on a computer that is running Windows Vista or Windows Server 2008, the function fails. Additionally, you receive a transient error that resembles the following:
Access to the path is denied.
You do not have access to .
Cause
This issue occurs because the GetTempFileName function handles a duplicated file name incorrectly.
When the GetTempFileName function tries to create a temporary file name, the function checks whether a duplicated file name already exists. If the GetTempFileName function finds a duplicated file name, and if the file is pending deletion, the function handles the duplicated file name incorrectly. Therefore, you receive an ERROR_ACCESS_DENIED error code.
Note The expected behavior is that the function would again try to create a temporary file name.
Resolution
Hotfix information
A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that described in this article. Apply this hotfix only to systems that are experiencing the problem described in this article. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.
If the hotfix is available for download, there is a «Hotfix download available» section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.
Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft website:
http://support.microsoft.com/contactus/?ws=supportNote The «Hotfix download available» form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.
Prerequisites
To apply this hotfix, you must be running Windows Vista Service Pack 2 (SP2) or Windows Server 2008 Service Pack 2 (SP2).
For more information about how to obtain a Windows Vista service pack, click the following article number to view the article in the Microsoft Knowledge Base:
935791 How to obtain the latest Windows Vista service pack
For more information about how to obtain a Windows Server 2008 service pack, click the following article number to view the article in the Microsoft Knowledge Base:
968849 How to obtain the latest service pack for Windows Server 2008
Restart requirement
You may have to restart the computer after you apply this hotfix.
Hotfix replacement information
This hotfix does not replace a previously released hotfix.
File information
The global version of this hotfix installs files that have the attributes that are listed in the following tables. The dates and the times for these files are listed in Coordinated Universal Time (UTC). The dates and the times for these files on your local computer are displayed in your local time together with your current daylight saving time (DST) bias. Additionally, the dates and the times may change when you perform certain operations on the files.
Windows Vista and Windows Server 2008 file information notes
Important Windows Vista hotfixes and Windows Server 2008 hotfixes are included in the same packages. However, only «Windows Vista» is listed on the Hotfix Request page. To request the hotfix package that applies to one or both operating systems, select the hotfix that is listed under «Windows Vista» on the page. Always refer to the «Applies To» section in articles to determine the actual operating system that each hotfix applies to.
The files that apply to a specific product, SR_Level (RTM, SPn), and service branch (LDR, GDR) can be identified by examining the file version numbers as shown in the following table.
Windows Vista and Windows Server 2008
The MANIFEST files (.manifest) and the MUM files (.mum) that are installed for each environment are listed separately in the «Additional file information for Windows Server 2008 and for Windows Vista» section. MUM files and MANIFEST files, and the associated security catalog (.cat) files, are very important to maintain the state of the updated components. The security catalog files, for which the attributes are not listed, are signed with a Microsoft digital signature.
Источник