'Microsoft.AspNet.Server.Kestrel' issue while hosting in IIS - iis

I have ASP.NET Core MVC 6 Web API project, which when hosted on IIS, gives the below error:
Error: Unable to load application or execute command 'Microsoft.AspNet.Server.Kestrel'. Available commands: web, ef.
System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
at System.Reflection.Assembly.LoadFile(String path)
at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadFile(String assemblyPath)
at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName)
at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
at Microsoft.Dnx.Host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadAssemblyImpl(AssemblyName assemblyName)
at Microsoft.Dnx.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
Contents of project.json:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data.Entity": "4.0.0.0"
}
},
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Please note, I have tried deleting the global.json file, and also tried running the commands dnu list, dnu restore, dnu build. Still getting the same error.
Thanks in advance.

Thanks everyone!! :) I switched from RC1 to RTM, and hosted the API in IIS successfully!
Used the below links:
docs.asp.net/en/latest/tutorials/first-web-api.html
docs.asp.net/en/latest/publishing/iis.html
#DavidG : If you had 'answered' instead of 'comment', I would have marked it as the answer. Thanks anyways!

Related

Service Stack InvalidOperationException When Requesting /types/typescript

I'm using service stack to build an api on .Net Core and it all works well, but I would like to have access to the type links generated by the service, but when I request the type listing for typescript at /types/typescript I get:
Response Status
Error CodeInvalidOperationExceptionMessageSequence contains no elementsStack Trace[TypesTypeScript: 11/12/2016 6:45:10 AM]: [REQUEST: {baseUrl:"http://localhost:55000"}] System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at ServiceStack.NativeTypes.MetadataTypesGenerator.ToType(Type type) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/NativeTypes/NativeTypesMetadata.cs:line 331 at ServiceStack.NativeTypes.NativeTypesService.GenerateTypeScript(NativeTypesBase request, MetadataTypesConfig typesConfig) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/NativeTypes/NativeTypesService.cs:line 209 at ServiceStack.Host.ServiceRunner1.Execute(IRequest request, Object instance, TRequest requestDto) in /opt/lib/teamcity-agent/work/d09206570215629/src/ServiceStack/Host/ServiceRunner.cs:line 107Errors
Type links for all the other types work. I've confirmed this behavior on windows and linux.
Below is my project json.
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Data.SQLite": "1.0.*",
"ServiceStack.Core": "1.0.*",
"ServiceStack.Interfaces.Core": "1.0.*",
"ServiceStack.Text.Core": "1.0.*",
"ServiceStack.Client.Core": "1.0.*",
"ServiceStack.Common.Core": "1.0.*",
"ServiceStack.Server.Core": "1.0.*",
"ServiceStack.Admin.Core": "1.0.*",
"Npgsql": "3.1.*",
"ServiceStack.OrmLite.PostgreSQL.Core": "1.0.*",
"ServiceStack.OrmLite.Sqlite.Core": "1.0.*"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
What is the best way to get this information to the service stack team? I'm not a commercial customer (yet)
This should now be resolved from the v1.0.29 NuGet .Core packages on NuGet.
If you're referencing ServiceStack dependencies via wild card, e.g 1.0.* then running dotnet restore will install the latest version.

Deploy .Net Core MVC app w/ class library to Ubuntu 16.04:

