Running Dotnet EF migrations add ... generates FileNotFoundException when run - asp.net

Error generated is as follows.
System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.
File name: 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
at Microsoft.DotNet.ProjectModel.ProjectReader.ReadProject(Stream stream, String projectName, String projectPath, ProjectReaderSettings settings)
at Microsoft.DotNet.ProjectModel.ProjectReader.GetProject(String projectPath, ProjectReaderSettings settings)
at Microsoft.EntityFrameworkCore.Tools.DispatchCommand.<>c__DisplayClass2_0.<Create>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.
This error occurs for any DOTNET EF command (even --help)
we have multiple machines that this does work on but 2 of the machines are seeing the above error, and it is very frustrating?
I have even tried to install just the ProjectModel component from Github with no success
Any help appreciated on how to get over this issue

I had this problem (along with other similar errors running other dotnet commands. For me it was due to having older RC1 and SDK installations. I removed everything from add/remove programs, along with removing the dotnet and DNX directories in c:\program files. Then I reinstalled and it started working.

I tried the suggested of uninstalling and deleting all of the DNX and DOTNET directories to no avail.
Then i did some more searching and found the answer. I had to change my Tools - entityframework configuration to the following
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net451+win8"
},
Then I had to clear the caches for the Entity Framework as per this article link
https://github.com/aspnet/EntityFramework/issues/5458#issuecomment-221912806
Then I needed to remove the Reference for Microsoft.EntityFrameworkCore.SqlServer from the project and let VS fix up the reference itself by reloading
After this a Build sorted out the issue and i could again run dotnet ef commands

Related

Adding "Uno.Cupertino" or "Uno.Material" to an Uno-Platform project make the project not compile. Even a blank project

After adding "Uno.Cupertino" or "Uno.Material" to any Uno-Platform project even a newly created blank project, the project no longer builds and throws tons of build errors.
Here are some of the common errors:
Error CS0433 The type 'SuspendingEventArgs' exists in both 'Microsoft.Windows.SDK.NET, Version=10.0.19041.24, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Uno, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null'
Error UXAML0001 Unable to find type Windows.UI.Xaml.ElementStub (net6.0-android)
I tried to solve the dependency errors by uninstalling or updating some of the packages to latest version but it makes no difference and it does not compile.

.net core application fails because of transient dependency

.net core application fails with the following message:
2021-05-06T11:48:20.114165977Z Unhandled exception. System.TypeInitializationException: The type initializer for 'Audit.Core.Configuration' threw an exception.
2021-05-06T11:48:20.114232677Z ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.
My code doesn't have any explicit dependencies on Newtonsoft.Json, by inspecting the project.assets.json file I can see the following picture:
App code depends on Microsoft.Extensions.Configuration.AzureKeyVault depends on Microsoft.Azure.KeyVault which depends on "Newtonsoft.Json": "9.0.1".
App code depends on Audit.EntityFramework.Core depends on "Newtonsoft.Json": "12.0.2"
App code depends on Audit.WebApi.Core depends on "Newtonsoft.Json": "12.0.2"
When I run dotnet publish command the Newtonsoft.Json version is always 9.0.0.0 in a published directory. My question is, how it would be possible to control the version of the Newtonsoft.Json so the higher version will be published during the build/publish.

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions in Sitecore 8.1 Project

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
I tried clean and rebuild the solution and deleted bin and obj still I got same error. I'm using sitecore 8.1.
Stacktrace:
[FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.]
Sitecore.DependencyInjection.<>c__14`1.<GetRequiredResetableService>b__14_0() +0
Sitecore.DependencyInjection.LazyResetable`1.get_Value() +148
Sitecore.Configuration.Factory.GetConfigNode(String xpath) +72
Sitecore.Resources.Media.UploadWatcher.InitializeIgnoreList() +156
Sitecore.Resources.Media.UploadWatcher..cctor() +85
[TypeInitializationException: The type initializer for 'Sitecore.Resources.Media.UploadWatcher' threw an exception.]
Sitecore.Resources.Media.UploadWatcher..ctor() +0
This could be caused by one of the following:
You added Sitecore.Kernel through Nuget package to your project, and you are referencing a later version (8.2) and its being deployed to the bin folder when you build and publish, You need to check you have the correct Sitecore.Kernel version in your nuget packages
You are overwriting the web.config from your project (which does not include Sitecore default configurations) and pushing it to the root folder, You need to make sure only the correct Sitecore web.config is in your root folder.
You are referencing a later version of "Microsoft.Extensions.DependencyInjection.Abstractions" package in your NuGet packages, Make sure you are referencing version number "1.0.0", as this is the version that sitecore is using.
Hope this helps

