使用 .Net 4.0 / WPF 应用程序 / C#
我的应用程序中有以下代码,当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
}
}
这段代码在其他机器上可以运行,但在我的机器上不行。它只是抛出一个异常 - 如下所示 - 当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
查出错误原因是comdlg32.dll
from Microsoft.Win32
命名空间,内部PresentationFramework.dll
程序集,我在注册表中查询了此 CLS ID
reg query HKCR\CLSID | find /i "{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}"
这就是它所说的
HKEY_CLASSES_ROOT\CLSID{DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}
我也尝试过以下方法
-
As per thisSO帖子,我尝试注册dll
,但它回来说
[窗口标题] RegSvr32
[内容] 模块“comdlg32.dll”已加载,但入口点
未找到 DllRegisterServer。
确保“comdlg32.dll”是有效的 DLL 或 OCX 文件,然后尝试
再次。
[OK]
As per thisSO帖子,我尝试改变Permissions
,但没有运气
除了重新映像计算机或重新安装 Windows 之外,还有其他方法可以解决此问题吗?
如果这有帮助:我的机器上安装了 .Net FrameWork v3.5/ v4.0 / v4.5.1 & v4.5.2PresentationFramework.dll
在文件夹内的所有位置都可用
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