{"record":{"id":"fd4b970b2ef6ad66","repo":"dotnet/wpf","slug":"dwrite-dll","errorCode":null,"errorMessage":"dwrite.dll","messagePattern":"dwrite\\.dll","errorType":"exception","errorClass":"DllNotFoundException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteLoader.cs","lineNumber":21,"sourceCode":"\nusing System.ComponentModel;\nusing System.Runtime.InteropServices;\n\nnamespace MS.Internal.Text.TextInterface\n{\n    internal static unsafe class DWriteLoader\n    {\n        private static IntPtr _dwrite;\n        private static delegate* unmanaged<int, void*, void*, int> _dwriteCreateFactory;\n\n        internal static void LoadDWrite()\n        {\n            // We load dwrite here because it's cleanup logic is different from the other native dlls\n            // and don't want to abstract that\n            _dwrite = LoadDWriteLibraryAndGetProcAddress(out delegate* unmanaged<int, void*, void*, int> dwriteCreateFactory);\n\n            if (_dwrite == IntPtr.Zero)\n                throw new DllNotFoundException(\"dwrite.dll\", new Win32Exception());\n\n            if (dwriteCreateFactory == null)\n                throw new InvalidOperationException();\n\n            _dwriteCreateFactory = dwriteCreateFactory;\n        }\n\n        internal static void UnloadDWrite()\n        {\n            ClearDWriteCreateFactoryFunctionPointer();\n        \n            if (_dwrite != IntPtr.Zero)\n            {\n                NativeLibrary.Free(_dwrite);\n\n                _dwrite = IntPtr.Zero;\n            }\n        }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Text/TextInterface/DWriteLoader.cs#L3-L39","documentation":"DWriteLoader.LoadDWrite loads dwrite.dll and locates DWriteCreateFactory. If the library cannot be loaded, it throws DllNotFoundException(\"dwrite.dll\") wrapping the Win32 error. DirectWrite is a Windows system component that WPF's text stack requires, so its absence is fatal at text-stack initialization.","triggerScenarios":"Constructing the DirectWrite loader on a system where dwrite.dll cannot be LoadLibrary'd — missing/corrupt system DLL, a broken Windows installation, or a sandbox/containers environment without DirectWrite.","commonSituations":"Running WPF apps on stripped-down Windows images or Server Core without the Desktop Experience; corrupted system files; CI containers missing Graphics/Text runtime features; DLL search-path hijacking placing a bad dwrite.dll earlier on the path.","solutions":["Run on a Windows installation that includes DirectWrite (dwrite.dll in System32) — install Desktop Experience on Server SKUs","Run 'sfc /scannow' or 'DISM /Online /Cleanup-Image /RestoreHealth' to repair a corrupt system copy","Check that no stray dwrite.dll in the app directory or PATH shadows the system one","Verify the container/CI image is a full Windows base image (e.g. servercore with the right features), not a minimal one"],"exampleFix":"// before\n// app starts text stack unconditionally on a minimal container\nApp.Main();\n// after\ntry\n{\n    App.Main();\n}\ncatch (DllNotFoundException ex) when (ex.Message.Contains(\"dwrite.dll\"))\n{\n    Console.Error.WriteLine(\"DirectWrite is unavailable: install a Windows image with Desktop Experience. \" + ex.Message);\n    return 1;\n}","handlingStrategy":"try-catch","validationCode":"// verify DirectWrite is available before starting the text stack\nstring sys32 = Environment.GetFolderPath(Environment.SpecialFolder.System);\nif (!File.Exists(Path.Combine(sys32, \"dwrite.dll\")))\n    throw new InvalidOperationException(\"dwrite.dll missing — install Windows with Desktop Experience\");","typeGuard":"static bool DirectWriteAvailable() =>\n    File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), \"dwrite.dll\"));","tryCatchPattern":"try { textStack.Initialize(); }\ncatch (DllNotFoundException ex) when (ex.Message.Contains(\"dwrite.dll\"))\n{\n    Log.Fatal(\"DirectWrite unavailable: {0}. Win32 error: {1}\", ex.Message, new Win32Exception().Message);\n    Environment.Exit(1);\n}","preventionTips":["Run WPF apps only on Windows images that include DirectWrite/Desktop Experience","Avoid placing third-party dwrite.dll copies in the app folder or PATH","Repair corrupted systems with sfc /scannow or DISM","Use full Windows base images in containers/CI, not minimal ones","Check DirectWrite availability at startup and fail fast with a clear message"],"tags":["windows","native-dependency","dll","wpf"],"backgroundTag":"missing-dependency","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"}