title: Cannot use loaded Oracle.ManagedDataAccess assembly in Powershell
body: <p>I am trying to connect to an existing oracle database using Powershell and Oracle.ManagedDatabaseAccess.dll. I have the code running in C# using the very same library.
  The assembly is loaded but i cannot use it.</p>
  <p>I am using Win10 and Powershell ISE.
  I also use VS2017/15.3.2 and .Net 4.7.02046.</p>
  <p>I tried using &quot;Add-Type -AssemblyName&quot; and &quot;Add-Type -Path&quot; which did not work at all. Both options showed errors immediately.</p>
  <p>I was able to call</p>
  <pre><code>[Reflection.Assembly]::LoadFile(&quot;myrootpath\.nuget\packages\oracle.manageddataaccess.core\2.18.5\lib\netstandard2.0\Oracle.ManagedDataAccess.dll&quot;)
  </code></pre>
  <p>but i got:</p>
  <pre><code>GAC    Version        Location 
  ---    -------        --------                                                                                                                                                                
  False   v4.0.30319     C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Oracle.ManagedDataAccess\v4.0_2.0.18.3__89b483f429c47342\Oracle.ManagedDataAccess.dll       
  </code></pre>
  <p>I added the Assembly manually to the GAC using gcautil.
  Now i get</p>
  <pre><code>GAC    Version        Location   
  ---    -------        --------                                                                                                                                                                
  True   v4.0.30319     C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Oracle.ManagedDataAccess\v4.0_2.0.18.3__89b483f429c47342\Oracle.ManagedDataAccess.dll  
  </code></pre>
  <p>Now when i call:</p>
  <pre><code>$command = New-Object Oracle.DataAccess.Client.OracleCommand($sql,$conn)
  </code></pre>
  <p>i get the following error:</p>
  <pre><code>New-Object : The Type [Oracle.ManagedDataAccess.Client.OracleConnection] cannot be found. Make sure that you load the Assembly that contains this Type.
  In Line:2 Character:8
  + $conn= New-Object Oracle.ManagedDataAccess.Client.OracleConnection($c ...
  +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
      + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
  </code></pre>
  <p>I read about the solution to compile a small C# console application (since that works) and call it from powershell. This might be feasible, however i really want to understand what the issue is here.
  Any help is greatly appreciated.</p>
  <h1>Update/Edit:</h1>
  <pre><code>PS H:\&gt; Add-Type -Path &quot;C:\mypath\Oracle.ManagedDataAccess.dll&quot;
  Add-Type : At least one type in the assembly could not be loaded.
      + CategoryInfo          : NotSpecified: (:) [Add-Type], ReflectionTypeLoadException
      + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
   
  PS H:\&gt; $error[0].Exception.LoaderExceptions[0]
  The type &quot;System.IO.Stream&quot; in the assembly &quot;netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51&quot; could not be loaded.
  </code></pre>
  <p>Netstandard2.0.0.0 is a requirement for the Oracle.ManagedDataAccess.dll, which also had to be installed in my VS project.</p>
  <p>System.IO.Stream should be available in PS without loading. Might be a version conflict because my main development environment is .Net 4.7.02046?</p>