2015-12-18 66 views
0

我試着在我的Mac上運行新的核心CLR類型ASP.Net並運行到問題的結束。ASP.Net與StructureMap.Dnx的DNX核心CLR問題:類型'對象'是在一個未引用的程序集中定義

我已經成功地得到引用StructureMap,並通過DNU和DNU恢復安裝,但在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" 
    ] 
} 

任何幫助感激地接受!

謝謝

+0

你有沒有嘗試刪除dnxcore50並剛剛運行dnx451?當它瞄準兩個框架之一時可能會失敗。 – BenM

+0

同樣的事情 - 跑了dnu再次恢復,沒有變化 –

+0

假設你也嘗試了相反的做法嗎? – BenM

回答

1

我試了一下,可以建議你兩個版本來解決編譯問題。

第一種方法是刪除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;

0

我也得到這個錯誤。我剛剛從dnx文件夾中刪除了所有軟件包,並通過「dnu restore」重新恢復所有軟件包,並且已修復。

相關問題