dotnet/wpf · error · IOException
Image_CannotCreateTempFile
Error message
Image_CannotCreateTempFile
What it means
BitmapDownload.BeginDownload attempted to create a temp file but every candidate path failed, so the download state machine cannot proceed and IOException(SR.Image_CannotCreateTempFile) is thrown. This is the aggregate failure after Win32Exception (1180) retries were exhausted or rethrown paths did not succeed.
Solutions
- Ensure %TEMP% exists and is writable by the process account
- Free disk space on the temp volume
- Fix corrupted TEMP/TMP environment variables
- Cache images locally and load from disk/streams instead of remote URIs
Example fix
// before image.Source = new BitmapImage(new Uri(remoteUrl)); // after string temp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".img"); using (var wc = new WebClient()) wc.DownloadFile(remoteUrl, temp); image.Source = new BitmapImage(new Uri(temp));
Defensive patterns
Strategy: try-catch
Validate before calling
bool canWriteTemp = Directory.Exists(Path.GetTempPath()) &&
(from p in new[] { Path.GetTempPath() } select p).All(p =>
{ try { var f = Path.Combine(p, Guid.NewGuid().ToString()); using (File.Create(f)) { } File.Delete(f); return true; } catch { return false; } }); Try / catch
try { img.BeginInit(); img.UriSource = remoteUri; img.EndInit(); }
catch (IOException ex) when (ex.Message.Contains("temp") || ex is IOException) {
log.Error("Image_CannotCreateTempFile", ex);
img = LoadFromMemoryStream(DownloadToMemory(remoteUri)); } Prevention
- Validate temp directory writability at app startup
- Configure a writable temp path for IIS/service identities
- Keep disk space headroom on the temp volume
- Download images to memory streams rather than relying on temp files
When it happens
Trigger: Downloading a bitmap from a URI via BitmapFrame/BitmapImage when the temp file cannot be created at any attempted location (invalid path characters in the generated name, denied ACLs, nonexistent temp directory, disk full).
Common situations: Misconfigured TEMP paths in services/IIS app pools, read-only system drives, group-policy folder redirection to unavailable network shares, disk space exhaustion.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- ArgumentOutOfRangeException(nameof(offset))
- can’t seek on baseStream
- No file exists at
- SR.DirectoryNotFoundExceptionWithFileName
- SR.FileNotFoundExceptionWithFileName
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ca03c4c1661ed54d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs:168
{
throw new Win32Exception();
}
entry.outputStream = new FileStream(fileHandle, FileAccess.ReadWrite);
entry.streamPath = pathToUse;
passed = true;
}
catch(Exception e)
{
if (CriticalExceptions.IsCriticalException(e))
{
throw;
}
}
if (!passed)
{
throw new IOException(SR.Image_CannotCreateTempFile);
}
entry.readBuffer = new byte[READ_SIZE];
entry.contentLength = -1;
entry.contentType = string.Empty;
entry.lastPercent = 0;
// Add the entry to the table if we know the uri
if (uri != null)
{
lock (_syncLock)
{
_uriTable[uri] = entry;
}
}
if (stream == null)
{View on GitHub (pinned to 81131a70a4)