[英]ASP.Net DNX Core CLR issue with StructureMap.Dnx: The type 'Object' is defined in an assembly that is not referenced
我正在Mac上试用新的Core CLR类型ASP.Net,并且没有出现任何问题。
我设法通过dnu和dnu restore引用并安装了StructureMap,但是现在我在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添加一个use,但这并不能解决问题。
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"
]
}
任何帮助表示感谢!
谢谢
我尝试了一下,可以建议您使用两个版本来解决编译问题。
第一种方法是删除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();
"dnxcore50": { }
scanning.TheCallingAssembly();
并using StructureMap.Graph;
我也收到此错误。 我只是从dnx文件夹中删除了所有软件包,然后通过“ dnu restore”再次恢复了所有软件包,这是固定的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.