ASP.Net DNX Core CLR проблема с StructureMap.Dnx: тип "Объект" определен в сборке, на которую нет ссылок

Я испытываю новый тип CLR типа ASP.Net на моем Mac и работаю без проблем.

Мне удалось получить ссылку и установить StructureMap через dnu и dnu restore, но теперь я получаю ошибки в VS Code, утверждающие, что:

The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. [dnx451]

Я сделал много поисков, но все, что я могу найти, это то, что мне нужно добавить использование System, но это не решает проблему.

Startup.cs:

using System;
using System.Reflection;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using StructureMap;

namespace Authorization
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var container = new Container();
            container.Configure(x => {
                x.Scan(scanning => {
                   scanning.Assembly(Assembly.GetExecutingAssembly());
                   scanning.TheCallingAssembly();
                   scanning.WithDefaultConventions(); 
                });
            });

            container.Populate(services);

            return container.GetInstance<IServiceCollection>(services);
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UseIISPlatformHandler();

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

        // Entry point for the application.
        public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run<Startup>(args);
    }
}

project.json:

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },
    "tooling": {
        "defaultNamespace": "Authorization"
    },

    "dependencies": {
        "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
        "StructureMap.Dnx": "0.4.0-alpha4"
    },

    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel"
    },

    "frameworks": {
        "dnx451": {},
        "dnxcore50": {}
    },

    "exclude": [
        "wwwroot",
        "node_modules"
    ],
    "publishExclude": [
        "**.user",
        "**.vspscc"
    ]
}

Любая помощь с благодарностью получена!

Спасибо

2 ответа

Решение

Я немного попробовал и могу предложить вам две версии, чтобы исправить проблему с компиляцией.

Первый способ это удаление dnxcore50 и внести некоторые изменения в Startup.cs, Чтобы быть точно можно использовать следующее project.json:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "structuremap": "4.0.1.318",
    "StructureMap.Dnx": "0.4.0-alpha4"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

и следующее Startup.cs:

using System.Reflection;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using StructureMap;
using StructureMap.Graph;

namespace HelloWorldWebApplication
{
    public class Startup
    {
        public IServiceCollection ConfigureServices(IServiceCollection services)
        {
            var container = new Container();
            container.Configure(x => {
                x.Scan(scanning => {
                    scanning.Assembly(typeof(Startup).GetTypeInfo().Assembly);
                    scanning.TheCallingAssembly();
                    scanning.WithDefaultConventions();
                });
            });
            container.Populate(services);
            return container.GetInstance<IServiceCollection>();
        }

        public void Configure(IApplicationBuilder app)
        {
            app.UseIISPlatformHandler();
            app.Run(async context => {
                await context.Response.WriteAsync("Hello World!");
            });
        }

        public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run<Startup>(args);
    }
}

В качестве альтернативы можно добавить обратно "dnxcore50": { } в "frameworks" часть, но прокомментируйте строку scanning.TheCallingAssembly(); а также using StructureMap.Graph;

Я также получаю эту ошибку. Я просто удалил все пакеты из папки dnx и восстановил все пакеты снова с помощью "dnu restore", и это исправило.

Другие вопросы по тегам