I wanted to build a simple .net core MVC app with a single class library for data access, to get an idea of what it takes to build/deploy/run Core on Linux. Not nearly as simple as I had hoped!
EDIT: Here's a copy of the solution, if anyone is interested:
https://s3.amazonaws.com/kilonova-public/code/CoreCrossPlatform.zip
I threw together a VirtualBox VM w/ Ubuntu Server 16.04 and installed dotnet core per these instructions:
https://www.microsoft.com/net/core#ubuntu
I installed all the latest, necessary bits on the host (Win10) for VS 2015 and created a solution with an MVC app and single class library called "DataAccess". It's EF Core talking to MySQL using their latest core provider. It all runs flawlessly on the Win10 host when I run/debug it. Pulls up data and looks great.
"dotnet --version" on both the host and the VM gives me:
1.0.0-preview2-003121
However, when I deploy it to the Ubuntu VM, I get the following error on the class library dependency:
Project corecrossplatform (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling corecrossplatform for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/project.json(24,23): error NU1002: The dependency DataAccess does not support framework .NETCoreApp,Version=v1.0.
Compilation failed.
0 Warning(s)
1 Error(s)
Time elapsed 00:00:00.0187782
This happens whether I run "dotnet restore" or "dotnet run". To be perfectly honest, I'm not even sure I'm deploying this thing correctly. Documentation is spotty and I'm making some guesses. I copied everything from the project folder "src\CoreCrossPlatform" (contains bin, Program.cs, appsettings.json, etc.) onto the VM and this is where I'm executing the "dotnet" commands from, in the VM.
The DataAccess .json file:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.0",
"MySql.Data.Core": "7.0.4-IR-191",
"MySql.Data.EntityFrameworkCore": "7.0.4-IR-191",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
The MVC project.json:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"DataAccess": "1.0.0-*"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Something to note: When I run the sample project using "dotnet new" and restore, run vis the tutorial link above, it runs fine.
What am I missing? Another side question: What's the best way to publish this type of app to a Linux box? Am I even close on that part?
Thanks much.
EDIT: While kicking this dead horse all afternoon, I compared some notes I found online, related to this "NU1002" error, and the sample project "dotnet new" generates. I tried changing the "framework" section of both project.json files (MVC and classlib) to the following, with no success...same error:
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dnxcore50",
"dotnet5.6",
"portable-net45+win8"
]
}
}
EDIT: Much thanks to goaty: As he pointed out in the comments, copying over the entire solution and building it, results in a successful build. However, I cannot run it without an error. It doesn't seem to restore the MySQL EF Core dependency:
Project CoreCrossPlatformFlat (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last build
Compiling CoreCrossPlatformFlat for .NETCoreApp,Version=v1.0
/opt/dotnet/corecrossplatform/src/CoreCrossPlatformFlat/project.json(25,52): error NU1001: The dependency MySql.Data.EntityFrameworkCore >= 7.0.4-IR-191 could not be resolved.
Compilation failed.
0 Warning(s)
1 Error(s)
The DataAccess library exists outside of your src/ directory. Therefore the web project could not find the reference.
I recommend this structure
src/
|---DataAccess/
|---CoreCrossPlatform/
Hope that helps :)

ASP.NET Core app not working after publish to Azure

