ASP .NET 5 Empty Project returns 500 Internal Server Error - asp.net-core

I've created a new Web Application, using the empty ASP .NET 5 preview template. The project builds after I run dnu restore.
When I run it, I get an empty response (i.e. blank page). Refreshing the page, I get a "HTTP Error 500.0 - Internal Server Error" typical page with no useful info (see screenshot below).
I'm using the standard boilerplate code from the project template:
public class Startup
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app)
{
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
I noticed that if I set a breakpoint, it tells me the breakpoint won't be hit.
What am I doing wrong, and how can I get this simplest of scenarios working?
Edit: project.json is the default one that comes with the project template (uses beta 5, which I know is not the latest):
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}

It's just crazy what I had to go through to make this work. Summary:
Go to %userprofile%, delete everything in .dnx\packages (just to make sure there aren't conflicts between different beta runtime versions)
Make sure latest runtime is being used
dnu restore
Replace dependencies in project.json as per this answer
As per comment below that answer, replace "Microsoft.AspNet.Hosting --config hosting.ini" with "Microsoft.AspNet.Server.Kestrel"
In Startup.cs, replace using Microsoft.Framework.DependencyInjection; with using Microsoft.Extensions.DependencyInjection;
Run project with command line invoking dnx web, NOT from Visual Studio
Moral of the story: the "preview template" that comes with Visual Studio is WAY out of date, and you're better off starting a fresh project.
Note: at the time of writing, the latest runtime is 1.0.0-rc1-update1.

Related

Reference local build of Microsoft.AspNetCore.Mvc in AspNetCore application

How can I reference a local build of Microsoft.AspNetCore.Mvc in my Asp.Net Core application? I'm trying to debug something in the framework. I've pulled down the source and have it compiled, but I can't get my application to see the location to pick-up the code.
My global.json file:
{
"projects": [
"src",
"test",
"c:/source/repos/mvc/src"
],
"sdk": {
"version": "1.0.0-preview2-003131"
}
}
Snippet of my package.json file. The version is the same version as the DLL that is built:
"dependencies": {
"Microsoft.AspNetCore.Mvc": {
"version": "1.2.0-preview1",
"type": "build"
},
If you want to be sure it will use the project reference instead of the nuget reference you can specify the dependency target:
"Microsoft.AspNetCore.Mvc": {
"version": "1.2.0-preview1",
"type": "build",
"target" : "project" //this will make sure it only looks for a project
},
Also make sure you run dotnet restore before you build the project.

Need Help Building ASP.NET Core Source Because of Missing .Net Version

I can't seem to find the version of asp.net core that is wanted to build what is at the current asp.net core site. I'm currently getting the error that vs is looking for v 1.0.0-preview2-1-003180 but I can't find that anywhere to install. I'ved looked here:
https://github.com/dotnet/core/blob/master/release-notes/download-archive.md
What is the recommended way to download the source from
https://github.com/aspnet/Mvc
and build it. (I'm on the dev branch).
Update:
There are 13 projects in the solution. There is a global.json in solution and a project.json in each project.
Here is the global.json:
{
"projects": [
"src",
"test/WebSites",
"samples"
],
"sdk": {
"version": "1.0.0-preview2-1-003180"
}
}
Try updating "frameworks" property of project.json to something like:
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": "dnxcore50"
}
},
This should target .NET Core 1.1 rather than the specific SDK version you are receiving an error on.
Hopefully that helps!

AspNetCore namespace doesnt exist

I'm following this course to learn ASP.NET Core.
I did exactly as they did, I can type dotnet new and dotnet restore.
I also installed the dotnetcore 1.0.1 SDK preview.
All seems fine, and I should be able to type
using Microsoft.AspNetCore.Http;
But the only things recognized after Microsoft are cSharp, visualbasic and win32?
Here is my project.json file:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.AspNet.WebApi": "5.2.3",
"Microsoft." **<< i cannt type AspNetCore here**
},
"imports": "dnxcore50"
}
}
There is no Microsoft."AspNetCore". The only things I do have starting with Asp are:
AspNet.Identity.Owin
AspNet.Mvc
AspNet.Providers.Core
AspNet.Razor
AspNet.SignalR
AspNet.Web.Optimization
AspNet.WebApi
AspNet.WebApi.Clients
AspNet.WebApi.Core
AspNet.WebApi.Cors
AspNet.WebPages
The code completion doesn't always work when editing the project.json file, especially if you're using a lighter editor like VS Code. (Sometimes it doesn't work even in full-blown Visual Studio).
If this happens, don't worry! You can still install any packages you need. Find packages by searching on NuGet and then edit the dependencies section like this:
"PackageName": "1.0.0" # Version from package details on NuGet
Then, use the dotnet restore command within the project directory to pull down all the packages in project.json.

ASP.Net 5 RC1 unresolved dependency: NU1001 The dependency ... >= 1.0.0-* could not be resolved

I hoping someone can help shed some light on how to get around this issue. I've noticed this issue while attempting to add a classic .csproj class library to a ASP.NET 5 RC1 xproj project and while attempting to add references to regualar .NET 4.5-4.6 assemblies to xproj based ASP.NET 5 RC1 projects. In this particular case I'm trying to add a reference to Microsoft.WindowsAzure.ServiceRuntime to an ASP.NET 5 WebApi project. I can see a wrap file get's generated that looks like this:
{
"version": "1.0.0-*",
"frameworks": {
"dnx46": {
"bin": {
"assembly": "../../lib/dnx46/Microsoft.WindowsAzure.ServiceRuntime.dll"
}
}
}
}
The reference in the project.json file looks like this:
"frameworks": {
"dnx46": {
"dependencies": {
"Microsoft.WindowsAzure.ServiceRuntime": "1.0.0-*"
}
}
},
When open up the project.lock.json file I see the following get added:
"DNX,Version=v4.6": [
"Microsoft.WindowsAzure.ServiceRuntime >= 1.0.0-*"
]
When I look at the references in visual studio I see the following:
What am I doing wrong? Is there any kind of workaround for this issue?

Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1'

I'm using ASP.NET 5.0 and I wanted to run just on the new Core CLR, so I removed "dnx451": { } from dependencies in my project.json file. I now get the following error when I launch in IIS:
Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
Microsoft.AspNet.Mvc 6.0.0-beta4
Microsoft.AspNet.Server.IIS 1.0.0-beta4
Microsoft.AspNet.Server.WebListener 1.0.0-beta4
Microsoft.AspNet.StaticFiles 1.0.0-beta4
My understanding was that AspNet.Mvc 6 would run on Core CLR? Why then do I have to include dnx451 as a dependency?
My project.json file:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"frameworks": {
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
Specifying dnxcore50 as a dependency in project.json is not the same as telling the Solution to target that dnx. To fix this I had to modify the solution global.json file to use a specific version of the dnx (i.e. a specific .Net executable). I also had to change a few using statements to use new Core CLR libraries instead of .Net 4.5 libraries. You will get intellisense and error warnings about these.
The global.json file can be found under the Solution node. I had to add the sdk version part:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta4"
}
}
Note that you can also edit this in a GUI:
Strongly recommend the recently uploaded ASP.NET Introduction and ASP.NET Deep Dive videos from Build 2015 available on Channel 9.
I had this error when publishing my DNX web app. It turned out it was because I had upgraded from Beta5 to Beta6 but neglected to update my publish powershell script which looks like:
$thisFolder = (Get-Item -Path ".\" -Verbose).FullName
$webFolder = "$thisFolder\..\src\Web.UI"
dnu publish $webFolder `
--out \\uatserver\uatshare `
--configuration DEBUG `
--no-source `
--runtime dnx-clr-win-x64.1.0.0-beta5
So in the last parameter my publish was still telling it to target beta5 instead of beta6.