Entity Framework throws an error in my .net namespace - c#

Error:
The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
As you can see my Entity Framework is complaining at the reference, tried to solve it but got nowhere. Has someone experienced this problem before? I'm basically trying to do this:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Go to your solution and follow this steps(provided that you use a downloaded zip from the page you specified):
Right click on sln node and Enable Nuget package restore, then rebuild you sln.
If not already installed try open the Manage Nuget Package and check EF is installed.
Would not recommend loading dll by hand, but you can try adding it.

Related

NET core - Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ', .NET 6

I have converted .NET Framework 3.5 TestAPP to .NET 6 TestAPP and worked well.
i have an Automation project(C++ project) which was using .NET Framework 3.5 TestAPP.dll to run the tests, but right now i have replaced the .NET Framework 3.5
.dll with .NET 6 TestAPP i.e. TestAPP.dll
when i ran the exe in command line , i have got an error as
"Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)"
Please let me know if anything needs to be corrected.
Resolved the error by changing the C++/CLI properties from visual studio project properties , which was referring to .NET framework earlier and i have changed the property as .NET core runtime(clr:netcore) and it is internally handled all GAC changes and worked well.
Hope it might help someone .
When upgrading an app to a later .NET version, edit your csproj file and make sure there is no <RuntimeFrameworkVersion> node in there that someone may have inserted manually.
This will not be updated automatically when switching .NET versions
The running project returned this error. When I changed it to the way in the image, the error was solved.
Project>Properties
In my case the error was due to worng Default Project in Package Manager Console, if you are running EF migrations or something that is in a project that need to get info from the API make sure you are targetting the right project, also try clean + build first.

Fixing "They type 'X' exists in both 'Y' and 'Z'" C# error for System.ServiceModel in LINQPad

If I:
Create a new C# query in LINQPad 6.
Add the System.ServiceModel.Http NuGet package or another package that references it.
Try to instantiate a class from the System.ServiceModel namespace, for example System.ServiceModel.BasicHttpBinding.
Leading to the following .linq file:
<Query Kind="Expression">
<NuGetReference>System.ServiceModel.Http</NuGetReference>
</Query>
new System.ServiceModel.BasicHttpBinding()
Then I get a compile error:
CS0433 The type 'BasicHttpBinding' exists in both 'System.Private.ServiceModel, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.ServiceModel.Http, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
If I create a project in Visual Studio and add the same NuGet package and code, I do not get this error.
According to the C# Language reference for the error, it should be possible to resolve by using the -reference compiler option or by not referencing one of the assemblies. However, I can't seem to find a way to use this compiler option in LINQPad, nor can I find any way to remove the assembly reference to System.Private.ServiceModel.
How can I fix the error?
This is a bug in LINQPad, triggered by an obscure scenario. The System.Private.ServiceModel package contains a lib folder with an assembly which is required at runtime, and a ref folder with a underscore.underscore file which indicates that no assemblies should be referenced by the compiler. Because LINQPad finds no reference assemblies, it feeds the compiler the assembly in the lib folder, which causes the error.
I've got a fix ready and regression tests are currently running. The fix will likely make it into the 6.11.2 beta build, which should be released in a day or two.

Conflict Newtonsoft.Json 6.0.0.0 and 12.0.0.0 in Web Application with Web Api, C#

I have started a new Web Application in Visual Studio 2019. I have added a Web Api. Shortly after or at the same time (can't remember), I startet getting warnings like this:
Warning No way to resolve conflict between "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
I noticed but did not do anything as I decided to wait until it gave me problems.
And that is now...
I am about to use a JSon object but when writing this:
JObject jObject = JObject.Parse(result);
The compiler gives me this error:
Error CS0433 The type 'JObject' exists in both 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
I have searched the web and my conclusions are as follows:
It looks like it is Microsoft.AspNet.WebApi.Client that is the only package installed, that has a dependency on Newtonsoft.Json (>= 6.0.4)
I have installed Newtonsoft.Json (12.0.3)
In Solution Explorer. In reference list, I have only 1 reference. And that is the one for 12.0.3.
In Web.Config I have this entry (and only this for Newtonsoft.Json).
<dependentAssembly><assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/></dependentAssembly>
In my .csproj I can see 3 different references in 3 different ItemGroups:
One for v. 12.0.0.0
One for v. 12.0.2
And one for v. 12.0.3
I tried to uninstall package Newtonsoft.Json, but is not allowed as other packages are dependent on this.
I have runned this command: Update-Package Newtonsoft.Json in the Package Manager Console, which told me, that no new updates were available.
And now, I have runned out of ideas. I am stucked. Anyone knows what to do?
****New update****
I found the 6.0.0.0. Please have a look at the picture:
Here in resources I double clicked the Newtonsoft.Json reference and in the object browser I can see both 6.0.0.0 and 12.0.0.0.
As you can see, both 6.0.0.0 and 12.0.0.0 are present. 6.0.0.0 is somewhere on my C:-drive inside a SDK.
I have tried to delete the file. My project got nuts. Then I replaced that file with the 12.0.0.0 from my project. This gave me the error that assemplies did not match.
I finally copied the old .dll back. And is a bit stucked again.
Any ideas?
Okay, I fixed it.
I had 2 references in my .csproj file to Newtonsoft.Json. One pointed at packages......\xxx.12.0.3 and one pointing at packages......\xxx.12.0.2.
Both of them was above 6.0.0.0 which was the error I got. So I ignored them.
But acutally, in my project I had only 12.0.3 folder and no 12.0.2 folder. So the reference did not work and VS tried to find another place to look.
I guess it looks around, maybe using the GAC but finally it ended up deep down my local drive in one Azure SDK and found Newtonsoft.Json 6.0.0.0. And that was the problem.
I removed the 12.0.2 reference from my .csproj and finally it worked.
The issue usually comes from two different projects that use different versions of the same library.
Both of those projects are then referenced to another one and the warning effectively warns you that something like this might happen.
Go to the solution and right click - manage nuget packages.
Go to the consolidate tab. Check that newtonsoft is there. If it is, install the same package to all projects.
If that doesn't work, check your projects for added references that don't come from a nuget and remove those too.
In my case, I had to edit the .csproj and look for Newton references. I found out that Antlr3 had a HintPath to an old version. Even the package not existing.

NetStandard / Net Framework reference hell

I have a NetStandard 1.6 library that references an external library (System.Runtime.Loader, fetched from NuGet). If I reference my NetStandard library from a Net Framework 4.7 Windows-application I get a System.IO.FileNotFoundException when running the Net Framework application.
Full exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'
Now, I know full what the exception message means but I haven't got the foggiest on how to solve it in this situation.
Ideas?
I advise you to right click on the visual studio solution, go to manage nuget packages for the solution and check the versions of the various libraries you have. Any conflicts between the libraries will be present in the 'consolidate' tab. Alternatively, try removing the library reference from the project's reference folder and adding it back.

Add Reporting.WinForms Reference to VS2015

I'm looking at adding the reference;
Microsoft.Reporting.WinForms
to my VisualStudio (2015) project but when I go to Add the Reference in the Solution Explorer I couldn't find it.
Eventually I added it through NuGet but now I am getting the error message;
Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
which leads me to believe I just haven't added the package properly. I've installed Microsoft SQL Server Data Tools through program features but still no luck.
What am I missing?
You can try by executing this into Package Manager Console
Install-Package Microsoft.Reporting.WinForms.v11

Categories