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.
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 datasource and was unable to find a way to limit the results the way I desired, so I removed that and wrote the following:
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) 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)
I tried to research 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.
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)
Thanks in advance for the help and please let me know if I need to provide more details.