Error installing Swashbuckle Nuget package on asp.net 5 - asp.net

I am trying to install SwashBuckle to an ASP.NET 5 Web API application.
The problem comes during installation where I get the following error:
This is due to the fact that the package is only partly compatible with DNX Core 5, specifically WebActivatorEx which is installed under DNX 4.5.1 and as such the SwashBuckle dll can't get at it as that is installed under DNX Core 5.
Following this answer, I moved both dlls under DNX 4.5.1 as suggested:
This has meant that the solution now builds, however I don't see any of the config add to StartUp.cs to enable and register Swagger. I have been trying to piece this together from examples for ASP.NET 4.5.1 but to no avail.
All I am currently seeing when I browse to http://MyApi/Swagger is a blank screen.
Can anybody let me know how I can register swagger with my API correctly?

Just Add
Blockquote
"Swashbuckle": "6.0.0-beta9"
Blockquote
To your Dependencies in the project.json file. Save the Project.json file and let the NPM Restore do its thing. Not sure why the other lower Stable builds don't work but this one does.

Related

ASP.NET Core publish produces lots of DLLs in the published folder, why?

I created a simple Web API project in Visual Studio 2015 using the .NET Core Framework. When I publish this project using the default settings, it creates the following:
In total there are 155 DLLs, 77 in the PublishOutput root and 78 in the refs folder.
Why put all the DLLs in the publish folder? Couldn't it just
reference the DLLs where they were installed from a single shared
location ?
Dotnet core tend to be very minimal as opposed to the previous versions of .net framework.
In dotnet core, the main purpose was making the core framework as small as possible and if you need more stuff, bring it in through NuGet packages.
So, many dependencies that used to be available in the framework are now moved to the NuGet packages and as you know there is a chain of dependencies in NuGet packages, so we will end up with so many libraries in our publish output, which is fine.
Another point being, most of the time, we're using project templates with too many dependencies that might not be needed whatsoever. So we can either start with a very minimal template and add needed stuff in it, or remove useless stuff from a more chuncky template.
I had a similar issue. When my local computer was upgraded from Net Core 2.0 to 2.1, my Core We Application which references a NetStandard application started publishing all DLL's in all referenced projects. I migrated my Core 2.0 application to 2.1 to match the highest version of SDK installed on my local and I could see my issue is now resolved. Publishing from the migrated(upgraded) application produced only the required DLL's. Hope this helps.

How to create a .NET Core library I can reference from a .NET Core App (Web API)

I'm working in Visual Studio 2015 Update 3 and .NET Core 1.0. I have a Web API project which is of type .NETCoreApp v1.0. When I add a .NET Core class library, it is of type .NETStandard v1.6. I can add this library to the Web API project as a reference, but it is not recognised when I try to add using statements.
If I create another project of type .NETCoreApp, I can reference it and use the classes without a problem.
How do I make use of a .NET Core class library from my .NET Core App?
Edit/Update:
This appears only to be an editor/Intellisense issue, because despite the editor warnings, the .NETCoreApp does build and run, calling into the class library.
I am running Resharper, which I see is blamed for similar problems with other types of projects: I have checked that I have the latest version and have cleared the Resharper cache and restarted VS2105.
This is a Resharper issue. At this time Resharper (v2016.1.2) does not support .NET Core 1.0.
There are 2 possible solutions:
Uninstall Resharper, and the Visual Studio native intellisense works.
Install the Resharper 2016.2 EAP (Early Access Program) version. I've done this and it's working. Obviously it comes with the caveats of any EAP/beta product.
Here is a link to the Jetbrains forum post where I was told .NET Core 1 was not yet supported and pointed to the EAP version.
Once you've built a library that targets netstandard1.X, you can either:
Produce a NuGet package with dotnet pack and host it locally or on NuGet. Then, install it in your netcoreapp project as any other dependency.
If your library and application are part of the same solution, make a local reference:
project.json
"dependencies":{
"MyLibrary.Core": {
"version": "1.0.0",
"target": "project"
}
}
target: project tells dotnet to look in the current solution for the dependency, instead of using your NuGet feeds. Again, this only works if you are developing the library and application in the same solution.

How to get ASP.NET MVC Music Store up and running with Visual Studio 2013/2015?

