Install/Use NpgSQL on Visual Studio 2010 - postgresql

I'm trying to connect to a Postgres 9.5 database using VB.NET/VS2010. I've got the 4.5 .NET framework installed and the project is targeting ".NET Framework 4". I used Npgsql-3.2.5.msi to install the NpgSQL.dll and referenced the dll, but was unable to build the project, or see any of the NpgSQL objects in the intellisense. I had tried using NuGet for the current version, but it threw errors when i tried to install it. I used
"Install-Package Npgsql -Version 3.2.5"
I did some research and was able to install the NuGet Legacy package
"Install-Package Npgsql.EntityFrameworkLegacy -Version 2.2.7"
but the project still refuses to build and I'm still unable to access the Npgsql objects, at least in the intellisense. When I try to build I get
"Could not load file or assembly 'PostGreSQL Test.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded." as an error.
Any help in getting a version of Npgsql to work with Visual Studio 2010 would be greatly appreciated! or at least let me know if it's not possible. This will be a read only connection.
here's the chunk of sample code i'm starting with:
Private Sub GetData()
Using conn = New Npgsql.NpgsqlConnection(connectionString)
conn.Open()
' Retrieve all rows
Using cmd = New Npgsql.NpgsqlCommand("SELECT some_field FROM data", conn)
Using reader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine(reader.GetString(0))
End While
End Using 'reader
End Using 'cmd
End Using 'conn
End Sub

Related

Why can't I install Microsoft.EntityFrameworkCore.Sqlite?

I am following this tutorial:
https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=visual-studio
I am immediately stopped because I can not complete the following command:
Install-Package Microsoft.EntityFrameworkCore.Sqlite
This is the error:
Could not install package 'Microsoft.EntityFrameworkCore.Sqlite.Core 7.0.0'. You are trying to install a package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I am attempting to learn how to use the Entity Framework and so I don't know much regarding this. Any advice would be helpful even if it's a link to something I need to read.
About the tutorial
The tutorial is about .netCore but in the error message you can see that you created a .netFramework project '.NETFramework,Version=v4.7.2'.
Create a new console application, but don't select projects that have (.NET Framework) in the description.
About the Sqlite package (only if continue the practicing with .netFramework)
The command Install-Package Microsoft.EntityFrameworkCore.Sqlite will try to install the last version. Currently, the last version is 7.0.0. This version only work with .NET 6.0.
You can check existing .net versions right here
So, you need to specify the version. The version for .NET 4.7.2 is the 3.1.31.
Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 3.1.31
Nuget Sqlite package info here

There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'ios-arm64'

I was using VS Enterprise 17.3 preview 1 but my trial was expiring so I download and installed VS Community 17.3 preview 1. I open my MAUI project and build and I get this error;
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'maccatalyst-x64
I assume I must've missed something in the installation so I go back but all the relevant components are installed
I double check with the Enterprise installation and they match. I then go back to opening the project in VS Enterprise and now I get the same error there too!?
I've tried deleting bin/obj folders cleaning and rebuilding;
I've tried adding this to the .csproj
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
I've tried changing the TargetFrameworks from this:
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
To this (and a few other combinations):
<TargetFrameworks>net6.0-android;</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
So I'm now stuck unable to build :( help pls
Turns out I had an error in a blazor file that the compiler wasn't referencing. The 'no runtime pack' error was a red herring and unrelated to the actual error.

Dotnet restore not working

dotnet Version: 1.1.0 (global.json)
NuGet Version : 4.4.1.4656
VS2017 v15.5.2 (as Administrator)
.NET Core 1.1
The solution I am trying to build
Update I:
I just changed the project to run under target framework .NET Core v2.0 & sdk version 2.1.3 and I only get these kind of errors:
Severity Code Description Project File Line Suppression State
Error NU1202 Package Microsoft.Extensions.FileProviders.Physical 1.1.0
is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0).
Package Microsoft.Extensions.FileProviders.Physical 1.1.0 does not
support any target
frameworks. AspNetCoreExample C:\Users\Admin\Source\Repos\Examples\src\AspNetCoreExample\AspNetCoreExample.csproj 1
Update II:
While the following solves the current issue, i am not sure if it solves the root cause for this issue.
Delete the global nuget.config file %AppData%/Nuget/Nuget.config.
I fixed this issue by doing the following:
I migrated the project to .net core 2.0 and changed the global.json to point to sdk 2.1.3.
Removed all references in AspNetCoreExample manually and added the latest version for all of them.
Issues with target framework 1.1
When doing a restore from the solution in VS 2017:
When doing the restore from cmd (dotnet restore)
Running dotnet restore in Package Manager Console
NuGet.targets(103,5): error : Access to the path 'System.Runtime.dll'
is denied
.NET Core SDKs installed:
.NET Host
Now when opening the solution I get:
Comparing the log entries you pasted to their AppVeyor build,
https://ci.appveyor.com/project/Autofac/examples
Your machine's NuGet configuration seems to be broken. Analyze that and fix the issues.
You should add this code to your .csproj file
<RuntimeFramework>2.0.3</RuntimeFramework>
This worked for me.

