1

I have an ASP.Net Core App and when I try to start it, the following line throws a System.TypeLoadException:

    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        if (env.IsEnvironment("Development"))
        {
            // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
            builder.AddApplicationInsightsSettings(developerMode: true);
        }

        builder.AddEnvironmentVariables();
        Configuration = builder.Build(); // <-- exception is thrown here
    }

The Exception reads:

Could not load type 'System.Runtime.Serialization.ISerializable' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

This is what my project.json looks like:

{
  "dependencies": {
    "adremes.Common": "1.1.0",
    "adremes.Data": "1.1.2",
    "AutoMapper": "5.2.0",
    "Microsoft.AspNetCore.Hosting.Abstractions": "1.1.0",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.SignalR.Server": "0.2.0-preview2-22683",
    "Microsoft.AspNetCore.WebSockets": "1.1.0-preview1-23121",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0",
    "AutoMapper.Collection": "2.1.2",
    "Microsoft.AspNetCore.Identity": "1.1.0",
    "DocumentFormat.OpenXml": "2.7.0-vnext0061",
    "AspNet.Security.OpenIdConnect.Server": "1.0.0-beta7-final",
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha3-final",
    "Microsoft.ApplicationInsights.AspNetCore": "2.0.0",
    "Microsoft.AspNetCore.Mvc": "1.1.1"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview4-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "adremes.Exchange.Common": {
          "target": "project"
        },
        "adremes.Exchange.Data": {
          "target": "project"
        },
        "adremes.Exchange.Services": {
          "target": "project"
        }
      },
      "imports": [
        "dnxcore50"
      ]
    }
  },
  "runtimes": {
    "win10-x64": {}
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "allowUnsafe": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

The referenced projects are all netstandard1.5

I tried adding "System.Runtime.Serialization.Primitives": "4.3.0" to my dependencies without success.

Does anyone know what I have to do to successfully start my Project?

5
  • whats the target framework of the solution? 4.0 or higher. Try setting to 4.0 if higher. Commented Jan 30, 2017 at 8:51
  • The target is netcoreapp1.0; because I#m using ASP Core, I cannot set it to 4.0, 4.5, etc. Commented Jan 30, 2017 at 9:03
  • have you tried adding it in as a dependant assembly in config. <dependentAssembly> <assemblyIdentity name="System.Runtime.Serialization.Primitives publicKeyToken="7cec85d7bea7798e" culture="neutral" /> Commented Jan 30, 2017 at 9:06
  • This is .Net Core and does not have a .csproj to add a dependantAssembly. However as mentioned above I tried adding it to the project.json without success. Commented Jan 30, 2017 at 9:11
  • I'm unfamiliar with .Net Core sorry. Is there no "Web.config" either? That is where the config setting goes Commented Jan 30, 2017 at 9:14

1 Answer 1

1

The problem is in the dependencies section of the project.json.

The line

"Microsoft.NETCore.App": "1.1.0",

should be

"Microsoft.NETCore.App": {
  "type": "platform",
  "version": "1.1.0"
},

Then this would generate an Error at startup (use "dotnet run" from a console to see the error message).

The error says that 1.1.0 of Microsoft.NETCore.App is missing.

Installing it from https://www.microsoft.com/net/download/core#/current then fixed the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.