Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)
Using .Net 4.0 / WPF Application / C #
I have the following piece of code in my application that opens a FileDialog when a button is clicked Select
.
OpenFileDialog fdgSelectFile;
bool? dialogResult;
try
{
fdgSelectFile = new OpenFileDialog {DefaultExt = FileDialogDefaultExt, Filter = FileDialogFilter};
dialogResult = fdgSelectFile.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
SelectedFilePath = fdgSelectFile.FileName;
// do your stuff
}
}
This piece of code works on other machines, but not on my machine. It just throws an exception - as shown below - when the button is clicked Select
.
2015-04-28 14:33:47,453 [1] ERROR XXXX.XXXX.XXXX.ViewModels.UploadViewModel - SelectFile - System.Runtime.InteropServices.COMException (0x80040111): Creating an instance of the COM component with CLSID {DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7} from the IClassFactory failed due to the following error: 80040111 ClassFactory cannot supply requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.Win32.OpenFileDialog.CreateVistaDialog()
at Microsoft.Win32.FileDialog.RunVistaDialog(IntPtr hwndOwner)
at Microsoft.Win32.FileDialog.RunDialog(IntPtr hwndOwner)
at Microsoft.Win32.CommonDialog.ShowDialog()
at XXXX.XXXX.XXXX.ViewModels.UploadViewModel.SelectFile(Object param) in c:\XXXX\XXXX\Client\XXXX.XXXX.XXXX\ViewModels\UploadViewModel .cs:line 176
The error detection is called comdlg32.dll
from Microsoft.Win32
a namespace, inside an assembly PresentationFramework.dll
, I have queried the registry for this CLS id
reg query HKCR\CLSID | find /i "{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}"
and this is what he says
HKEY_CLASSES_ROOT \ CLSID {DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}
I have also tried the following
-
According to this SO Post, I tried to register
dll
but it came back saying[Window Name] RegSvr32
[Content] Module "comdlg32.dll" was loaded, but the entry point DllRegisterServer was not found.
Verify that "comdlg32.dll" is a valid DLL or OCX file, and then try again.
[OK]
-
As per this SO Post, I tried to change
Permissions
but no luck
Is there any solution to this other than reprocessing the machine or reinstalling Windows?
If it helps: I have .Net FrameWork v3.5 / v4.0 / v4.5.1 and v4.5.2 installed on my machine and PresentationFramework.dll
available in all locations inside folders.
v3.5 : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client
v4.0 : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
v4.5 : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5
v4.5.1 : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1
v4.5.2 : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2
source to share
Discarding the possibility that the Windows installation is broken is actually a rather insidious problem caused by disabling "Visual Themes" in Windows 7 and above.
To reproduce it, you can take a working WPF application and change its compatibility settings (righ-click on the .exe in Windows Explorer, then select Settings and under the Compatibility tab, check the Disable visual themes box). Then try running the application and you will notice that it starts to crash when you try to show OpenFileDialog or SaveFileDialog.
Visual themes can also be disabled at the OS level (for example, when using a high contrast theme), and they are usually disabled in Terminal Services sessions or when sharing computers via WebEx or other desktop sharing applications.
Unfortunately I don't have a solution yet, but based on reading through MSDN, it looks like Microsoft is stating that you should "provide an alternate code path" when desktop composition and visual themes are disabled - whatever that means.
Internally, the OpenFileDialog implementation has a method that attempts to initialize an open file dialog COM control instance that fails when visual themes are disabled.
[SecurityCritical, SecurityTreatAsSafe]
internal override IFileDialog CreateVistaDialog()
{
new SecurityPermission(PermissionState.Unrestricted).Assert();
return (IFileDialog) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")));
}
source to share