System.Web.Http.GlobalConfiguration does not contain a definition for 'Configure - asp.net-web-api

In global asax cs file i have this line:
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
which causes this error.
I have tried as suggested on other forums:
Open the Package Manager Console for the project with the error.
Type in Install-Package Microsoft.AspNet.WebApi.WebHost and hit Enter
Rebuild your project and all should be right with the world (or at least right with your project)
The output was:
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.2.2)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Microsoft.AspNet.WebApi.WebHost 5.2.2' already installed.
SM.EORD.Web already has a reference to 'Microsoft.AspNet.WebApi.WebHost 5.2.2'.
and error is still there. What could be wrong?
br, Simon

After hours of investigating i have found out that after I have installed ASP.NET Web API 2.2, the reference path of all dlls was from some old Web API - it didn't take the new ones.
The new dlls has been installed in packages folder, while the old one were in bin folder inside project.

if you want to update your references as well next time try upgrading from the package manager console you can update all or just specify the package name. Update package will upgrade vs installing a new package and you have manually go update your references.
Update-Package

In my case, the problem was that I renamed the Namespace of my project, and I did not know I needed to manually edit the namespaces section of the Views\Web.Config to match my new namespace.

Related

Unable to find package Telerik.UI.for.Xamarin with version(>=2022.1222.1)

We have a Xamarin project, and we need to start debugging on MAC. We use the MacInCloud Service.
After cloning the project from source control, I encounter the following error -> Unable to find package Telerik.UI.for.Xamarin with version(>=2022.1222.1). It appears as soon as the project is cloned and with the the 'Could not restore packages'.
What options do I have to resolve this issue?
I have tried removing the the package from the Packages directory and removed the reference in the csproj aswell.
I can't do a manual install of telerik as we do not have admin rights on MacInCloud.
The log file >This is the entire log file - Getting restore information for project /Users/user219905/Documents/GitHub/gts-mobile/GtsApp/GtsApp/GtsApp.csproj
Getting restore information for project /Users/user219905/Documents/GitHub/gts-mobile/GtsApp/GtsApp.iOS/GtsApp.iOS.csproj
Getting restore information for project /Users/user219905/Documents/GitHub/gts-mobile/GtsApp/GtsApp.Android/GtsApp.Android.csproj
Running restore with 4 concurrent jobs.
Reading project file /Users/user219905/Documents/GitHub/gts-mobile/GtsApp/GtsApp/GtsApp.csproj.
Restoring packages for /Users/user219905/Documents/GitHub/gts-mobile/GtsApp/GtsApp/GtsApp.csproj...
Restoring packages for .NETStandard,Version=v2.0...
GET https://api.nuget.org/v3-flatcontainer/telerik.ui.for.xamarin/index.json
GET https://nuget.devexpress.com/xRMAAuTIJGNTlKc1O83zlgVKkkr2ibgsDfUBelIIfu3Oq2Ku77/api/FindPackagesById()?id='Telerik.UI.for.Xamarin'&semVerLevel=2.0.0
GET https://api.nuget.org/v3-flatcontainer/telerik.ui.for.xamarin.datagrid/index.json
GET https://nuget.devexpress.com/xRMAAuTIJGNTlKc1O83zlgVKkkr2ibgsDfUBelIIfu3Oq2Ku77/api/FindPackagesById()?id='Telerik.UI.for.Xamarin.DataGrid'&semVerLevel=2.0.0
NotFound https://api.nuget.org/v3-flatcontainer/telerik.ui.for.xamarin.datagrid/index.json 172ms
OK https://api.nuget.org/v3-flatcontainer/telerik.ui.for.xamarin/index.json 173ms
OK https://nuget.devexpress.com/xRMAAuTIJGNTlKc1O83zlgVKkkr2ibgsDfUBelIIfu3Oq2Ku77/api/FindPackagesById()?id='Telerik.UI.for.Xamarin.DataGrid'&semVerLevel=2.0.0 367ms
OK https://nuget.devexpress.com/xRMAAuTIJGNTlKc1O83zlgVKkkr2ibgsDfUBelIIfu3Oq2Ku77/api/FindPackagesById()?id='Telerik.UI.for.Xamarin'&semVerLevel=2.0.0 502ms
Resolving conflicts for .NETStandard,Version=v2.0...
Unable to find package Telerik.UI.for.Xamarin with version (>= 2022.1.222.1)
Found 1 version(s) in nuget.org [ Nearest version: 2015.3.1202 ]
Found 0 version(s) in DevExpress
Unable to find package Telerik.UI.for.Xamarin.DataGrid. No packages exist with this id in source(s): DevExpress, nuget.org
Package 'Microsoft.Bcl 1.1.10' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package 'Microsoft.Net.Http 2.2.29' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package restore failed. Rolling back package changes for 'GtsApp'.

