Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

difficulty loading assembly from NuGet #27

Open
dbist opened this issue Mar 10, 2020 · 0 comments
Open

difficulty loading assembly from NuGet #27

dbist opened this issue Mar 10, 2020 · 0 comments

Comments

@dbist
Copy link

dbist commented Mar 10, 2020

# List available modules, specifically, we're looking for Npgsql driver loaded.
Get-Module -ListAvailable
Directory: /usr/src/jupyter-powershell/Modules


ModuleType Version    Name                                ExportedCommands                                              
---------- -------    ----                                ----------------                                              
Manifest   1.1.0.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}                            
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}                           
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPolicy, ...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}    
Script     1.1.7.0    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packag...
Script     1.6.0      PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}  
Script     0.0        PSDesiredStateConfiguration         {ThrowError, Get-PSMetaConfigDocumentInstVersionInfo, New-D...
Script     1.2        PSReadLine                          {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, Remove...
# List available repos, specifically, we're looking for Nuget where Npgsql is available
Get-PackageSource
Name                             ProviderName     IsTrusted  Location                                                   
----                             ------------     ---------  --------                                                   
MyNuGet                          NuGet            False      https://www.nuget.org/api/v2                               
PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2
# If unavailable, register Nuget repo
Register-PackageSource -Name MyNuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet
Register-PackageSource : Package Source 'MyNuGet' exists.



At line:2 char:1
+ Register-PackageSource -Name MyNuGet -Location https://www.nuget.org/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CategoryInfo          : ResourceExists: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-PackageSource], Exception

FullyQualifiedErrorId : PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource
# Search for the package after repo is added.
Find-Package Npgsql
Name                           Version          Source           Summary                                                
----                           -------          ------           -------                                                
Npgsql                         4.1.3.1          MyNuGet          Npgsql is the open source .NET data provider for Pos...
# Install Npgsql from the newly added repo
Install-Package Npgsql -Force -SkipDependencies -Scope CurrentUser 
Name                           Version          Source           Summary                                                
----                           -------          ------           -------                                                
Npgsql                         4.1.3.1          MyNuGet          Npgsql is the open source .NET data provider for Pos...
# Verify Npgsql is installed
Get-Package -Name Npgsql 
Name                           Version          Source                           ProviderName                           
----                           -------          ------                           ------------                           
Npgsql                         4.1.3.1          /usr/local/share/PackageManag... NuGet
# Get the strong Name of the assembly for reference
[System.Reflection.AssemblyName]::GetAssemblyName('/usr/local/share/PackageManagement/NuGet/Packages/Npgsql.4.1.3.1/lib/netstandard2.1/Npgsql.dll').FullName
Npgsql, Version=4.1.3.1, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
# Import the Npgsql library for use (Doesn't work in Jupyter)
Import-Module '/usr/local/share/PackageManagement/NuGet/Packages/Npgsql.4.1.3.1/lib/netstandard2.1/Npgsql.dll' 
Import-Module : Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.




At line:2 char:1
+ Import-Module '/usr/local/share/PackageManagement/NuGet/Packages/Npgs ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException

FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
# Doesn't work in Jupyter
Add-Type -Path '/usr/local/share/PackageManagement/NuGet/Packages/Npgsql.4.1.3.1/lib/netstandard2.1/Npgsql.dll' 
# https://books.google.com/books?id=yxiUDwAAQBAJ&pg=PA138&lpg=PA138&dq=powershell+npgsql&source=bl&ots=MCjIQZIpC6&sig=ACfU3U0YPc74WsKicn02hW5VelSTEFPVKQ&hl=en&sa=X&ved=2ahUKEwi8p9GV0I3oAhXFc98KHZrQCPwQ6AEwB3oECAsQAQ#v=onepage&q=powershell%20npgsql&f=false
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Npgsql/4.1.3.1 -OutFile .\postgres.zip
Expand-Archive .\postgres.zip
ls $bin
postgres
postgres.zip
share
Add-Type -Path /home/jovyan/.local/postgres/lib/netstandard2.1/Npgsql.dll -ReferencedAssemblies "/usr/src/jupyter-powershell/System.*.dll"
# List current assemblies
[System.AppDomain]::CurrentDomain.GetAssemblies() #| Select-String "Npgsql"
GAC    Version        Location                                                                                          
---    -------        --------                                                                                          
False  v4.0.30319     /usr/src/jupyter-powershell/System.Private.CoreLib.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/PowerShell-Kernel.dll                                                 
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.dll                                                    
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Logging.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/netstandard.dll                                                       
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Logging.Abstractions.dll                         
False  v4.0.30319     /usr/src/jupyter-powershell/Jupyter.dll                                                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.Extensions.dll                                         
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.FileSystem.dll                                              
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Configuration.dll                                
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Configuration.Abstractions.dll                   
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Configuration.Json.dll                           
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Configuration.Binder.dll                         
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.Thread.dll                                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Console.dll                                                    
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Logging.Debug.dll                                
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Logging.Console.dll                              
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.Debug.dll                                          
False  v4.0.30319     /usr/src/jupyter-powershell/System.Linq.dll                                                       
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.FileProviders.Abstractions.dll                   
False  v4.0.30319     /usr/src/jupyter-powershell/System.Management.Automation.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Options.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/System.Collections.dll                                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.dll                                                  
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.InteropServices.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Configuration.FileExtensions.dll                 
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.FileProviders.Physical.dll                       
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.Primitives.dll                                   
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.FileSystem.Watcher.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/System.ComponentModel.Primitives.dll                                  
False  v4.0.30319     /usr/src/jupyter-powershell/System.Collections.Concurrent.dll                                     
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.Tasks.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Extensions.FileSystemGlobbing.dll                           
False  v4.0.30319     /usr/src/jupyter-powershell/Newtonsoft.Json.dll                                                   
False  v4.0.30319     /usr/src/jupyter-powershell/System.Dynamic.Runtime.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/System.Linq.Expressions.dll                                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.ObjectModel.dll                                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.dll                                                         
False  v4.0.30319     /usr/src/jupyter-powershell/System.Globalization.dll                                              
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.Numerics.dll                                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Private.Uri.dll                                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.ComponentModel.TypeConverter.dll                               
False  v4.0.30319     /usr/src/jupyter-powershell/System.ComponentModel.dll                                             
False  v4.0.30319     /usr/src/jupyter-powershell/System.Collections.Specialized.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/System.Drawing.Primitives.dll                                         
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.InteropServices.RuntimeInformation.dll                 
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.Serialization.Primitives.dll                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.Serialization.Formatters.dll                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.dll                                                 
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.Extensions.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.Emit.ILGeneration.dll                               
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.Primitives.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.Emit.Lightweight.dll                                
False  v4.0.30319                                                                                                       
False  v4.0.30319     /usr/src/jupyter-powershell/System.Text.Encoding.Extensions.dll                                   
False  v4.0.30319     /usr/src/jupyter-powershell/System.Resources.ResourceManager.dll                                  
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.TraceSource.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/System.Xml.ReaderWriter.dll                                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Private.Xml.dll                                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.FileVersionInfo.dll                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.Metadata.dll                                        
False  v4.0.30319     /usr/src/jupyter-powershell/System.Collections.Immutable.dll                                      
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.MemoryMappedFiles.dll                                       
False  v4.0.30319     /usr/src/jupyter-powershell/System.Text.RegularExpressions.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.AccessControl.dll                                     
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.Tracing.dll                                        
False  v4.0.30319     /usr/src/jupyter-powershell/System.Reflection.Emit.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.Timer.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.Tasks.Parallel.dll                                   
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.PowerShell.Security.dll                                     
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Principal.dll                                         
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.FileSystem.DriveInfo.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/System.Runtime.Loader.dll                                             
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Management.Infrastructure.dll                               
False  v4.0.30319     /usr/src/jupyter-powershell/System.Net.Primitives.dll                                             
False  v4.0.30319     /usr/src/jupyter-powershell/System.Net.NetworkInformation.dll                                     
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Cryptography.X509Certificates.dll                     
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Cryptography.Encoding.dll                             
False  v4.0.30319     /usr/src/jupyter-powershell/System.Net.Mail.dll                                                   
False  v4.0.30319     /usr/src/jupyter-powershell/System.Collections.NonGeneric.dll                                     
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.FileSystem.AccessControl.dll                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Principal.Windows.dll                                 
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Win32.Registry.dll                                          
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.Process.dll                                        
False  v4.0.30319     /usr/src/jupyter-powershell/System.Data.Common.dll                                                
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Cryptography.Primitives.dll                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Cryptography.Algorithms.dll                           
False  v4.0.30319     /usr/src/jupyter-powershell/NetMQ.dll                                                             
False  v4.0.30319     /usr/src/jupyter-powershell/System.Net.Sockets.dll                                                
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.Win32.Primitives.dll                                        
False  v4.0.30319     /usr/src/jupyter-powershell/AsyncIO.dll                                                           
False  v4.0.30319     /usr/src/jupyter-powershell/System.Text.Encoding.dll                                              
False  v4.0.30319     /usr/src/jupyter-powershell/System.Net.NameResolution.dll                                         
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.ThreadPool.dll                                       
False  v4.0.30319     /usr/src/jupyter-powershell/System.Text.Encoding.CodePages.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.PowerShell.Commands.Management.dll                          
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.PowerShell.Commands.Utility.dll                             
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.PowerShell.ConsoleHost.dll                                  
False  v4.0.30319     /usr/src/jupyter-powershell/System.Security.Claims.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/System.Net.Http.dll                                                   
False  v4.0.30319     /usr/src/jupyter-powershell/System.Threading.AccessControl.dll                                    
False  v4.0.30319     /usr/src/jupyter-powershell/Modules/PackageManagement/1.1.7.0/coreclr/netcoreapp2.0/Microsoft.P...
False  v4.0.30319     /usr/src/jupyter-powershell/Modules/PackageManagement/1.1.7.0/coreclr/netcoreapp2.0/Microsoft.P...
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.CodeAnalysis.CSharp.dll                                     
False  v4.0.30319     /usr/src/jupyter-powershell/Microsoft.CodeAnalysis.dll                                            
False  v4.0.30319     /usr/src/jupyter-powershell/System.ValueTuple.dll                                                 
False  v4.0.30319     /usr/src/jupyter-powershell/System.Xml.XDocument.dll                                              
False  v4.0.30319     /usr/src/jupyter-powershell/System.Private.Xml.Linq.dll                                           
False  v4.0.30319                                                                                                       
False  v4.0.30319     /usr/src/jupyter-powershell/Modules/PackageManagement/1.1.7.0/coreclr/netcoreapp2.0/Microsoft.P...
False  v4.0.30319     /usr/src/jupyter-powershell/Modules/PackageManagement/1.1.7.0/coreclr/netcoreapp2.0/Microsoft.P...
False  v4.0.30319     /usr/src/jupyter-powershell/Modules/PackageManagement/1.1.7.0/coreclr/netcoreapp2.0/Microsoft.P...
False  v4.0.30319     /usr/src/jupyter-powershell/Modules/PackageManagement/1.1.7.0/coreclr/netcoreapp2.0/Microsoft.P...
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319                                                                                                       
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.Compression.dll                                             
False  v4.0.30319     /usr/src/jupyter-powershell/System.Buffers.dll                                                    
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.StackTrace.dll                                     
False  v4.0.30319     /usr/local/share/PackageManagement/NuGet/Packages/Npgsql.4.1.3.1/lib/netstandard2.1/Npgsql.dll    
False  v4.0.30319     /usr/src/jupyter-powershell/System.Linq.Parallel.dll                                              
False  v4.0.30319     /usr/src/jupyter-powershell/System.Diagnostics.DiagnosticSource.dll                               
False  v4.0.30319     /usr/src/jupyter-powershell/System.IO.Compression.ZipFile.dll                                     
False  v4.0.30319
# doesn't work yet, this is helpful https://stackoverflow.com/questions/34674761/how-to-import-the-npgsql-module

$connection = [Npgsql.NpgsqlConnection]::new('Host=crdb-1;Port=26257;Username=maxroach;Password="";Database=movr')
$connection.Open()
$command = [Npgsql.NpgsqlCommand]::new('SELECT * from rides limit 10', $connection)
 : Unable to find type [Npgsql.NpgsqlConnection].



At line:3 char:15
+ $connection = [Npgsql.NpgsqlConnection]::new('Host=crdb-1;Port=26257; ...
+               ~~~~~~~~~~~~~~~~~~~~~~~~~

CategoryInfo          : InvalidOperation: (Npgsql.NpgsqlConnection:TypeName) [], ParentContainsErrorRecordException

FullyQualifiedErrorId : TypeNotFound
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant