0

我最近在共享主机上遇到了 linq 的问题。
主机是 Shared Intellect,它们支持 v3.5 的框架。但是,我不确定他们是否安装了 SP1。我怀疑他们没有。

我有一个简单的News表,其结构如下:

NewsID          uniqueidentifier
Title           nvarchar(250)
Introduction    nvarchar(1000)
Article         ntext
DateEntered     datetime (default getdate())
IsPublic        bit (default true)

我的目标是显示该表中最近的 3 条记录。我最初采用 D&D 方法(我知道,我知道)并创建了一个 linq 数据源,但无法找到一种方法来按照我想要的方式限制结果,所以我删除了它并编写了以下内容:

var dc = new NewsDataContext();
var news = from a in dc.News
           where a.IsPublic == true
           orderby a.DateEntered descending
           select new { a.NewsID, a.Introduction };
lstNews.DataSource = news.Take(3);
lstNews.DataBind();

这在我的本地机器上完美运行。

但是,当我将所有内容上传到共享主机时,我收到以下错误:

.Read_<>f__AnonymousType0`2
(System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1<System.Data.SqlClient.SqlDataReader>) 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.MethodAccessException: 
.Read_<>f__AnonymousType0`2
(System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1<System.Data.SqlClient.SqlDataReader>)

我试图在谷歌上搜索错误,但没有成功。然后,我尝试以我能想象到的各种方式修改我的查询,删除 where/orderby 参数的各种组合,并将我的查询限制为单个列,甚至删除Take 命令

因此,我的问题分为三个部分:

  1. 有没有其他人遇到过这种情况,如果有,是否有“快速”修复?
  2. 有没有办法使用数据源来限制行?
  3. 有没有办法确定共享主机运行的框架版本没有直接通过电子邮件发送(我已经完成并正在等待答案)
4

1 回答 1

2

System.MethodAccessException当缺少程序集或引用之一的版本错误时由框架抛出。

我要做的第一件事是尝试将代码上传并引用到 BIN 中的 LINQ 程序集,而不是共享托管服务提供商 GAC。

于 2008-08-24T23:12:37.667 回答