Project Reference & Nuget Package Reference Conflict - Key with same name already exists

Using Visual Studio 2019 Version 16.6.0 Preview 2.1 - I have a solution with two projects:
Project A - Has a nuget package dependency Package1
Project B - Has a project reference to Project A
I now also require that Project B include the same nuget package dependency Package 1
When i attempt to install the package I get an error "An item with the same key has already been added".
I have seen a few posts that discuss this, but no definitive solution. For debugging purposes I want to keep Project A as a project reference for Project B. Any idea how I can solve for this?
Project Reference & Nuget Package Reference Conflict - Key with same
name already exists
First, try to remove the Project Reference of Project A in Porject B,then Install Package in Project B and then add the Project Reference of Project A in Project B.Check if it works.
If not, I think there are some different conflicting versions of a nuget package in your Project. See this similar issue. You should remove the duplicate packages. Try these:
1) if you use Packages.config, you should check whether there are two duplicate packages like these:
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
Delete the old one and remain the latest one. At the same time, check your xxx.csproj file and delete the duplicate nodes.
2) delete bin,obj folder of Project A and Project B
3) clean local nuget caches and delete the packages folder under your solution(xxxx\Projects\MyProjName\packages).
After that, run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console.
Do both on Project A and Project B.
4) and then to install Package 1 on Project B to test whether the issue persists.

How to disable "transitive package management" for a Visual Studio project

How do I disable "transitive package management"?
I wish to do so, so that I can install a package that I "packed" locally and have in a .nupkg file. When I attempt to do so, I get a messaging stating that The 'Source' parameter is not respected for the transitive package management based project(s) {csproj file}. The enabled sources in your NuGet configuration will be used.
Complete Context
When developing a NuGet package that's not ready for distribution via our NuGet feed, I often create a local .nupkg file like this from the package manager console:
nuget pack {path-to-csproj-file}
This generates a {project-name}.nupkg file, which I can then install in another project by opening it in Visual Studio, navigating to the package manager console, and entering the command
Install-Package {path-to-nupkg-file}
This has worked great and once the NuGet package is ready for distribution, we push it up to Azure DevOps and let the build pipeline there push it into our feed.
However, I just recently inherited a project where the prior developer apparently setup "transitive package management" that prevents this workflow. Here's what I get when I try to install directly from a .nupkg file:
Install-Package C:\Users\Josh\source\repos\SpeakerDiscountManager\SpeakerDiscountData.1.0.5.nupkg
The 'Source' parameter is not respected for the transitive package management based project(s) MembershipApplicationWidget\MembershipApplicationWidget.csproj. The enabled sources in your NuGet configuration will be used.
<snipped several lines of unsuccessfully searching configured package sources>
Install-Package : NU1102: Unable to find package SpeakerDiscountData with version (>= 1.0.5)
Obviously, it doesn't find the package I've specified via file, because it is searching online feeds and it doesn't exist in any of our online package sources--the package is in a testing state, not ready for anyone to use but me.
Based on the error message, I need to turn off "transitive package management" so that I can specify a file source for the package, but I've been unable to turn up any information online about how this is configured.
I did try installing this exact same .nupkg file in another project, using the same Install-Package {path-to-nupkg-file} procedure. This works.
How to disable “transitive package management” for a Visual Studio
project
I think this problem transitive package management is related to your current project structure which has some intricate dependencies, custom rules and so on. Therefore, turning off transitive package management is unpractical. If you create other projects and then install this package by your way, I think it probably will not occur.
As a best workaround, as you said(hint from the message The enabled sources in your NuGet configuration will be used.), add the the local nuget package's path into Nuget Package Source.
In your side, I think you specify -Source xxxxx(the path of the nuget package) to install this package in the package manager console, if so, this function actually is inconvenient.
You can just add the folder path which SpeakerDiscountData.1.0.5.nupkg exists into global nuget package source. Once you have done it, it will applies to any projects in this machine.
It has two ways:
1) VS IDE UI
Tools-->Options-->NuGet Package Manager-->Packages Sources-->add a new key and input the path of the nuget folder. Also, check its option.
2) global NuGet.Config file
(C:\Users\xxxx\AppData\Roaming\NuGet\Nuget.Config and step 1 is just add the path into this file by VS UI Control)
add these:
<packageSources>
<add key="Local Packages Source" value="C:\Users\Josh\source\repos\SpeakerDiscountManager\" />
..........
</packageSources>
After that, you can use your command to install this nuget package.
Note: If the root directory of your solution also has a file named nuget.config, the parameters in it will override the global file. It has the highest priority.
Just go to Vs IDE Tools/Nuget Package Manager/Package Manager Setting And Check The address of Package Sources.
it's something like "C:\Program Files (x86)\Microsoft SDKs\NuGetPackages".
Then Copy your package file into that folder and at last run this command in Package Manager Console:
install-package packagename

Cannot restore nuget packages on VSTS (Packages failed to install)

I'm using Visual Studio Team Services to build a .NET solution. I have a Nuget Installer task to restore the packages of the solution that is configured as follows:
Nuget.config file has 2 package sources - one is nuget.org (v2) and the other is a custom feed (Nuget Server v2.5.40416.9020). All packages from the nuget.org feed are restored but the ones from the custom feed are not, for each package from the custom feed there is an error message like this:
Unable to find version 'abc' of package 'xyz'
Error:
[error]Error:
C:\a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.22\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe
failed with return code: 1 [error]Packages failed to install
This was working fine 1 or 2 days ago.
Locally everything seems to work fine. Also, I tried with the nuget version 3.5.0 and a custom version of nuget.exe, without success.
Any suggestions?
I just had this error today. I fixed this error by reviewing the changes in my solution file with our base code branch and found some old lines that weren't supposed to be there. I think they were a result of a bad merge and should have been removed during a conflict resolve.
To fix the issue I simply removed the references that were old and everything built just fine.
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{EAECFF2D-7339-4180-8E1E-6DF9EC9EB131}"
EndProject
{3C14F190-6B6A-4913-9681-AFD9B62850FA} = {EAECFF2D-7339-4180-8E1E-6DF9EC9EB131}
{687ECE00-A567-40F3-BFF9-C3B639328F27} = {EAECFF2D-7339-4180-8E1E-6DF9EC9EB131}
Thanks,
Fissh

After deploying to AppHarbor I get The type or namespace name 'WebActivator' could not be found

I'm uploading my first application to AppHarbor and I'm getting the following error:
"The type or namespace name 'WebActivator' could not be found (are you missing a using directive or an assembly reference?)"
The solution is building correctly on the dev environment and on other build servers using MSBuild.
I couldn't find any help on the AppHarbour support page, any idea what could be happening?
Thanks
You can use the command into your nuget:
Install-Package WebActivator -version 1.5.3
EDIT
Here's a link to the nuget page.
Install-Package WebActivatorEx
I had a same problem in below code:
[assembly: WebActivator.PreApplicationStartMethod(
typeof(myApp.Web.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
And I found that in new versions of WebActivator its namespace is changed to WebActivatorEx; So below code solve my problem:
[assembly: WebActivatorEx.PreApplicationStartMethod(
typeof(myApp.Web.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
Looks like WebActivator DLL is not copied to bin folder. Make sure in VS you have Copy Local set to true and that your deployment script includes this file.
You might want to clean your local solution / deployment folder by deleting all instances of WebActivator to try to replicate the problem.

Resources