I want to get MVC Music Store tutorial application up and running with Visual Studio 2013/2015. Here are the steps that I've taken:
downloaded the latest version from Downloads page
unpacked it
opened it with Visual Studio 2013/2015 - got a migration report without errors but with some warnings
tried to build the solution, but it won't build - got a plenty of errors about missing type/namespace like that:
The type or namespace name could not be found (are you missing a using
directive or an assembly reference?)
How do I build and run locally the MVC Music Store project with Visual Studio 2013/2015?
There are two ways:
1) Download and install ASP.NET MVC 3 Tools from the official ASP.NET MVC 3 page or from Microsoft Download Center. It will install the required DLLS into the GAC.
2) Install the corresponding ASP.NET MVC 3 NuGet package into MvcMusicStore project using following command in the Package Manager Console:
Install-Package Microsoft.AspNet.Mvc -Version 3.0.50813.1
or
Install-Package Microsoft.AspNet.Mvc -Version 3.0.20105.1
After using either of the described ways you will be able to successfully build and run the MVC Music Store tutorial application.
Note that these ways are not conflicting with each other, so you may safely install ASP.NET MVC 3 Tools into your OS and install ASP.NET MVC 3 NuGet package into the project.
Install-Package Microsoft.AspNet.Mvc -Version 3.0.20105.1
Worked for me instead of Version 3.0.50813.1
I was running into the same problem as other mentioned here, tried installing the nuget package and was still getting an error.
My solution after following other advice here by installing the nuget package, the key to my solution was to make sure the project targeted "Microsoft Framework 4.0". I.E. Right mouse on the project node in the solution explorer, select properties, and within the "Application" page for the project select ".Net Framework 4.0".
All is working fine for me after this, seems VS was defaulting to 4.5.1.
HTH.
dan d:)

Attempt by method 'HttpConfiguration..ctor(HttpRouteCollection)' to access method 'HttpConfiguration.DefaultFormatters()' failed

I have a Web API that has version 5.1.2 of the Microsoft.AspNet.WebApi.Client package installed.
I am trying to access the API from an ASP.NET MVC application, which also has the same version of the package installed.
However, in the Global.asax of the Web API project, on the line below, I get the following exception:
WebApiConfig.Register(GlobalConfiguration.Configuration);
Attempt by method 'System.Web.Http.HttpConfiguration..ctor(System.Web.Http.HttpRouteCollection)' to access method 'System.Web.Http.HttpConfiguration.DefaultFormatters()' failed.
I found that this error occurs when you have multiple projects pointing to different .net versions.
For example if you have a Web API project targeting .net 4.5 and a unit test project targeting .net 4.5.3 it seems that default settings mean nuget may silently update the .net 4.5 project references to incompatible versions one day when you open visual studio and cause your Web API project to fail with the recondite 'Attempt by method 'HttpConfiguration..ctor(HttpRouteCollection)' to access method 'HttpConfiguration.DefaultFormatters()' failed' error.
To avoid the error drop the higher .net version back on the new project to match the Web API project - for this example right click the unit test project, click properties, then change the target framework to .net framework 4.5.
In my case it was a discrepancy between versions of Microsoft.AspNet.WebApi.Client and Microsoft.AspNet.WebApi.Core, I tried updating both to the same version and it worked.
In my case, the issue was solved when I installed the Microsoft.AspNet.WebApi.Core as well. So three libraries should present and be in harmony (uninstall / install) Microsoft.AspNet.WebApi.Client, Microsoft.AspNet.WebApi.Core and Newtonsoft.json
same for the above answers in my case also it is working good after updating or reinstalling packages
Microsoft.AspNet.WebApi.Client
Microsoft.AspNet.WebApi.Core

How to obtain System.Web.Http.Tracing.dll?

I read about Web API having its own TraceWriter implementation with 2012.2, for example here, among other sources.
I am now using VS2013 with .NET 4.5.1 and the EnableSystemDiagnosticsTracing is nowhere to be found. It's meant to be defined in the HttpConfigurationTracingExtensions class which resides in the System.Web.Http.Tracing.dll. However, this assembly is nowhere to be found - not in list of assemblies in the Add Reference dialog, not in GAC.
Where is this assembly supposed to come from? Docs say it's part of .NET Framework 4, which I have installed. Also installed the ASP.NET Web API 2 Tracing 5.0.0 NuGet package. Is there some update? Should I re-install .NET Framework?
I know it's not a big deal to implement ITraceWriter myself but it bothers me not to know what happened with the built-in implementation.
Just install needed NuGet Package
Install-Package Microsoft.AspNet.WebApi.Tracing -Version 5.0.0
It's a little bit strange, but it is the right package
http://www.nuget.org/packages/microsoft.aspnet.webapi.tracing
If you installed the Tracing 5.0.0 NuGet package, it should be correctly included in your project. The moment it is installed, I believe a separate text file should open in VS showing the code you should include in your WebApiConfig.cs file.
I haven't created a Web API 2 project from scratch (only upgraded from pre-5.0 to 5.0 projects), but this is the code that should reside in your WebApiConfig.cs file:
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
And that should be it, if the package is installed correctly, tracing should now be used in your project.

Resources