Unable to locate System.Data.SqlClient reference - c#

I have a fresh Visual Studio 2017 Professional install. I'm building a quick POC Console application using .NET 4.7.1, and I'm unable to find the reference for System.Data.SqlClient.
I have scoured my system, and located 4 versions of System.Data.SqlClient.dll, but none are correct and won't compile.
I have also attempted to use System.Data, but no reference to SqlClient is located within. I have manually added the dll/reference for System.Data, but also did not resolve the reference issue.
My application is really simple at the moment, and it will NOT compile due to this missing reference.
What steps do I need to do to get this resolved?
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApp1
{
class Database
{
public void Start()
{
string connString = #"server=(local);initial catalog=MyDatabase;Integrated Security=SSPI;";
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 ID, Name FROM TableA", conn))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
Console.WriteLine("ID: [{0}], Name: [{1}]", reader.GetValue(0), reader.GetValue(1));
}
}
}
}
}
}
}

dotnet add package System.Data.SqlClient

You just have to add reference option in solution explorer and after that, if it is not working you need to change class library use ".net framework" apart from ".net standard"

New issue. Microsoft removed System.Data.SqlClient from newer versions of Visual Studio and .NET Core. The fix is to install the NuGet package System.Data.SqlClient. In other words, you might not find the DLL on your system and need to add it using NuGet.
In the Solution Explorer, right-click References and choose "Manage NuGet Packages...". Search for "System.Data.SqlClient". Choose it when found, and Install.

In my case, I had a subtle problem different from other answers.
The reference was added but it had a yellow triangle meaning I had a problem with the reference.
I had to remove it from the references dropdown
and reinstall the package with
Update-Package System.Data.SqlClient -Reinstall
Then it added the correct reference back.
I was pulling my hair apart for two days because I knew I had the reference, but never noticed it had the yellow triangle.
I thought it was only a mismatch version problem, but using binding redirects on web.config were of no avail.
It was then when I realized that System.Data.SqlClient.dll was not being copied into my bin folder. That was due to the wrong assembly reference. I don't know how this reference came to be corrupted though.

Please check your version of SQL Server on your machine, you might have more than one version of sql server express installed on your machine.
Please try to connect (localdb)/MSSQLLOCALDB from your management studio and if you are able to open try updating the connection in your program and try again.

