未定义预定义类型'System.Object'或未导入.net 4.6 [英] Predefined type 'System.Object' is not defined or imported .net 4.6
问题描述
我正在使用MVC 5和.net 4.6创建一个我的移动应用程序也可以连接的Web API.
I'm using MVC 5 and .net 4.6 to create a web API that my mobile app can connect too.
每当我构建项目时,都会出现数百个错误,告诉我我需要添加已经存在的引用,并且项目中的每种类型实际上都不存在.这些错误的一些示例:(不包括标题中的一个)
Whenever I build the project I get hundreds of errors telling me that I need to add references that are already there and that literally every type in my project 'does not exist'. Some examples of these errors: (Not including the one in the title)
我尝试过的事情:
- 通过nuGet添加了对System.Runtime的引用. (来自此问题的建议.)
- 从project.json文件中的框架中删除了aspnetcore50. (另一项建议,
- Added a reference to System.Runtime via nuGet. (A recommendation from this question.)
- Removed aspnetcore50 from the frameworks in the project.json file. (Another recommendation, this question.)
- Restarting VS2015, my machine.
- Going through the nuGet package manager and upgrading every package in my project to the latest.
- Actually making sure I can see the references in the references node of the solution explorer.
更新:-我的project.json
文件如下所示. (根据卡尔斯答案进行修改后.错误列表现在减少到十个,但是它们仍然是以前的错误.)
UPDATE: -My project.json
file looks like this. (After modifying based on Karls answer. The error list is now down to ten, however they are still the same errors as before.)
{
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"System.Runtime": "4.0.20-beta-23019"
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Data.DataSetExtensions": "4.0.0.0",
"System.Data.Linq": "4.0.0.0"
}
}
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"version": "1.0.0-*",
"webroot": "wwwroot"
}
推荐答案
我在这里有点猜测,但您似乎对dnx451
使用常规的System.Data.*
东西却感到怀疑,但没有什么可做的为dnxcore50
做好准备.您是否还以核心版本为目标?或者仅仅是项目创建过程中的剩余内容?如果您要定位核心版本并且仍然使用旧的System.Data.*
东西,则需要包装这些程序集中的所有内容.
I'm guessing a bit here but it looks suspicious that you are using the regular System.Data.*
stuff for dnx451
but doesn't have anything to make up for it for dnxcore50
. Are you targeting the core edition as well or is it just leftovers from project creation? If you want to target the core edition and still use the old System.Data.*
stuff you'll need to wrap anything from those assemblies like this.
#if DNX451
// Do some DNX451 specific stuff here
#endif
反之亦然.
#if DNXCORE50
// Do some DNXCORE50 specific stuff here
#endif
但是,如果您尚未考虑支持此功能,我只需从框架列表中删除dnxcore50
,您的错误可能就会消失.
But if you aren't thinking about supporting this yet I would simply remove dnxcore50
from the framework list and your errors will probably go away.
这篇关于未定义预定义类型'System.Object'或未导入.net 4.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!