title: VB.net Error When Trying To Connect To Access Database With OpenCurrentDatabase in Microsoft.Office.Interop.Access.Application Namespace
body: <p>I am trying to get a legacy system to work in a new environment.  The legacy system consists of a VB.net application that connects to an Access database.  My new environment consists of Visual Studio 2017 and Access 365.</p>
  
  <p>When I try to run the application, I get an error message that reads, </p>
  
  <blockquote>
    <p>System.AccessViolationException: 'Attempted to read or write
    protected memory. This is often an indication that other memory is
    corrupt.'</p>
  </blockquote>
  
  <p>I have created a new VB.net application and Access database from scratch and am able to recreate the error.  The VB code is below.</p>
  
  <pre><code>Imports Microsoft.Office.Interop
  
  Public Class Form1
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          Dim oAccess As Access.Application
          oAccess = New Access.Application
          oAccess.OpenCurrentDatabase("C:\MyDatabase\NewAccessDatabase.accdb")
      End Sub
  End Class
  </code></pre>
  
  <p>The error occurs on the last line of the method with the call to OpenCurrentDatabase.</p>
  
  <p>I have read on other forums that this error can be fixed by clicking on Visual Studio's Build menu, opening the Configuration Manager screen, and changing the Platform setting.  I have done that, but with no luck.  However, I am sometimes able to get a different error message (on the same line of code) that reads, </p>
  
  <blockquote>
    <p>System.InvalidCastException: 'Unable to cast COM object of type
    'Microsoft.Office.Interop.Access.ApplicationClass' to interface type
    'Microsoft.Office.Interop.Access._Application'. This operation failed
    because the QueryInterface call on the COM component for the interface
    with IID '{68CCE6C0-6129-101B-AF4E-00AA003F0F07}' failed due to the
    following error: Error loading type library/DLL. (Exception from
    HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'</p>
  </blockquote>
  
  <p>However, resolving this error hasn't been any easier than resolving the first one.</p>
  
  <p>If someone could help me to resolve this error, I would really appreciate it.  I didn't think that one method call to OpenCurrentDatabase could cause so much difficulty, but it is!</p>