Code First Migrations: Could not load file or assembly - c#

I'm having difficulty using Package Manager to run update-database. Specifically, I'm getting a System.IO.FileNotFoundException
Approximately, the structure of my solution is as follows:
Foo.Data
Foo.Presentation
Foo.Data has all my EF code in. Foo.Presentation is the presentation layer (in this instance, a MVC5 site)
With Foo.Presentation set as the startup project and Foo.Data set as the default project in Package Manager, whenever I try to run update-database I get:
"Could not load file or assembly 'Foo.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
If I set Foo.Data as the startup project and the default project I can run update-database (so long as I specify the connection string and provider).
This has been driving me nuts all morning - so if anyone has any ideas, you'll help me get this sorted and preserve what remains of my sanity!
A couple of notes:
I've recently branched the solution. The old branch is working fine
I've checked, double-checked and triple-checked that Foo.Presentation references Foo.Data. It does, and I can access it from Foo.Presentation

Just in case anyone stumbles across this same/similar problem - I was being an idiot.
The cause was a discrepancy in a couple of nuget package versions that were used in both Foo.Data and Foo.Presentation. I had inadvertently used a newer version of the package in Foo.Presentation.

Related

The type initializer for ‘LibGit2Sharp.Core.NativeMethods’ threw an exception

Specific Exception received: “Could not load file or assembly ‘System.Runtime.InteropServices.RuntimeInformation, Version=0.0.0.0, Culture=neutral’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference.”
I have two projects, one is a sort of “Proof of concept” and the exact same code works perfectly there, while the other is a large solution in which I’m adding code to one of the existing projects.
I am getting an exception in the second (failing) project when running the following line of code:
LibGit2Sharp.Repository.Clone(baseGitHubURL + ourOrg + “/“ + ourRepo.Name, ourRepoPath + #“\” + ourRepo.Name, co);
Ahead of this code, I’ve got it printing the arguments being passed, which are as follows in the output from BOTH projects (again - identical code in each):
GitHub path: https://github.company.com/TESTING/CA4F
Filesystem path: C:\Users\User\CA4F
The creation of CloneOptions is identical in both projects with static values being used (it uses a personal access token as a username).
I am suspecting there is something wrong with how LibGit2Sharp was added to the failing project. Note that the PROCESS was the same for both:
From NuGet console: “Install-Package LibGit2Sharp”
Both have the same version (latest, version 0.25.0).
Despite these facts, the working project has a “Dependencies” section under the project listing LibGit2Sharp, while the non functioning project does not have this section. LibGit2Sharp WAS added as a reference to my actual project when I went to Nuget Package Manager and told it to install to ALL projects in the solution.
Another piece of information - the working project does NOT have a NuGet package for “LibGit2Sharp.NativeBinaries”, while the failing project does. On a whim, I tried deleting it from the failing project, but Nuget says “Unable to uninstall ‘LibGit2Sharp.NativeBinaries.1.0.210’ because ‘LibGit2Sharp.0.25.0’ depends on it.”
Just to close this up - I was able to resolve this by adding the following to the first configuration property group under the PropertyGroup tag in the csproj of every single project in the solution:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
After doing that, a recompile and run allowed me to successfully call LibGit2Sharp! :)
Note that this was the solution provided by “bording” over on the LibGit2Sharp git issues “forum”.

VS 2015 suddenly complaining about Newtonsoft.Json version compatibility

I have a complex solution which suddenly -- and I mean suddenly, for days it was compiling just fine and the next moment it wasn't -- started complaining about Newtonsoft version compatibilities:
Severity Code Description Project File Line Suppression State
Error CS1705 Assembly 'UploadFramework' with identity
'UploadFramework, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' uses 'Newtonsoft.Json, Version=9.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher
version than referenced assembly 'Newtonsoft.Json' with identity
'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' UploadProcessor..NET Framework
4.6 C:\Programming\ConnellCampaigns\src\UploadProcessor\batch\EnvelopeSalutationJob.cs 341 Active
I am totally at a loss as to how to fix this...as so far as I can tell, nothing has changed in the code base.
However, I had just done a "reorganize usings" across the entire solution, which modified quite a few files. OTOH, as soon as I ran into this problem, I immediately reverted all the changes -- thank goodness for git! -- so I should be back to where I am.
But I'm not...
Any advice on how to fix this would be greatly appreciated.
Additional Info
I should've mentioned that the project.json file for UploadFramework has this line in it:
"Newtonsoft.Json": "6.0.8"
There's a blue squiggly line under the 6.0.8 which, when you hover the mouse over it, says that the project ended up with version 9.0.1. I don't understand how I can specifically define a particular version, and end up with a more recent one. Perhaps that's a clue as to what's going on.
You have two different versions of the Newtonsoft assembly references in your solution. You can use the "consolidate" option in the nuget package manager and you should be fine.
If it do not work after a revert: clean is the first thing to try, sometimes you also need to clean up the /packages folder - you might have multiple folder for Newtonsoft these. Simply delete the version you are not working. Then the solution should build again.

Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies

