类型“System.Data.Linq.DataContext"在未引用的程序集中定义 [英] The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced

查看:23
本文介绍了类型“System.Data.Linq.DataContext"在未引用的程序集中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

转到特定页面时出错(在本地调试中):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 hidden

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 并在 system.web > 配置 > 程序集中放置对 linq 的程序集引用.我的没有列出程序集,我怀疑这更适用于旧版本.反正我做到了.它给了我另一个错误,说它不知道如何处理程序集.

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 属性窗口
  • 在属性窗口中,将 Copy Local: False 更改为 True

在此之前,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"在未引用的程序集中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