StructureMap.DNX的ASP.Net DNX核心CLR问题:类型';对象';在未被引用的程序集中

本文关键字:DNX 引用 程序 集中 程序集 对象 Net 问题 CLR 类型 ASP | 更新日期: 2023-09-27 18:27:31

我正在我的Mac上试用新的Core CLR类型ASP.Net,并在中运行,问题层出不穷。

我已经设法通过dnu和dnu恢复引用和安装了StructureMap,但现在我在VS代码中遇到了错误,说明:

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]

我已经做了大量的谷歌搜索,但我能找到的都是说明我需要添加一个使用系统的东西,这并不能解决问题。

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"
    ]
}

感谢您的帮助!

感谢

StructureMap.DNX的ASP.Net DNX核心CLR问题:类型';对象';在未被引用的程序集中

我尝试了一点,可以建议您使用两个版本来解决编译问题。

第一种方法是删除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);
    }
}

或者,可以在"frameworks"部分添加回"dnxcore50": { },但注释行scanning.TheCallingAssembly();using StructureMap.Graph;

我也收到了这个错误。我刚刚删除了dnx文件夹中的所有包,并通过"dnu恢复"再次恢复所有包,这是修复。