20

I'm deploying a asp.net core 2.0 website to IIS 10.

I've made sure that my app is using the correct configuration for ISS in the program.settings file.

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();
}

And in my startup.cs file:

    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<IISOptions>(options =>
        {
        });
        services.AddMvc();
    }

Yet when I run dotnet website.dll from the command line I get the below error message shown in the command line window:

An assembly specified in the application dependencies manifest (website.deps.json) was not found: package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.1' path: 'lib/netstandard2.0/Microsoft.AspNetCore.Antiforgery.dll' This assembly was expected to be in the local runtime store as the application was published using the following target manifest files: aspnetcore-store-2.0.3.xml

Based off the error message, i'm guessing Microsoft.AspNetCore.Antiforgery isn't being bundled when I publish since I do not receive this error when debugging.

How can I ensure that my app can find Microsoft.AspNetCore.Antiforgery when published to a live environment?

EDIT: This is a basic .net core website. No changes have been made to the standard project at this time apart from the above changes for deployment with IIS.

When I run the project from IIS instead of the command line I get a 502.5 error message.

3
  • 2
    Try dotnet restore. If this not help use temporary solution and just copy this *.dll from local to deploy
    – J. Doe
    Commented Nov 23, 2017 at 14:21
  • 1
    As @J.Doe mentioned, try a dotnet restore. Would you also mind sharing your csproj? Commented Nov 24, 2017 at 10:13
  • 1
    If you publish in Windows (other somewhere other than your server) and run in Linux, then make sure both .Net SDK's version are the same or compatible. You can check their versions with dotnet --info or dotnet --version.
    – Babak
    Commented Feb 18, 2018 at 15:21

8 Answers 8

18

I was able to fix this issue by updating the .net core runtime on the server to v2.0.3.

This issue occurs if

  1. You have an existing server running v2.0.0 of the .net core runtime.
  2. You create an app targeting v2.0.3 of the SDK
  3. You publish the v2.0.3 app to a server running v2.0.0

The issue can be resolved by installing v2.0.3 of the runtime on the server. You can download the runtime from the microsoft site here https://www.microsoft.com/net/download/windows

3
  • 5
    Alternatively, you can revert to an earlier .NET Core Nuget package. I had to install 2.0.0 because the Pivotal Cloud Foundry buildpack I was pushing to was at 2.0.0 and my build was using 2.0.3. Commented Dec 7, 2017 at 11:56
  • 1
    There is a "ASP.NET Core Runtime" and a ".NET Core Runtime". Only the ASP version solved the issue for me (v2.0.7 worked). Also, on the download page you first have to click the "Run apps" button, to access these downloads.
    – Wouter
    Commented May 29, 2018 at 9:39
  • 1
    In my case I needed to change the base image in Dockerfile from aspnetcore:2.0 to aspnetcore:2.0.8 because I was referencing Microsoft.AspNetCore.All 2.0.8 which required Microsoft.AspNetCore.Antiforgery >= 2.0.3.
    – Danioss
    Commented Jul 10, 2018 at 10:18
11
+50

If you are actually using this library, make sure that your *.csproj file has the corresponding explicit reference:

<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="..." />

Then, play with the PublishWithAspNetCoreTargetManifest property to resolve the aforementioned issue with a mismatched manifest. Check out the following threads to learn more about possible issues while its deployment:

An assembly specified in the application dependencies manifest (RhWeb.deps.json) was not found

published application is missing assembly (missing runtime store associated ...) [2.0.0-preview2-005905]

HTTP Error 502.5 - Microsoft.AspNetCore.Antiforgery.dll

1
  • 1
    Adding the PublishWithAspNetCoreTargetManifest property with value false appears to work for me. i did notice the additional files included with a publish. It appears it makes the application wholly self-contained?
    – gregsonian
    Commented Feb 14, 2018 at 22:25
6

I had this issue - simple workaround, actually install the NuGet package (I wasn't using it).

Microsoft.AspNetCore.Antiforgery

Published, deployed - fixed the issue.

In another case, when I published the project, a lot of the dlls weren't being placed in the publish folder - including Antiforgery. The below appears to force publishing to add all the required dlls.

Edit your projectname.json file to ensure PropertyGroup contains PublishWithAspNetCoreTargetManifest = false:

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>

Interested to know why the above works?!

1
  • Thanks! Made simple the dependency nightmare I got myself in with different projects using different versions of dotnet on an old VPS.
    – Tyeth
    Commented May 27, 2018 at 14:10
3

This also problem happens if Antiforgery is called but Antiforgery is not installed.

Can be fixed by installing Microsoft.AspNetCore.Antiforgery by Nuget package manager.

1

I fixed this issue on my inhouse windowsserver with this solution
* go to netcore https://github.com/dotnet/core/tree/master/release-notes
* go to the lastest version of the core runtime 2.?
* download DotNetCore.2.0.6-WindowsHosting.exe in my case
https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.6-download.md#net-core-runtime-only-installation

Install this on server and the error was solved for me. Hope this helps anyone.

1

Got this error after updating Microsoft.AspNetCore.All from v2.0.7 to v2.0.8 (latest at the time) and then publishing to a server that was running .NET Core Runtime v2.0.7 (latest at the time).

Downgraded Microsoft.AspNetCore.All back down to v2.0.7, re-published, and everything works.

1

If you publish the app as a self-contained ASP.NET Core 2.2 apps as per the linked screenshot (I don't have enough rep for inline image), it will fix this issue.

Self contained: Screenshot

This can be set when editing your publish settings.

0

If this issue is related to your Razor mail template, you can add "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation". When I add, the problem is solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.