title: Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)
body: <p>Using .Net 4.0 / WPF Application / C#</p>
  
  <p>I have the following piece of code in my application, which opens a FileDialog when the <code>Select</code> button is clicked.</p>
  
  <pre><code>OpenFileDialog fdgSelectFile;
  bool? dialogResult;
  
  try
  {
      fdgSelectFile = new OpenFileDialog {DefaultExt = FileDialogDefaultExt, Filter = FileDialogFilter};
      dialogResult = fdgSelectFile.ShowDialog();
      if (dialogResult.HasValue &amp;&amp; dialogResult.Value)
      {
          SelectedFilePath = fdgSelectFile.FileName;
          // do your stuff
      }
  }
  </code></pre>
  
  <p>This piece of code works in other machines, but not in my machine. It just throws an exception - as below - when the <code>Select</code> button is clicked upon.</p>
  
  <pre><code>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&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)
     at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; 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
  </code></pre>
  
  <hr>
  
  <p>Finding out the error is caused by <code>comdlg32.dll</code> from <code>Microsoft.Win32</code> namespace, inside <code>PresentationFramework.dll</code> assembly, I queried the Registry for this CLS ID </p>
  
  <pre><code>reg query HKCR\CLSID | find /i "{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}"
  </code></pre>
  
  <p>and here is what it says</p>
  
  <blockquote>
    <p>HKEY_CLASSES_ROOT\CLSID{DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7}</p>
  </blockquote>
  
  <hr>
  
  <p>I have also tried the following</p>
  
  <ol>
  <li><p>As per <a href="https://stackoverflow.com/questions/16602256/80040111-classfactory-cannot-supply-requested-class-exception-from-hresult-0x8">this</a> SO Post, I tried to register the <code>dll</code>, but it came back saying </p>
  
  <blockquote>
    <p>[Window Title]  RegSvr32</p>
    
    <p>[Content]   The module "comdlg32.dll" was loaded but the entry-point
    DllRegisterServer was not found.</p>
    
    <p>Make sure that "comdlg32.dll" is a valid DLL or OCX file and then try
    again.</p>
    
    <p>[OK]</p>
  </blockquote></li>
  <li><p>As per <a href="https://stackoverflow.com/questions/7297918/com-class-factory-error-80040154-when-opening-get-directory-dialog">this</a> SO Post, I tried changing the <code>Permissions</code>, but no luck</p></li>
  </ol>
  
  <hr>
  
  <p>Is there any way this can be resolved apart from re-imaging the machine or re-installing Windows?</p>
  
  <p>If this helps : I have .Net FrameWork v3.5/ v4.0 / v4.5.1 &amp; v4.5.2 installed in my machine and the <code>PresentationFramework.dll</code> is available in all locations inside the folders</p>
  
  <pre><code>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
  </code></pre>