Home Issues in referencing .Net Standard 1.6 library from .Net framework 4.6.1 Web API app
Reply: 0

Issues in referencing .Net Standard 1.6 library from .Net framework 4.6.1 Web API app

Raj
1#
Raj Published in 2017-12-07 19:15:11Z

We have a .Net standard 1.6 library that has some middleware classes defined. Able to use this library from .Net core 1.0 Web API app, no issues here.

But not able to use it from .Net Framework 4.6.1 (on VS 2017 15.4.1) Web API apps.

No access to ApplicationBuilder to configure Middleware as there is no StartUp class available in .Net framework Web API project. When I created a StartUp and Program classes manually(as shown below), I am able to configure the middleware in Startup class, But have issues in Program.cs where I configured to use the StartUp class.

Getting "FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" exception in Program.cs class.

I wanted to know whether I am on right track on dealing with this issue. Please suggest if we have better way of handling this case.

StartUp.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MyCompany.myMiddleware;

public class Startup

{
    public Startup(IHostingEnvironment env)
    {

    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // This Middleware is defined in .netStandard 1.6 library.            
        app.UseThisMiddleWare();
    }
}

Program.cs

using Microsoft.AspNetCore.Hosting;
public class Program
   {
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()                
            .Build();

        host.Run();
    } 
 }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319429 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO