views:

274

answers:

1

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__AnonymousType02 (System.Data.Linq.SqlClient.Implementation.ObjectMaterializer1) 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__AnonymousType02(System.Data.Linq.SqlClient.Implementation.ObjectMaterializer1)

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.

  1. Has anyone else encountered this and if so, is there a "quick" fix?
  2. Is there a way to use the datasource to limit the rows?
  3. 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.

+2  A: 

System.MethodAccessException is thrown by the framework when it is missing an assembly, or one of the references are the wrong version.

The first thing I'd do is try uploading and referencing your code to the LINQ assemblies in your BIN, instead of the shared hosting providers GAC.

FlySwat