I recently ran into an issue with linq on a shared host.
The host is Shared Intellect and they support v3.5 of the framework. However, I am uncertain to whether they have SP1 installed. My suspicion is that they do not.
我最近在共享主机上遇到了linq的问题。主机是共享智能,它们支持框架的v3.5。但是,我不确定他们是否安装了SP1。我怀疑他们没有。
I have a simple News
table that has the following structure:
我有一个简单的新闻表,具有以下结构:
NewsID uniqueidentifier
Title nvarchar(250)
Introduction nvarchar(1000)
Article ntext
DateEntered datetime (default getdate())
IsPublic bit (default true)
My goal is to display the 3 most recent records from this table. I initially went the D&D method (I know, I know) and created a linq data-source and was unable to find a way to limit the results the way I desired, so I removed that and wrote the following:
我的目标是显示此表中的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();
This worked perfectly on my local machine.
这在我的本地机器上完美运行。
However, when I uploaded everything to the shared host, I recieved the following error:
但是,当我将所有内容上传到共享主机时,我收到以下错误:
.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>)
I tried to search the error on Google, but met with no success. I then tried to modify my query in every way I could imagine, removing various combinations of the where/orderby parameters as well as limiting my query to a single column and even removing the Take command.
我试图在Google上搜索错误,但没有成功。然后我尝试以我能想象的各种方式修改我的查询,删除where / orderby参数的各种组合,以及将我的查询限制为单个列甚至删除Take命令。
My Question therefore comes in 3 parts:
因此,我的问题分为三部分:
- Has anyone else encountered this and if so, is there a "quick" fix?
- Is there a way to use the datasource to limit the rows?
- Is there some way to determine what version of the framework the shared host is running short of emailing them directly (which I have done and am awaiting an answer)
有没有其他人遇到过这个,如果有的话,是否有“快速”修复?
有没有办法使用数据源来限制行?
有没有办法确定共享主机运行的框架版本没有直接通过电子邮件发送(我已经完成并正在等待答案)
1 个解决方案
#1
2
System.MethodAccessException
is thrown by the framework when it is missing an assembly, or one of the references are of the wrong version.
框架在缺少程序集时抛出System.MethodAccessException,或者其中一个引用的版本错误。
The first thing I would do is try uploading and referencing your code to the LINQ assemblies in your BIN, instead of the shared hosting providers GAC.
我要做的第一件事是尝试将代码上传并引用到BIN中的LINQ程序集,而不是共享主机提供程序GAC。
#1
2
System.MethodAccessException
is thrown by the framework when it is missing an assembly, or one of the references are of the wrong version.
框架在缺少程序集时抛出System.MethodAccessException,或者其中一个引用的版本错误。
The first thing I would do is try uploading and referencing your code to the LINQ assemblies in your BIN, instead of the shared hosting providers GAC.
我要做的第一件事是尝试将代码上传并引用到BIN中的LINQ程序集,而不是共享主机提供程序GAC。