Saa*_*cky 4 .net c# com wpf dll
Using .Net 4.0 / WPF Application / C#
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
}
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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}"
Run Code Online (Sandbox Code Playgroud)
and here is what it says
HKEY_CLASSES_ROOT\CLSID{DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}
I have also tried the following
As per this SO Post, I tried to register the dll, but it came back saying
[Window Title] RegSvr32
[Content] The module "comdlg32.dll" was loaded but the entry-point DllRegisterServer was not found.
Make sure that "comdlg32.dll" is a valid DLL or OCX file and then try again.
[OK]
As per this SO Post, I tried changing the Permissions, but no luck
Is there any way this can be resolved apart from re-imaging the machine or re-installing Windows?
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
Run Code Online (Sandbox Code Playgroud)
排除 Windows 安装损坏的可能性,这实际上是一个相当隐蔽的问题,由 Windows 7 及更高版本中关闭“Visual Themes”引起。
要重现它,您可以使用一个有效的 WPF 应用程序并修改它的兼容性设置(在 Windows 资源管理器中右键单击 .exe,然后选择首选项并从兼容性选项卡中,选中“禁用视觉主题”)。然后,尝试运行该应用程序,当您尝试显示 OpenFileDialog 或 SaveFileDialog 时,您会注意到它开始崩溃。
视觉主题也可以在操作系统级别关闭(例如,当使用高对比度主题时),它们通常在终端服务会话中关闭,或者在通过 WebEx 或其他一些桌面共享应用程序共享桌面时关闭。
不幸的是,我还没有解决方案,但根据阅读 MSDN,微软似乎在说,当桌面组合和视觉主题关闭时,您应该“提供替代代码路径”——不管这意味着什么。
在内部,OpenFileDialog 的实现有一个方法,该方法尝试初始化打开文件对话框 COM 控件的实例,该实例在 Visual Themes 关闭时失败
[SecurityCritical, SecurityTreatAsSafe]
internal override IFileDialog CreateVistaDialog()
{
new SecurityPermission(PermissionState.Unrestricted).Assert();
return (IFileDialog) Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6179 次 |
| 最近记录: |