I'm using webapi service into Mvc I had created a reference of Api to mvc but after writing the code I'm getting this error
The type 'System.Web.Http.ApiController' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I also installed this package
Install-Package Microsoft.AspNet.WebApi.Core -version 5.2.3
Assembly System.Web.Http is in package Microsoft.AspNet.WebApi.Core.
You have to save all files and then run update-package -reinstall System.Web.Http. Script runed after installing will add refernce to this assembly to you project (it will be saved in .csproj). And then save all files again (needed to save project file).
Reference in .csproj file:
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
E.g. in empty project after Install-Package Microsoft.AspNet.WebApi.Core you will have modification in packages.config and in .csproj files.
If you will close project right after performing install command and choose no to save changes, then you will see this error again.
Related
I inherited some old legacy code which I'm trying to build, but I'm missing some specific dlls. In particular, I need version 4.0.0.0 of System.ComponentModel.Composition, but the Nuget Package Manager options only go down to 4.5.0. Why is this, and how can I get the version I need?
Here is the line specified by the Web.config file I inherited.
<add assembly="System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
__
Edit: I tried Jingmiao Xu-MSFT's solution but I'm getting an error saying I'm already referencing these packages. Then I noticed that I'd commented out these assembly lines in my Web.config, so where are these packages being referenced from?
According to your description, you can refer to the following steps to find the dlls you need:
Right-click on the References under your project in Solution Explorer.
Choose Assemblies and search System.ComponentModel.Composition, System.Net.Http.WebRequest
Check them and add them to the project.
When i build locally it works, but my VSTS hosted 2017 instance build fails with the following message:
[error]apps\Ascend.Identity\AccountController.cs(126,17): Error CS0012: The type 'HttpRequestMessage' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Locally, there is also a yellow triangle in the reference list.
but it still builds
and the reference is there in csproj
and the package is restored from nuget (packages.config)
<package id="System.Net.Http" version="4.3.3" targetFramework="net472" />
In your local, try the steps below:
Delete packages folder in your source directory.
Remove System.Net.Http reference.
Right click References, select Manage Nuget Packages, browser and install package System.Net.Http.
Build your project and check the result. Make sure there is no yellow triangle in the reference list.
Check in the changes and queue a build.
I have cloned the repo for Json.Net on GitHub [https://github.com/JamesNK/Newtonsoft.Json] and built a local copy of the dll. I have been using this dll for a while now in a couple projects (console app and WebForms 4.0 site). But now I have started a new Web API 2.2 project which automatically brings in references to Json.Net for use in Microsoft.AspNet.Web.Optimization and WebGrease which both get installed by default in a new Web Api project.
I'm hoping to be able to take advantage of the optimizations provided by those dlls, but I need to reference my local version of the Newtonsoft.Json dll. NuGet wont let me remove the Json.Net package b/c of the dependency from WebGrease, and if I manually remove the reference from the project and add a reference to my local version of Json.Net, I get the following error:
Could not load file or assembly 'Newtonsoft.Json, Version=6.0.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 am not sure how to get the references to line up so that I can use my local copy of the dll instead of the NuGet version that is expected by WebGrease.
This is in my .csproj file:
<Reference Include="Newtonsoft.Json, Version=6.0.3.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\External\GitHub\Json.NET\Src\Newtonsoft.Json\bin\Debug\Net40\Newtonsoft.Json.dll</HintPath>
</Reference>
That local reference has Copy Local = True in the reference properties.
And this is in my web.config:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.3.0" newVersion="6.0.3.0"/>
</dependentAssembly>
How do I get this reference resolved?
I am in the process of moving my development environment to a new machine. I decided to install VS2013 Pro on my new machine (VS2010 Pro on the old machine). I copied the entire Visual Studio 2010 folder over to the Projects folder on the new machine. I opened my solution in VS2013 and everything migrated without error. I rebuilt the solution and got the following warnings. I have compared my projects side by side on old and new machine and can't find any differences. The only difference I have been able to find is that the old machine has folders for only .NET 4.0 and the new machine has .NET 4.0, 4.5 and 4.5.1.
Warnings:
(0,0): warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Email, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. The dependencies are: Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly.
(0,0): warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: SharedLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. The dependencies are: Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly.
(0,0): warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: VendorsLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. The dependencies are: Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly.
I think I figured it out based on this post. Adding a line in the compilation section of web.config for Microsoft.VisualBasic prevents the build warnings.
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" batch="false">
<assemblies>
.
.
.
<add assembly="Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
I am Migrating from my project which runs on VS2003 with MSOffice 2003 to VS2010 project.
My project makes use of assembly 'Microsoft.Office.Interop.Excel.dll'
But I get the following Error.
2>ResolveAssemblyReferences:
2> No way to resolve conflict between "Office, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "Office, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null". Choosing "Office, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
2>InitializeBuildStatus:
2> Touching "Debug\ACCT.unsuccessfulbuild".
2>CustomBuild:
2> All outputs are up-to-date.
2>cl : Command line warning D9035: option 'clr:oldsyntax' has been deprecated and will be removed in a future release
2> stdafx.cpp
2>stdafx.cpp : fatal error C1107: could not find assembly 'Microsoft.Office.Interop.Excel.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable
2>
2>Build FAILED.
I made sure that the assembly 'Microsoft.Office.Interop.Excel.dll' has been referenced.
You have to remove the old reference, and re-add the 2010 one. They are actually different. It's a bit of pain when upgrading office components.