来自HRESULT的异常:0x80040111(CLASS_E_CLASSNOTAVAILABLE) [英] Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)

查看:210
本文介绍了来自HRESULT的异常:0x80040111(CLASS_E_CLASSNOTAVAILABLE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.Net 4.0 / WPF应用程序/ C#

Using .Net 4.0 / WPF Application / C#

我的应用程序中包含以下代码,当时将打开FileDialog。单击

I have the following piece of code in my application, which opens a FileDialog when the Select button is clicked.

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
    }
}

这块的代码可在其他计算机上使用,但不适用于我的计算机。单击 Select 按钮时,它只会引发异常-如下所示。

This piece of code works in other machines, but not in my machine. It just throws an exception - as below - when the Select button is clicked upon.

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






查找错误是由 PresentationFramework内部的 Microsoft.Win32 命名空间中的 comdlg32.dll 引起的。 dll 程序集,我向注册表查询了此CLS ID


Finding out the error is caused by comdlg32.dll from Microsoft.Win32 namespace, inside PresentationFramework.dll assembly, I queried the Registry for this CLS ID

reg query HKCR\CLSID | find /i "{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}"

,这就是它说


HKEY_CLASSES_ROOT\CLSID {DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}

HKEY_CLASSES_ROOT\CLSID{DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}






我也尝试了以下方法


I have also tried the following


  1. 根据 SO帖子,我尝试注册 dll ,但是又回来了

  1. As per this SO Post, I tried to register the dll, but it came back saying


[Window标题] RegSvr32

[Window Title] RegSvr32

[内容]模块 comdlg32.dll已加载,但未找到入口点
DllRegisterServer。

[Content] The module "comdlg32.dll" was loaded but the entry-point DllRegisterServer was not found.

确保 comdlg32.dll是有效的DLL或OCX文件,然后再次尝试

Make sure that "comdlg32.dll" is a valid DLL or OCX file and then try again.

[确定] ]


  • 根据这篇 SO帖子中,我尝试更改 Permissions ,但没有运气

  • As per this SO Post, I tried changing the Permissions, but no luck






    除了重新映像机器或重新映像外,是否还有其他方法可以解决此问题安装Windows?


    Is there any way this can be resolved apart from re-imaging the machine or re-installing Windows?

    如果这有帮助:我有.Net FrameWork v3.5 / v4.0 / v4.5.1&安装在我的计算机中的v4.5.2和 PresentationFramework.dll 在文件夹内的所有位置都可用

    If this helps : I have .Net FrameWork v3.5/ v4.0 / v4.5.1 & v4.5.2 installed in my machine and the PresentationFramework.dll is available in all locations inside the 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
    


    推荐答案

    丢弃Windows安装被破坏的可能性,这实际上是由在Windows 7及更高版本中,视觉主题已关闭。

    Discarding the possibility that the Windows installation is broken, this is actually a rather insidious problem that is caused by "Visual Themes" being turned off in Windows 7 and above.

    要重现它,您可以使用有效的WPF应用程序并修改其兼容性设置(在Windows资源管理器中右键单击.exe,然后选择偏好设置,然后从兼容性选项卡中,选中禁用视觉主题)。然后,尝试运行该应用程序,当您尝试显示OpenFileDialog或SaveFileDialog时,您会发现它开始崩溃。

    To reproduce it you can take a working WPF application and modify it's compatibility settings (righ-click on the .exe in Windows Explorer, then select Preferences and from the Compatibiltiy tab, check "Disable Visual Themes"). Then, try running the application and you'll notice it starts crashing when you try to show an OpenFileDialog or a SaveFileDialog.

    Visual Themes可能在操作系统级别关闭了同样(例如,当使用高对比度主题时),通常在终端服务会话中,或者在通过WebEx或其他桌面共享应用程序进行桌面共享时,它们会被关闭。

    Visual Themes may be turned off at the OS level as well (when using a high contrast theme for instance) and they are usually turned off in Terminal Services sessions, or when desktop sharing via WebEx or some other desktop sharing applications.

    不幸的是,我还没有解决方案,但是基于对MSDN的阅读,微软似乎在说当桌面合成和视觉主题关闭时,您应该提供替代的代码路径-不管怎么说。

    Unfortunately I don't have a solution yet but based on reading through MSDN it looks like Microsoft is saying you should "provide an alternative code path" when desktop composition and visual themes are off - whatever that means.

    内部,OpenFileDialog的实现具有一种尝试初始化打开文件对话框COM控件的实例的方法,该实例在视觉主题关闭时会失败

    Internally, the OpenFileDialog's implementation has a method that attempts to initialize an instance of the open file dialog COM control which fails when Visual Themes are off

    [SecurityCritical, SecurityTreatAsSafe]
    internal override IFileDialog CreateVistaDialog()
    {
        new SecurityPermission(PermissionState.Unrestricted).Assert();
        return (IFileDialog) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")));
    }
    

    这篇关于来自HRESULT的异常:0x80040111(CLASS_E_CLASSNOTAVAILABLE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