Dependency on the framework assembly "System.Runtime, Version=4.0.10.0," which could not be resolved in the currently targeted framework

TFS 2013 - Build: ASP.Net 4.5.1 website I get this error:
warning MSB3268: The primary reference "C:\Builds\2\MyProj\Web1_Main\bin\MyProj1.dll"
could not be resolved because it has an indirect dependency on the framework assembly
"System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which
could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5.1". To resolve this problem, either remove the reference
"C:\Builds\2\MyProj\Web1_Main\bin\MyProj1.dll" or retarget your application to a framework
version which contains "System.Runtime, Version=4.0.10.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a".
All projects and site was 4.0 initially using Unity 1.0.0.0. I upgraded it to 4.5.2. Also the MyProj1 in the error above is referencing Unity and I upgraded it to 3.5.1 as well.
Read this: https://unity.codeplex.com/workitem/12756
The build server already have the updated 4.5.2 pointed in the workaround.
So I downgraded to 4.5.1 but still getting the error.
Solution builds fine locally via Visual studio 2013.
The stand alone class libraries project build in TFS fine but when MyProj is added as a reference to my Website, that's when it fails.
Any ideas?
Do I need any web.config changes other than TragetFramework settign while upgrading?
I had to upgrade my Unity to 3.5 due to my project's dependency on some other project and this error came again. This time, finally got it fixed.
This one helped me: http://devsilos.blogspot.com/2014/10/msb3268-while-targeting-aspnet-web-site.html
Solution I copied all the files that build was complaining about from:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Facades
To
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2
Here's the explanation from the link above in case it goes down for any reason in future:
A deeper inspection revealed the following interesting fact:
aspnet_compiler for some reason does not take into account the .dll-s
that reside under the Facade directory of 4.5 assemblies (C:\Program
Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades). It looks
only under C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5
As a result the whole thing failed since both System.Threading.Tasks
and System.Runtime .dll-s were under the Facades directory and not
inside the v4.5.
Now the solutions:
Just simply copy the missing .dll-s from Facade to the v4.5
directory.
Set the TargetFrameworkMoniker to 4.5.1 in the .sln file. The exact
syntax is as follows: TargetFrameworkMoniker =
".NETFramework,Version%3Dv4.5.1".
What happens in this case is that the aspnet_compiler does not
recognize the exact version of the required framework and tries to
use the GAC wherever it can. If 4.5 is the highest version installed
on the build machine I believe it should work.
Actually sorry I don't think "assemblyBinding" would help.
It seems like a known bug. It has not been resolved. Using Unity 3.5 you can target .NET 4.5.1 but not 4.5.2.
So one option would be to re-target to .NET 4.5.1 and see if the problem goes away, if that's an option.
p.s.
Also you can try .NET Framework 4.5.2 Developer Pack. But some have mentioned it did not work.
We recently ran into a similar problem with a site that was upgraded to target .NET 4.5, and initially followed the solution in gbs's answer.
In our case, we had several warnings following this pattern:
<project name>.metaproj : warning MSB3268: The primary reference "<project reference>.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "<project reference>.dll" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
We then discovered that if you create a new web site targeting 4.5.x (File > New > Web Site...) and select the ASP.NET Empty Web Site template, the package Microsoft.Net.Compilers is included. Adding this package to our site resolved the issue without the need to touch the reference assemblies.
Of the original two solutions, copying the files caused the build to succeed but presented maintenance concerns, and changing the TargetFrameworkMoniker (to 4.5.3 rather than 4.5.1) produced a different build error and was a brittle solution.

"Could not load file or assembly" error when installing Google.api.customsearch.v1 client library

I am trying to install Google.api.customsearch.v1 client library from Nuget but I get this error when I try to run my asp.net website.
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
I have discovered stackoverflow for such issue, but non of them resolved my problem. any suggestion?
Ok, I fixed the problem by updating Newtonsoft.Json package. Run the following command in the Package Manager Console
Update-Package Newtonsoft.Json

Resources