Enough to add reference "System.Data.SqlClient";
The same answer as above, simply select LIB class ".net framework" while it`s needed to add lib class into the your project.

Related

The type or namespace name 'SQLite' does not exist in the namespace 'System.Data'

This might be a repetition of a question that already has been posted although I am still stuck after I read the answer, I am using .net framework 4.0, I don't understand how to fix this issue.
I keep receiving this message: The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' and the function SQLiteConnetion is not recognized.
I have already installed System.Data.SQlite, should I install another version ? if so, which version should I install ?
when installing any package kindly check that the minimum target framework is reached this may help you to sort it out, and in all cases, you can achieve the desired tasks by following this scenario:
Install-Package Microsoft.Data.Sqlite -Version 5.0.7
set project target framework to 4.6.2
using Microsoft.Data.Sqlite;
code snippet will be something like the following
string connectionStr = "//////";
using (var con = new SqliteConnection(connectionStr))
{
con.Open();
var cmd = new SqliteCommand("SELECT SQLITE_VERSION()", con);
string version = cmd.ExecuteScalar().ToString();
Console.WriteLine($"SQLite version: {version}");
}

Type or namespace name TSocket could not be found apache thrift C# Visual Studio 2019

Screenshot of installed thrift package and Thrift.dll reference:
I am trying to create a simple thrift client in Visual Studio 2019 using C#. I have generated the c# thrift bindings and everything else. However, I get "Type or namespace name "TSocket" could not be found". I have no other errors. Here is a snippet from my setup code:
// imports, namespaces
using System;
using System.Net;
using Thrift;
using Thrift.Transport;
using Thrift.Protocol;
TTransport socket1 = new TSocket("hostname", port);
TTransport transport = new TFramedTransport(socket1);
(more stuff .....)
I have no other issues with other references to thrift modules within the client. It just can't find "TSocket" somehow. I am super new to c# and thrift.
I am using thrift 0.14.1 and have installed it using the NuGet packages add-on Visual Studio 2019.
What could be the problem? Thanks.
screenshot of error
After looking at, it seems "TSocket" is not even listed under Transport as you can see in the screenshot below.
screenshot of available modules under Thrift Transport
Thrift 0.14 changed some names and the nested namespace structure. What was Thrift.Transport.TSocket is now Thrift.Transport.Client.TSocketTransport. See if swapping that fixes it.
If not check your project ref to the Thrift lib. Something like this may help (quoting "The Programmer's Guide to Apache Thrift"):
"To add the C# Apache Thrift library reference, right-click the References item in the project in the Solution Explorer and choose “Add Reference”. Next use the “Browse...” button to locate the Thrift.dll in thrift/lib/csharp/src/bin/Debug (or wherever). Make sure that there is a check next to the Thrift.dll entry in the Reference Manager dialog and then click OK. After a brief pause Intelisense errors should clear."
... or using the package manager:
"To add a Thrift.dll reference you can simply run the PackageManager install command:
PM> Install-Package -Prerelease ApacheThrift -ProjectName <your proj name here>
'ApacheThrift 1.0.0-dev' already installed.
Adding 'ApacheThrift 1.0.0-dev' to tradeServer.
Successfully added 'ApacheThrift 1.0.0-dev' to tradeServer.
"

VSCode C# Issue Adding An Assembly Reference

I have the C# VSC extension as well as the NuGet Package Manager installed. Here is my VSC version info:
First, I create a brand new console application in VSC with the command:
dotnet new console
This gives me the code:
using System;
namespace ReferenceTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
I now want to create a using System.Windows.Forms; reference. When I start typing this using statement however, intelli-sense fails me:
I found this question/answer already but in step #5 the autofill option shown is not there:
When I try to improvise and follow other instructions I've found in my searching by using the
NuGet Package Manager: Add Package
option, I cannot select System.Windows.Forms
I have looked for a project.json file per the instructions of several sites but I can only find a project.assets.json file and it doesn't look very similar to what I see in the examples I find. This issue is not only for System.Windows.Forms but other references I try as well.
Windows Forms and WPF applications are not supported in .NET Core, only in .NET Framework.
have a look at the following article:
https://stackify.com/net-core-vs-net-framework/

Could not load file or assembly 'Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342'

I have installed oracle 11 g r 2 in the server, and I downloaded ODAC112040Xcopy_64bit and installed the .net components.
I copied Oracle.DataAccess.dll that exists in this location Oracle_Folder\odp.net\bin\4 to the bin folder inside my Visual Studio project
When I executed my code, I got this exception:
An unhandled exception of type 'System.BadImageFormatException' occurred in TestOracleConnection.exe
Additional information: Could not load file or assembly 'Oracle.DataAccess, Version=4.112.4.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.
My code is:
public string CallCardDetails(string CallCardNo)
{
//initialize
using (DataSet ds = new DataSet())
{
//connect
using (OracleConnection conn = new OracleConnection("User Id=oraDB;Password=ora;Data Source=CCT"))
{
// Oracle uses : for parameters, not #
string query = "SELECT idcard from CallCardTable where idcard= :pCallCardNo";
// Let the using block dispose of your OracleCommand
using (OracleCommand cmd = new OracleCommand(query, conn))
{
// Note: be careful with AddWithValue: if there's a mismatch between the .NET datatype of
// CallCardNo and the idcard column you could have an issue. Cast the value you provide
// here to whatever is closest to your database type (String for VARCHAR2, DateTime for DATE, Decimal for NUMBER, etc.)
cmd.Parameters.Add(":pCallCardNo", CallCardNo);
conn.Open();
// Again, wrap disposables in a using or use try/catch/finally (using will dispose of things in case of exceptions too)
using (OracleDataAdapter dA = new OracleDataAdapter(cmd))
{
dA.Fill(ds);
return ds.GetXml();
}
}
}
}
}
Okay, I'm going to suggest the following based on my experience with ODP.NET:
Your system is attempting to load the 64 bit Oracle DLL, and can't because the application is running in 32 bit mode. Try setting your application to explicitly be 64 Bit. Alternatively, install the 32 bit ODP.Net drivers and see if those work any better.
Had a similar problem some time ago...
Referring to this question here:
Try to set your projects 'Platform target' to 'x86' and not 'Any CPU'.
Hope this helps!
This is how I resolved it:
Install-Package ODP.NET4 -Version 4.112.3
Check that target framework of the dll and your project match.The file location you posted shows you took it from Oracle_Folder\odp.net\bin\4 the bin folder for 4 version. Look if there is the req dll in bin\4.5 that maybe what you need. As this exception can also occur if you add dlls to your project whose target framework do not match.
Also, clean your solution before placing the dll in bin folder. :)
I usually use the NuGet packages for ODP.net, they work fine. You can find them here.
This is all you need to build your solution, you do not need to install any drivers.
In order to use the Oracle Data Prover for .NET (ODP.NET) Version 4.112.4.0 64bit following conditions must apply:
Target Framework is 4.0 or higher
Architecture must be x64 or AnyCPU (in case of an 64bit Windows, which is most likely the case)
An 64-Bit Oracle Client version 11.2 is installed on your PC and on the target machine
Find some more information in this anser: The provider is not compatible with the version of Oracle client

Beginner ILNumerics: install under VS2012

I am very much interested in ILNUmerics and would like to try the free version, but I am having troubles.
I have started with a console application and was trying to run the 'hello ilnumerics'console application but I noticed that VS fails to find MKL libraries.
I am using VS2012 under Windwos 8 (through Bootcamp on a MacBook Pro mid 2010; should it be relevant); I have installed the NuGet Packages extension from the Project solution. Then right-click on references in the solution explorer, 'Manage Nu Get Packages', fron online/search found ilnumerics in various versions. I chose 'ILNumerics' and install. I got 'ILNumerics' and 'ILNumerics.Native' added to my project. Then I can see ILNumerics under 'References' in Solution Explorer and also get two new folders /bin32/ and /bin64/ they both contain two DLLs named: libiomp5md.dll and mkl_custom.dll. I have checked their
'Copy to Ouput Directory' property and they are all set to 'Copy if newer'.
Apparently mkl_custom is not found. I write the following code, taken from the quickstart guide:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ILNumerics;
namespace ConsoleApplication3
{
class Program : ILMath
{
static void Main(string[] args)
{
ILArray<double> A = array<double>
(new double[] { 1,1,1,1,1,2,3,4,1,3,6,10,1,4,10,20} ,4, 4);
ILArray<double> B = counter(4, 2);
ILArray<double> Result = linsolve(A, B);
Console.Out.WriteLine("A: " + Environment.NewLine +
A.ToString());
Console.Out.WriteLine("B: " + Environment.NewLine + B.ToString());
Console.ReadKey();
}
}
}
and I get this exception:
An unhandled exception of type 'System.DllNotFoundException' occurred in ILNumerics.dll
Additional information: Unable to load DLL 'mkl_custom': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
If I do not invoke linsolve the ToString method of ILArray does work: if I comment // ILArray Result = linsolve(A, B);
I get the two matrices printed on the screen.
I have also tried to compute the determinant of a matrix and got the same exception: apparently any time I call mkl_custom VS is not capable to find it.
Any help/hint, please?
Also, is it necessary to install ILNumerics through NuGet on any project added to the solution? Would it be possible to install it locally once for all and then add the reference if necessary?
Two options:
1) Make sure, all binaries are accesible as intended: ILNumerics uses AnyCPU targets and chooses the platform dependend subfolder by adding the "bin32" / "bin64" directories to the PATH envoronment variable on startup. Possibly there is something failing on your machine? You can make sure by placing the correct binaries (depending on your platform) directly into the output path manually.
2) In case the error persists: mkl_custom.dll depends on some other dlls itself. One (libiomp5md.dll) is delivered with the ILNumerics nuget package. Others are expected to exist on your system: KERNEL32.DLL and MSVCR110.DLL. Make sure, you have these! If the kernel dll was missing -> call it a miracle and reinstall your system. If the msvcr110 is missing -> go here and install the "Visual C++ Redistributable for Visual Studio 2012".
In case the problem persists, you may file a bug on the ILNumerics bugtracker, because, the runtime should be there, as you wrote you are using VS2012. Possibly it is a versioning problem though.
EDIT: Since version 4.0 ILNumerics does not deploy the native binaries in bin32/ bin64/ subfolder anymore but installs all native dependencies systemwide into the GAC and System32/WOW folders. The old scheme will still work (for compatibility with old projects) though. But it is not necessary anymore to deal with any dependancies for ILNumerics explicitly. They should simply be found at runtime.
Like numbers303 said, ILNumerics.dll can't find a required dependency. You can brute force fixing this dependency by copying the required DLLs to the same directory as the ILNumerics.dll as a post build step, but I think there's a more elegant solution.
A VS2010 .NET console solution gets created by default with the x86 configuration. Compiling and running the ILNumerics example Hello ILNumerics! code with this configuration results in a DLL not found exception (mkl_custom.dll).
Re-targeting the solution via configuration manager to 'Any CPU' fixed the issue for me:
In Solution Explorer, right click on the solution and select properties. Select Configuration Properties and click on the Configuration Manager... button in the upper right hand corner. Make sure that the project that uses ILNumerics has the 'Any CPU' selected. If 'Any CPU' isn't available as a selection, select '' from the pulldown and create an 'Any CPU' platform based on your current platform. Usually this just means accepting the default in the 'New Project Platform' dialog. You'll probably also want to modify the 'Active solution platform:' to contain an 'Any CPU' target as well.
Rebuild/run.
In my case it helped to install "Visual C++ Redistributable for Visual Studio 2012" although I work with Visual Studio 2010 with the corresponding "Visual C++ Redistributable for Visual Studio 2010" installed. Which worked fine as long as the mkl_custom.dll is not needed. But colleagues of mine dosn't have this problem without having the 2012 Redistributable installed.

Categories