Ninject assembly does not match referenced assembly - asp.net

Setup:
ASP.NET MVC3
Ninject v2.2.1.4
Ninject v3.0.0.15
Ninject.MVC3 v3.0.0.6
Ninject.Web.Common v3.0.0.7
Using NuGet, my UnitTest project references Ninject v2.2.1.4
My Web Project references Ninject v3.0.0.15, Ninject.MVC3 and Ninject.Web.Common
Problem:
With win explorer open at the bin folder of my web project, I build my solution and I can see Ninject v2.2.1.4 copied into the bin directory of my web project. And then being replaced by Ninject v3.0.0.15.
When i hit F5 to debug, Ninject.dll v3.0.0.15 gets replaced with Ninject v2.2.1.4 causing the following error :
Could not load file or assembly 'Ninject, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
What gives?

Some thoughts:
Only in your debug build did you have an indirect reference to the
v2 Ninject version. Case in point, I'm guessing when you are doing
your debug build you build your Test project while a release build
does not build your Test project.
When you were building, did you happen to notice what project was being built when the v2 DLL was placed in the bin? Then you'll be
able to figure out what project is referencing the v2 build and be
able to narrow down your search (i.e. the answer would become quite a bit more obvious if it wasn't the Test project).
Never a good idea to reference multiple versions in different projects.
Did you check out what your Web.config and App.config references were pointing to?

Related

Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data'

First of all some context: my project exists out of a common project that contains all the DAL stuff and a web project. Now the common project is written in .NET framework 4.5 while the web project is written in .NET Core 2.0.
When trying to acces the repositories of the DAL project I get following error:
Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Now I'm not sure what to do now. I have added the System.Data.Common nuGet package to my web project, but without succes. How can I slove this problem preferably without altering the common DAL project? Thanks in advance.

System.TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.Formatting.JsonContractResolver'

I'm getting a very annoying error about System.Net.Http.Formatting.JsonContractResolver having inheritance security rules violated in a project which uses PCLs.
Here is the setup and how I tracked down the problem.
Project 1 - Custom.WebApi (portable, targeting .net 4.5, Core 5.0, Win8, Xamarin.Android, Xamarin.iOS, Xamarin.iOS(Classic))
This project is an abstraction over HttpClient to unify the return types of Get, Post, Delete, ... and depends ONLY on Newtonsoft.Json and .NET with this profile.
We are using Newtsonsoft.Json pcl version 6.0.8.($packagesFolder\Newtonsoft.Json.6.0.8\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll)
Project 2 - Custom.WepApi.Tests (unit test project)
This is a test project for the WebApi project. It references full version of 6.0.8 ($packagesFolder\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll)
This project is able to run tests against WebApi project no problem.
Project 3 - MyWebsite (ASP.NET WebApi site)
This project is a WebApi project where the response types are unified and found in the Custom.WebApi project. This references a bunch of 3rd party stuff, but also Newtonsoft.Json v 6.0.8 full ($packagesFolder\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll)
Project 4 - MyWebsite.Tests
To test the web project, I have a test project that calls endpoints using Custom.WebApi implementation. This project also references newtonsoft.json version 6.0.8. However, this references is purely to fix errors observed when running. Nothing in this project depends on Newtonsoft.Json, but if I do not explicitly add a reference to it, it will fail with TypeLoadException. Adding the reference seems to make that go away.
When I run the Project 4 tests, they all fail, indicating that the website is having TypeLoadException on Startup. After a TON of investigation, I noticed that when the MyWebsite project builds, the Newtonsoft.Json.dll in the bin folder is overwritten with the portable version and fails.
If I change the test project to reference the same portable newtonsoft.json.dll, the test project fails with the same error. Using the full version, no error is observed.
If I manually replace the dll in the bin folder of MyWebsite, it is overwritten again upon build. I have made sure the references are correct in MyWebsite .csproj file, including the hint path.
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
So, either I need to resolve why it believes there is an inheritance security rule violation (looking at the source code did not reveal anything obvious about access modifiers not matching), or it needs to stop overwriting the Newtonsoft.Json.dll in the MyWebsite bin folder.
To further complicate things, this replacement only occurs SOMETIMES. If I Start Without Debugging, it seems to not happen all the time and executing the Unit Tests succeeds against the deployment when the dll is not replaced with portable version.
You can resolve this by setting "Copy Local" to false on the Newtonsoft.Json reference in your PCL projects. I'll show you tomorrow.

mismatch assembly definition error after dll renaming on IIS server

I made some enhancements to the web site in Visual Studio 2012 and rebuilt the project. Up on the IIS server, I renamed the original dll to fooOLD.dll and copied up the newer version, foo.dll.
But now when I try to run the main page, there's an error:
Could not load file or assembly 'fooOLD' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I have tried stopping and starting the IIS server, to no avail.
Apparently, IIS noticed my renaming of the file and has "remembered" it somewhere. How do I tell IIS that I'm trying to replace the old dll with a newer version?
You need to remove the old DLL from the bin directory.
If you don't, you have two assemblies in that directory with the same AssemblyName:
The runtime does not consider the file name when determining an assembly's identity. The assembly identity, which consists of the assembly name, version, culture, and strong name, must be clear to the runtime.
Now apparently the wrong one is loaded first, causing the error to be thrown, because the loading assembly (your site) is compiled against a newer version of the referenced assembly.
Do iisreset
Go to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files or
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
Note: Select path based on framework version you are using.
Delete folder named after your application.
IIS will use newly copied file.

msdeploy: deploy reference of reference

is there a way for msdeploy to figure out reference of reference?
for example, i have project B that references project A that references TFS assemblies.
On my dev machine, TFS assemblies are GACed with Visual Studio installation, but my server doesn't have VS installed so it isn't GACed.
msdeploy doesn't seem to understand that it has to copy both assembly A and TFS assemblies that assembly A references.
I believe it is by design that VS ignores 'CopyLocal' if the assembly is GACed and i know that i can work around it by adding the assembly directly into the project but i am looking for more automatic way.
You should use the TFS API Nuget package to reference these assemblies instead of the GAC.
Microsoft.TeamFoundationServer.ExtendedClient

How to install ASP.NET MVC 5 on a server?

I just updated my website from MVC 4 to MVC 5.
Now when I want to run it on my web server instead of my development machine it does not work.
It think it is because I need to install the MVC 5 libraries on the server but I can't find them.
I downloaded WebMatrix 3 hoping it would provide a way to install it but it only gives me the ability to install MVC 4.
What should I install to be able to run a ASP.NET MVC 5 application?
(without installing Visual Studio 2013)
EDIT:
I disabled custom errors and eror what I have:
Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
EDIT 2:
I found out that the problem was due to one of my dependencies which was using the version 2.0.0.0 of razor.
When you deploy your app just make sure that all the assemblies are being deployed to your production environment in the bin folder. ASP.NET MVC is an xCopy deployment, so you don't have to install anything.
You might want to check that your Production environment has ASP.NET 4.0 and 4.5 registered.
MVC5 and future version of MVC doesn't require to installed on Windows Server. MVC5 app have everything as packages. You didn't need anything to install it.
What is required on server is copy of every library and assembly that you have used in your app. For fix this, Just make sure that everything on your bin folder is called same on server instead of server is looking for it's own GAC for assembly used in your app.
If you didn't found all the packages then you can install nuget packages on server by cmd.
The best is to do a Publish, right click on your project in Solution Explorer and select 'Publish'. Basically it will compile your solution and dump all the assemblies/artifacts to either your webserver, ftp or a local folder.
Make sure all your assembly references are being copied to the deployment directory. To do this you can change the <Reference...> tag in your .project file. Optionally, you can use visual studio's property setter to set the "Copy Local" property of each dll reference to "True".

Resources