{"record":{"id":"ca03c4c1661ed54d","repo":"dotnet/wpf","slug":"image-cannotcreatetempfile","errorCode":null,"errorMessage":"Image_CannotCreateTempFile","messagePattern":"Image_CannotCreateTempFile","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs","lineNumber":168,"sourceCode":"                {\n                    throw new Win32Exception();\n                }\n                    \n                entry.outputStream = new FileStream(fileHandle, FileAccess.ReadWrite);\n                entry.streamPath = pathToUse;\n                passed = true;\n            }\n            catch(Exception e)\n            {\n                if (CriticalExceptions.IsCriticalException(e))\n                {\n                    throw;\n                }\n            }\n\n            if (!passed)\n            {\n                throw new IOException(SR.Image_CannotCreateTempFile);\n            }\n\n            entry.readBuffer  = new byte[READ_SIZE];\n            entry.contentLength = -1;\n            entry.contentType = string.Empty;\n            entry.lastPercent = 0;\n\n            // Add the entry to the table if we know the uri\n            if (uri != null)\n            {\n                lock (_syncLock)\n                {\n                    _uriTable[uri] = entry;\n                }\n            }\n\n            if (stream == null)\n            {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs#L150-L186","documentation":"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.","triggerScenarios":"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).","commonSituations":"Misconfigured TEMP paths in services/IIS app pools, read-only system drives, group-policy folder redirection to unavailable network shares, disk space exhaustion.","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"],"exampleFix":"// before\nimage.Source = new BitmapImage(new Uri(remoteUrl));\n// after\nstring temp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + \".img\");\nusing (var wc = new WebClient()) wc.DownloadFile(remoteUrl, temp);\nimage.Source = new BitmapImage(new Uri(temp));","handlingStrategy":"try-catch","validationCode":"bool canWriteTemp = Directory.Exists(Path.GetTempPath()) &&\n    (from p in new[] { Path.GetTempPath() } select p).All(p =>\n    { try { var f = Path.Combine(p, Guid.NewGuid().ToString()); using (File.Create(f)) { } File.Delete(f); return true; } catch { return false; } });","typeGuard":null,"tryCatchPattern":"try { img.BeginInit(); img.UriSource = remoteUri; img.EndInit(); }\ncatch (IOException ex) when (ex.Message.Contains(\"temp\") || ex is IOException) {\n    log.Error(\"Image_CannotCreateTempFile\", ex);\n    img = LoadFromMemoryStream(DownloadToMemory(remoteUri)); }","preventionTips":["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"],"tags":["wpf","io","temp-file","download"],"backgroundTag":"file-open-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}