WEPAPI development requiring Newtonsoft.Json.dll - c#

We are developing a new WEBAPI, which requires dll Package installation : “Microsoft.AspNet.WebApi ” version 6.0 for assembly reference. As a part of this Newtonsoft.Json.dll is referenced to the project.
Our Application already has “Microsoft.AspNet.WebApi ” version 4.5.
I even tried to use the older dll, but its not compatible with reset of the binaries in the WebAPI project.
If I override the older version with the newer version what could be the possible impact. I have used the old version in the Exception Handling wrapper classes.

I've lost a good bunch of brain cells fighting similar issue for Owin-based WebAPI project. "Solution" I use is dependencies redirection in app.config file. Here is file from my solution, you can correct it to your needs.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Related

Can't find System.IO.Compression assembly

When calling the System.IO.Compression.Zipfile.CreateFromDirectory, I am met with the following error :
However, my project does contain the first version of the assembly mentioned in the error (seen in the screenshot below).
After searching around, I saw that this error could arise from not having the System.IO.Compression.FileSystem assembly, which this project has :
I tried using / removing the System.IO.Compression.Zipfile assembly (which I found out is just a "link" to System.IO.Compression.FileSystem), changing System.IO.Compression versions, but nothing worked.
This project runs under the .NET Framework 4.6.1.
Does anyone have an idea of how to troubleshoot this one ? Thanks !
In my case I added the following to web.config runtime/assemblyBinding node:
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
You can manually add the following binding redirect in your application's config file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression.ZipFile" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Change this
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=true" />
</runtime>
To
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.Compression.ZipFile.UseBackslash=false" />
</runtime>

Could not load file or assembly System.Web.Mvc, Version=5.2.3.0

I have an MVC project. I can run in my local environment. When I deploy a web hosting on Godaddy, I get an error like this, Where do I have to look?
Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Even know Godaddy is hosting the site, I don't think they are the culprit of the error.
I would check the version of your reference with the version in the config. You currently have 5.2.3 but the actual reference could be 5.2.2 or something of the sorts. An example would be...
Under References I have EntityFramwork.dll Version 5.0, But the web.config shows that I am using EntityFramwork.dll Version 6.0. This dll will be in your bin folder as well.
I would also check the iis settings in Godaddy. If that still does not work check your framework and ensure that godaddy supports your version. You should see this in the iis settings.
I use godaddy hosting too. I have not had much issue with this. I do set up my PC as a server and do my publishing there. Then I copy over the published files. This seems to help deter main were the bug is. On my side or godaddys.
Sometimes people are quick to mark you down when they don't fully understand the issue. I would like for those to remain quite.

Visual Studio 2017 Unit Tests not discovered unless App.Config is deleted

This is the weirdest thing. I have a solution with multiple Class Library projects (all .Net Framework 4.7) and multiple unit test projects to test those class libraries. Once in a while I upgrade my NuGet packages to keep them up to date, and some of those upgrades introduces an app.config file to the test-project. Once that app.config is introduced, the tests are not longer discovered by Visual Studio, and therefor they are no longer ran after each build. Considering a failed test is a trigger to correct code, this created a scenario where we would introduce code that failed the unit tests, but because we relied so much on automation, we assumed it succeeded.
In summary:
- the existence of an app.config makes VS2017 not discover the tests in the project containing the app.config, even if the app.config is completely empty. Only deleting the config-file will make VS2017 rediscover the tests
- Everything in the solution is targeting .Net Framework 4.7
- All Nuget Packages are updated, including the MsTest Adapter and TestFramework
- The app.config files are filled only with assemblybinding entries, forinstance:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Found the perpetrator, thought I'd share in case anyone else runs into this. After adding the System.Runtime NuGet package to my test-projects, the tests got discovered by VS2017.

Could not load file or assembly 'System.Web.Http, Version=5.2.2.0

I added the Odata v4 package to my API, I noticed that it updated my Microsoft.AspNet.WebApi package to 5.2.3 version. But when i try to use
odata builder configuation in my WebApiConfig it showing error like
'Could not load file or assembly 'System.Web.Http, Version=5.2.2.0'.
config.MapODataServiceRoute("odata", null, GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
I searched this version(5.2.2) in my project but every thing is 5.2.3 and I updated all the packages too to solve this issue but failed.
Copy to Local property also true for System.Web.Http dll.
Any idea?
Visual studio solved this for me. The version conflicts are shown as warning and when I clicked it automatically added the binding redirect to my web config.
https://msdn.microsoft.com/en-us/library/2fc472t2.aspx
The binding redirect that solved my issue is,
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
Well this is not "real" solution but a workaround:
I have changed the machine.config and replaced <runtime /> with
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
so I works but if you have other web sites running...

SignalR 2.0.2 and Owin 2.0.0 dependency conflict

I'm trying to get SignalR working in an MVC5 project with individual accounts.
The MVC project has by default Owin 2.0.0 and all of the Owin.* components are also 2.0.0.
So I used NuGet to get all the SignalR packages, it automatically resolved dependancies and downloaded v 2.0.2.
The project throws an error on startup with the following message:
Could not load file or assembly 'Microsoft.Owin, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I also tried upgrading Owin to 2.1.0 but that didn't help either.
Has anyone faced the same problem and what was the solution?
You can update this references to the lastest version I found (now is 2.1.0):
Install-Package Microsoft.Owin -Version 2.1.0
Install-Package Microsoft.Owin.Security -Version 2.1.0
And make sure your Web.config have these binding redirects for version 2.1.0:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Or you can update this references to version 2.0.1:
Install-Package Microsoft.Owin -Version 2.0.1
Install-Package Microsoft.Owin.Security -Version 2.0.1
And make sure your Web.config have these binding redirects for version 2.0.1:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Perhaps you need a binding redirect in your .config
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
In my case when I hosted my WCF service that has SignalR functionality in IIS and when I go to my IIS manager and to my application where I hosted my service right click svc file and click Browse, I was getting this error. So I did the following
In my Visual Studio, Tools -> Library Package Manager -> Package Manager Console
I made sure I selected my Website project that hosted my WCF service and gave below two commands one after another
uninstall-package Microsoft.AspNet.SignalR
install-package Microsoft.AspNet.SignalR
After this I just re-build my solution. Went to IIS manager and to my application where I hosted my service right click svc file and click Browse, I was able to see my service running in IE.

Categories