NuGet restore during first asp.net vNext project

Today I installed ASP.NET 5 on windows and begun creating my first application in Visual Studio 2015.
When the project loads I get an error: "Package restore failed", specifically the following error:
Restore failed Det gick inte att hitta en del av s�kv�gen C:\Users\h\.dnx\packages\Microsoft.Win32.Primitives\4.0.0\Microsoft.Win32.Primitives.4.0.0.nupkg.sha512. NuGet Config files used:
C:\Users\h\AppData\Roaming\NuGet\nuget.config
C:\Users\h\documents\visual studio 2015\Projects\NextTest\nuget.config
Feeds used:
https://api.nuget.org/v3-flatcontainer/
C:\Program Files (x86)\Microsoft Web Tools\DNU
When I look for the missing file I find the following path missing:
C:\Users\h\.dnx\packages\Microsoft.Win32.Primitives\4.0.0\Microsoft.Win32.Primitives.4.0.0.nupkg.sha512
But this one exists, note the extra 0 in the version:
C:\Users\h\.dnx\packages\Microsoft.Win32.Primitives\4.0.0.0\Microsoft.Win32.Primitives.4.0.0.0.nupkg.sha512
How would I go about to solve this?
I've tried to search through the project files but no mention of neither Primitives nor verion 4.0.0.
The "Solution DNX SDK version" is 1.0.0-beta8, (beta5 was also available but not selected).
Delete C:\Users\h.dnx\packages folder and try running "dnu restore" command.

Trying to Add-Migration - Exception in Package Manager Console: "Cannot get an instance of EnvDTE.DTE"

I have been migrating my project to Visual Studio 2015 RC. I have also refactored it into separate projects. Now I need to add a migration for a model change in entity framework but as soon as I open the Package Manager Console I get this error message:
Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE At C:\Users...\Visual Studio 2010\Projects\MyProject\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:30
If I clear the console and try again, I get "an exception has been encountered" - with more information in the activity log. Inspect the activity log and the exception is:
System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values. Parameter name: span at
Microsoft.VisualStudio.Text.SnapshotSpan..ctor(ITextSnapshot snapshot,
Span span) at
NuGetConsole.Implementation.Console.WpfConsoleClassifier.GetClassificationSpans(SnapshotSpan
span) at
Microsoft.VisualStudio.Text.Classification.Implementation.ClassifierTagger.d__1.MoveNext()
at
Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.d__1.MoveNext()
I realised that I had removed some packages that I probably should not have. So I re-installed these:
ModelScaffolding 0.9.2
MvcScaffolding 1.0.9
T4Scaffolding 1.0.8
This appears to have taken the second exception (ArgumentOutOfRangeException) away. However, now when I try Add-Migration I get
Join-Path : Cannot bind argument to parameter 'Path' because it is
null. At C:\Users...\Visual Studio
2010\Projects\MyProject\packages\EntityFramework.6.1.0\tools\EntityFramework.psm1:713
char:27
I tried uninstalling and re-installing Entity Framework. I noticed during install that the Join-Path error was displayed again, but package-manager continued, and reported a successful install. I still got the error when I tried Add-Migration
Then I opened the solution in Visual Studio Express 2013. I still get the initial Cannot get an instance of EnvDTE.DTE error, but I can clear the console window and I can add a migration - Phew!
I'd still like to get rid of that error message...and use VS 2015...
There was an error in the NuGet VS extension. You can fix this by installing the latest NuGet (not available through VS yet). This may require an update of Powershell and/or Windows Management Framework.