问题
转到特定页面时(在本地调试中)时出错:CS0012:类型'System.Data.Linq.DataContext'在未引用的程序集中定义.您必须添加对程序集'System.Data.Linq,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的引用.
Error when going to a specific page (in local debug): CS0012: The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
以下是错误消息中引用的代码行:
Here are the referenced lines of code in the error message:
第28行: 第29行: 第30行:公共类_Page_Views_blah_granny_cshtml:System.Web.Mvc.WebViewPage { 第31行: 第32行:#line隐藏了
Line 28: Line 29: Line 30: public class _Page_Views_blah_granny_cshtml : System.Web.Mvc.WebViewPage { Line 31: Line 32: #line hidden
所有其他页面都很好用-仅在访问特定页面时才会发生这种情况.该参考在其他所有页面上均有效.据我所能确定的,这与参考文献无关.
All other pages work great - this only happens when accessing one page in particular. The reference is working on all other pages. As far as I am able to determine, this is not a problem with the reference.
我花了很多时间研究这个问题.
I've spent a good block of time researching this issue.
我发现的所有答案都建议转到web.config并将程序集引用放在linq的system.web>配置>程序集中.我的没有列出程序集,我怀疑这对于较旧的版本来说更多.无论如何我都做到了.它给了我另一个错误,说它不知道如何处理程序集.
All the answers I found suggested going to web.config and putting an assembly reference to linq in system.web > configuration > assemblies. Mine doesn't have assemblies listed and I suspect this is more for older versions. I did it anyway. It gave me another error saying it has no idea what to do with assemblies.
我删除了system.data.linq并再次添加了它.
I deleted system.data.linq and added it in again.
我重新启动了VS和计算机.
I rebooted both VS and my computer.
我的代码-由VS默认生成-具有System.Linq.
My code - as generated by default by VS - has System.Linq.
背景-这是这样开始的:
该应用程序是MVC 4,C#.
The application is MVC 4, C#.
我在DataContext中创建了一个新类,添加了一个新的控制器,并创建了一个强类型的视图.
I created a new class in my DataContext, added a new controller, and created a strongly typed view.
这里有一些非常相似的代码(可能不需要,但以防万一).
Here is some very similar code (likely not needed, but just in case).
两个类:
public class granny { public string data { get; set; } public string criteria { get; set; } } public List<granny> getGranny() { var a = from x in grannytable join dx in anothertable on x.criteria equals dx.criteria select new granny { data = x.somenewdata; }; return a.ToList(); }这是控制器:
public ActionResult granny() { return View(db.getGranny()); }那里什么都没有.
该页面是典型的剃刀视图,其类型为强力的列表" ...它具有要迭代创建的表,并随即转储数据.
The page is a typical razor view, strongly typed "List"...it has a table that it iterates to create, dumping the data as it goes.
很高兴根据需要提供其他任何代码.
I am happy to provide any additional code as needed.
我还没有弄乱web.config.我尚未删除或调整页面上的任何参考.所有其他视图都很棒.
I have not messed with web.config. I have not removed or tweaked any of the references on the pages. All of the other views work marvelously.
当我在本地运行它并尝试转到/granny时,出现上述错误.
When I run it locally, and attempt to go to /granny I get the above error.
感谢您的帮助!
解决方案:我参考了System.Linq(对于旧版本,我想是System.Data.Linq),并将CopyLocal更改为True.
THE SOLUTION: I went into references, and for the System.Linq (or for older versions, I suppose, System.Data.Linq) and changed CopyLocal to True.
推荐答案这对我有用:
- 导航到Web项目的引用"节点
- 找到对System.Data.Linq的引用
- 打开VS属性窗口
- 在属性窗口中,将复制本地:错误"更改为真"
在此之前,未将System.Data.Linq.dll复制到bin目录中. (将其手动复制到bin目录中也解决了该错误)
Before this, the System.Data.Linq.dll was not being copied into the bin directory. (Copying it manually into the bin directory also resolved the error)
更多推荐
类型"System.Data.Linq.DataContext"在未引用的程序集中定义
发布评论