I have this exception generated on some user machines (~1 of 20):
Could not load file or assembly 'System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its
dependencies. The system cannot find the file specified.
I found several references to this error over the web and this site but nothing helped.
I have an add-in application which uses WCF to connect to the server. The add-in built with .NET Framework 3.5 with VS 2008.
The error is reproducible on one of the test machines in only one user account. I install my application and can only reproduce this from one account on this machine everywhere else it is working fine. Furthermore it is only reproducible with only one version of host application which I created add-in for (I assume because it uses differnet .NET Frameworks).
I have checked the fuse logs and I see the following:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files\SolidWorks Corp\SolidWorks\sldworks.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Home\User
LOG: DisplayName = System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/SolidWorks Corp/SolidWorks/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
So by some reasons it is trying to use v2.0.50727\mscorwks.dll loader to load the Version=4.0.0.0 of System.dll. On build machine I'm referring 2.0.0.0 version of System.dll.
I had this same problem - some users could pull from git and everything ran fine. Some would pull and get a very similar exception:
Could not load file or assembly '..., Version=..., Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.
In my particular case it was AjaxMin, so the actual error looked like this but the details don't matter:
Could not load file or assembly 'AjaxMin, Version=4.95.4924.12383, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.
It turned out to be a result of the following actions on a Solution:
NuGet Package Restore was turned on for the Solution.
A Project was added, and a Nuget package was installed into it (AjaxMin in this case).
The Project was moved to different folder in the Solution.
The Nuget package was updated to a newer version.
And slowly but surely this bug started showing up for some users.
The reason was the Solution-level packages/respositories.config kept the old Project reference, and now had a new, second entry for the moved Project. In other words it had this before the reorg:
<repository path="..\Old\packages.config" />
And this after the reorg:
<repository path="..\Old\packages.config" />
<repository path="..\New\packages.config" />
So the first line now refers to a Project that, while on disk, is no longer part of my Solution.
With Nuget Package Restore on, both packages.config files were being read, which each pointed to their own list of Nuget packages and package versions. Until a Nuget package was updated to a newer version however, there weren't any conflicts.
Once a Nuget package was updated, however, only active Projects had their repositories listings updated. NuGet Package Restore chose to download just one version of the library - the first one it encountered in repositories.config, which was the older one. The compiler and IDE proceeded as though it chose the newer one. The result was a run-time exception saying the DLL was missing.
The answer obviously is to delete any lines from this file that referenced Projects that aren't in your Solution.
I got this after downgrading a project from .net 4.5 to .net 3.5.
To resolve I had to go in to the project - properties - settings window and delete all my settings, save the project, exit and restart visual studio, go back into project - properties -settings window and re-enter all my settings and their default values
This worked for me.
Go to Project->Propertied->Target Frawork->Change frame work like 3.5 to 4.0
I had the problem under Linux and I needed to install those. I don't know which one actually fixed the problem, but that error was gone after that:
apt-get install mono-utils mono-runtime-sgen mono-runtime-common \
mono-runtime-boehm mono-runtime-dbg mono-xbuild
I've seen this a couple times, and it is usually fixed by running a repair on .NET Framework (whichever version the application is trying to use).
You are using .net 4? - Maybe on the clients there is only the ".net framework 4 client profile" installed. Try to install full package!!
Download here
In my case, I was able to find issue with ScriptManager by setting Debug=true in web.config file
I answered too late but it has worked in my case.If you are facing this issue in your project please add the following line in your web.config :
<compilation batch="false" >
This worked in my case. If you already have compilation tag in your web.config then add only batch="false" property to it.
You can enable NuGet packages and update you dlls. so that it work.
or you can update the package manually by going through the package manager in your vs if u know which version you require for your solution.
Even I have experience some more strange things, I can see there is no dll in GAC from where the dll is loading but windows > Module shows system.dll version=4.0.0.0 loaded
i just changed my target .net framework and it worked .in my case i changed from .net 4.7 to .net 4.
Right click your solution and select properties
selct properties
Click Application >> Target Framework
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
this is my problem. I installed system.configuration assembly in the project and other class libraries also. now the problem has gone.
am used net 6.0 with aspcore.report and problem like this happened with me
I installed system.configuration assembly in the server project problem solved

Migrator.NET MSBuild - Could not load file or assembly 'Migrator.Framework'

I've installed Migrator.NET using NuGet but when I attempt to run a migration using MSBuild I get the following error. I see that its having trouble accessing the Migrator.Framework assembly but I am unsure as to why or where specifically I need to put the DLL in order to get it to run.
C:\Users\Cody\src\App\App.Migrations\App.Migrations.csproj(64,5): error MSB4062: The "Migrator.MSBuild.Migrate" task could not be loaded from the assembly C:\Users\Cody\src\App\App.Migrations..\packages\MigratorDotNet.0.9.0.33276\tools\Migrator.MSBuild.dll.
Could not load file or assembly 'Migrator.Framework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=3b3586e9632ecfce' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Does anyone have any insight? I've spent far too long fiddling with this.
It turns out the issue was in fact that it was looking for version 0.0.0.0. I downloaded the project and recompiled the Migrator.Framework binary as version 0.0.0.0 as a quick fix. The real solution is recompiling Migrator.MSBuild.dll to look for the proper version of Migrator.Framework.
I'll see if this was a one-off error or if I can reproduce it, and submit it as a bug to the Migrator.NET team if it is in fact a bug with the NuGet package.

NSevriceBus Assembly Version Error

I have an issue when trying to load the NServiceBus assembly from a client machine. The software runs correctly from my development box but once rolled out I get the following error:
Could not load file or assembly 'NServiceBus, Version=2.0.0.1100, Culture=neutral, PublicKeyToken=9fc386479f8a226c' or one of its dependencies. The system cannot find the file specified.
The weird thing is I am not using version 2.0.0.1100, I am using the latest version 2.0.0.1219. It seems to be referencing the old version somewhere but I cannot find where. I have set the “Specific Version” flag to true on both the NServiceBus & NServiceBus.Core assemblies and have tried to explicitly set the version number in the app config, both with no luck. I don’t understand why it works fine locally but errors once rolled out. The project causing the error is a shared class library and it only appears to be erroring on some projects too.

Categories