I have an ASP.NET Core app which is running fine locally.
However, when I publish (Web Deploy) the site to Azure, I get a 403: You do not have permission to view this directory or page.
I have a default controller and a route defined in Startup.cs:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
The folder structure after web deploy to Azure looks like:
|_ home
|_ site
|_ wwwroot (contains DLL's and files specified through 'publishOptions' in project.json)
|_ wwwroot (the contents of the 'wwwroot' folder I have in Visual Studio)
|_ Views (contains MVC views)
|_ refs (contains referenced DLLs, I think?)
Any idea of what I should look for in project.json or the Kudu portal to figure out what's wrong?
My project.json file:
{
"title": "My Web App",
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true,
"compile": {
"exclude": [ "bin/**", "obj/**", "node_modules/" ]
}
},
"publishOptions": {
"include": [ "wwwroot", "Views", "appsettings.json", "appsettings.*.json" ]
},
"scripts": {
"prepublish": [ "jspm install", "gulp build" ]
},
"dependencies": {
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"System.IO.FileSystem": "4.0.1"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
},
"imports": "dnxcore50"
}
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:8000/"
}
}
Edit:
For one, I was missing the Microsoft.AspNetCore.Server.IISIntegration NuGet package. When I added it, I also got a web.config file in the site root (which I included through project.json).
I also added .UseIISIntegration() to my WebHostBuilder in Startup.cs:
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
I can now run it on IIS Express locally (although I guess it's IIS fronting Kestrel?), but when published to Azure I get error:
HTTP Error 502.5 - Process Failure
The event log in Azure states: Failed to start process with commandline '"%LAUNCHER_PATH%" %LAUNCHER_ARGS%', ErrorCode = '0x80070002'.
According to the documentation, the troubleshooting step is:
If the server does not have Internet access while installing the server hosting bundle, this exception will ensue when the installer is prevented from obtaining the Microsoft Visual C++ 2015 Redistributable (x64) packages online. You may obtain an installer for the packages from the Microsoft Download Center.
Not sure how this applies to Azure, though?
The problem came from insufficient IIS integration/configuration.
I had to add the following to project.json:
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
I also added a postPublish script for IIS publishing:
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
I also added the Microsoft.AspNetCore.Server.IISIntegration NuGet package:
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0"
}
This created a web.config file, which I had to modify as:
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\My.Web.App.dll" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
</system.webServer>
</configuration>
Finally I added UseIISIntegration to my WebHostBuilder:
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
A standard Publish (Web Deploy) from Visual Studio and the website started just fine on Azure (although in my case I also had to add a prepublish script for some Gulp tasks).

Cannot change Target Runtime when publishing to Azure from VS

I have a ASP.Core RC2 project (.NET 4.5.1 framework is used) that should be deployed on Azure as x86 Web-Site.
On Publish Setting tab in VS there are the following values:
Target Framework: .NET Framework 4.5.1
Target Runtime: Inferred Runtime (win7-x64)
What I want to change is the value of "Target Runtime" to x86 platform, but this combobox is inactive (grey).
Current project.json:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.Platforms": "1.0.1-*",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"net451": { }
},
"publishOptions": {
"include": [
"appsettings.json",
"project.json",
"web.config",
"NlogWeb.config"
]
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-*",
"imports": "portable-net45+wp80+win8+wpa81+dnxcore50"
}
},
"scripts": {
"postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
}
}
When you're developing self-contained applications, you have to add all required runtimes to the project.json file, so that nuget/dotnet restore can download the runtime files on restore.
Adding the win7-x86 runtime to the project.json should do the trick.
"runtimes": {
"win7-x64": { },
"win7-x86": { }
}
When you target portable apps, you don't need the runtimes section but you have to install the runtime yourself on the target machine. See .NET Core App Types documentation for a more detailed description on how portability types work and are configured.

Can't deploy ASP.net core RC2 targeting net451 or net46 to Azure Web App

I can't seem to be able to deploy my asp.net core RC2 app to Azure when I target the net451 or net46 framework.
When I try to reach my application I get the following error
The specified CGI application encountered an error and the server terminated the process.
Everything works when I deploy to my local IIS.
The Azure logger gives me
Failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%', Error Code = '0x80070002'.
I tried replacing %LAUNCHER_PATH% for dotnet and %LAUNCHER_ARGS% for myapp.exe in the web.config but still the same error occur.
Here is my project.json
{
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net46": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Thanks
It seems that updating my web.config to specify the processPath did the trick.
I also had to delete the previous publish attempts for it to work properly.
<aspNetCore processPath=".\myapp.exe" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout"/>
With the same symptoms I checked the logs as #Pawel suggested.
The logs contained FileNotFoundException which was resolved by adding two dependencies to project.json.
"dependencies": {
...
"System.IO.FileSystem.Watcher": "4.0.0-rc2-24027",
"System.IO.FileSystem": "4.0.1-rc2-24027"
},
The issue is reported here
Azure doesn't support net461 and use better net451.
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
Publishing SkyIsTheLimit for .NETFramework,Version=v4.5.1/win7-x64

Resources