.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Question on WCF service with Linq to SQL on 64-bit system

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :.NET Framework
I'm trying this question one more time since I realized the work in in a 64-bit environment. I have a WCF service which runs in production in a 32-bit environment using VS2008 and .NET 2.0. We made a big change to our environment (lots at the same time) and I moved the services to VS2010, .NET 4.0, and 64-bit processes.  I wrote a new service and deployed it under IIS.  If I browse to the service I get the example screen and clicking on the link gives me the metadata.  So all of that is working. In my services I create a Linq to SQL context, perform a query, then return the result set as an Array.  I wrapped the context creation with a using.  My tests returned an exception "Attempt to access an object that has already been disposed".  I traced it down and found that the code executes, forces the query, returns the results, exits the using statement (disposing the context properly) then exits the method.  The next thing I get is the exception, inside framework code, and it is linq code attempting to fulfill the query once again. I have searched until I'm blue in the face trying to find prior incidents and fixes but all I found was one post, two years ago, same problem with less debugging, and no answer to the problem other than 'don't use the using statement' which is a bad suggestion.  So for a work around I wrote a Co

View Complete Post

More Related Resource Links

C#, LINQ: (List<>) Question???


Hi Everyone,

I have a strange problem:


There is an entity (Table) called "Filters" in my .edmx which has all my tables and stuff in it (to use it for LINQ queries)

I have created a class called "CustomFilters" which inherits "Filters". So now my cutom class has all the properties of the original "Filters" class (table) and 1 more additional property that i wanted which is a List of "CustomFilters":

List<CustomFilters> children = new List<CustomFilters>();

Now i get all my records into:

List<CustomFilters> theOriginalList = new List<CustomFilters>();

NOTE: first all records are tken into a List<Filters> and then these are added into List<CustomFilters> where List<CustomFilters> for children of that record is added, and then children of the child records, and so on......

so now, every record is an instance of CustomFilters which has a property named "children" which is a list again; and each child again has instanaces of "CustomFilters", and each instance again has children...and on and on and on.....

(basiacally its a data source for a treeview in my silverlight control)

every thing is good and working as expected.


The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must



This is frustrating, and I don't know how to solve it.

I have a strange problem. I am adding a LinqDatasource object, and set the context:

        protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
            e.ObjectInstance = new KaruselaDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

Then I get this error:
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=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.


On web.config I already have this:
<add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

NOTE: The datacontext is in a different project (DLL proect) where I added a refernce to System.Data.Linq.

is there another way adding a refernce to a web project? or only though teh web.config?


System.Xml.Linq.XElement and XPathDocument


I have an XPathDocument that I want to save to a table using LINQ, but I get this error

cannot implicitly convert type 'System.Xml.XPath.XPathDocument' to 'System.Xml.Linq.XElement'

I create the XPathDocument from some (valid) xml contained in a resource file

XPathDocument xDoc = new XPathDocument(new StringReader(Resource1.TestXML));

when I try to assign it with LINQ, it flags up an error

NewDataItem.XML = xDoc  ----  error here

NewDataitem is a LINQ to SQL object created from the underlying table, 'NewDataItem.XML' is a column type of 'XML'

how do i (easily) convert xDoc so I can pass it into the LINQ object ?

Team System: Team Foundation Server Event Service


Use the Team Foundation Server EventService to create and manage event subscriptions or create a Web service to receive and process events.

Brian A. Randell

MSDN Magazine May 2008

Service Station: What's new in System.Xml 2.0?


In this installment of Service Station, Aaron Skonnard takes a long hard look at System.Xml 2.0.

Aaron Skonnard

MSDN Magazine September 2006

web service soap mapper error question

Hi,I'm trying to connect to a web service using excel.I have currently no issues logging into the web service, and running one of the other functions to fetch a full list of data.  Once I am able to log in, the function returns a token, which I use to fetch data.But Currently, I'm getting the following errors one two of the functions:SoapMapper:Restoring data into SoapMapper ViewListResult failed HRESULT=0x80020009: Exception occurred. - Client:Unspecified client error. HRESULT=0x80020009: Exception occurred.Run-time error '-2147221504 (80040000)':SoapMapper:Restoring data into SoapMapper ViewListResult failedAny idea why I might be getting this error?  And also how I can fix it?  Thanks.

Serializing Linq to Entities for use in a REST Service

What would be the best approach to send data retrieved from Linq to Entities over a rest service? For example, if you have a Linq to Entities class, say Products from the Northwind database. I want to return a subset of the Products (based on a query on the model) back through a service. First a retrieve a List<Product> from the context, and then i need to serialize the data and send it over the wire. If I use the exact Linq to Entities class, then there is so much "garbage" that it either fails outright (from a circular reference) or you are wasting bandwith. What is a design to overcome this? Create POCO objects for each linq to entities class you want to send and create custom code to tranform each object in the list to the POCO object? This is the only way I can see doing it, although it would be very tedius to create and maintain (unless some custom code generation was created). Is there a better approach? clients

Question about WCF Service hosted in Windows Service

Hi, I have little experience with WCF and working on a projet that requires WCF Service instance to run 24x7. After searching for a solution and reading about WCF, I think if I host it under Windows Service I can have a single instance of WCF Service running 24x7. Is this correct? I just successfully ran the MSDN sample project that hosts CalculatorService in Windows Service. I realized that Windows Service cannot communicate with WCF Service it is hosting (I do not have any experience with writing Windows Service). I wrote a test function (public) in Windows Service and tried to call it from WCF Service but it did not appear in the Intellisense list. Is my assumption correct or is there a way to establish communication between Windows Service and its hosted WCF Service? Thanks. kr

System.ComponentModel.DescriptionAttribute not showing up in REST service

I am trying to set the description for a REST WCF service, but it doesn't seem to be working. Code is: [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]     [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]     [WebDispatchFormatterConfiguration("application/xml")]     [WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.PoxDataContract), "application/xml", "text/xml")]     [WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.DataContractJson), "application/json")]     [WebDispatchFormatterMimeType(typeof(WcfRestContrib.ServiceModel.Dispatcher.Formatters.FormUrlEncoded), "application/x-www-form-urlencoded")]     public class PublicAppointmentSchedulerSvc : IPublicAppointmentScheduler     {         IPublicAppointmentScheduler impl = new PublicAppointmentScheduler();         [WebDispatchFormatter]         [Description("Immediate or callback contact request")]         [WebInvoke(UriTemplate = "InitiateContact", Method = Verbs.Post)]  &n

Noob Question - Using Linq in View

I just inherited an MVC2 application. So far my only experience with MVC is reading the Nerd Dinner sample chapter and downloading the nerd dinner app. I do plan to dive much deeper but i need a quick answer because i have to hit the ground running. So basically in the main Index view the view model is being passed as an IQueryable. Then he is doing some queries on the view model to loop through the data. See example below:<% if (Model.Where(w => w.State == workflowStep.Key).Count() > 0) { %>To me, even though minor, this is business logic and shouldn't be in the view. Shouldn't any type of logic like this be sorted out before you get to the view? Or is this common practice in MVC?Basically i want to know if I should spend time refactoring this thing or just go with the flow.  Thanks.

The type or namespace name 'Linq' does not exist in the namespace 'System'

Hi, I uploaded my website to the server, and I have there a working with wcf - it should be fw 3.5 I saw that fw 3.5 is installed on the server and also we have there fw 3.0 sp1. I run my website : www.qenglishcenter.com and I'm getting an error : The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) shouldn't System.linq be already existed ? Thanks for any reply.  

SQL Server 2008 R2 Installation and Service Pack 1 Question

I am migrating a SQL 2000 server to a SQL 2008 R2 server (on different physical servers) . When I ordered SQL Server 2008 the volume licensing allowed me to download sql server web 2008, sql server web 2008 R2 and sql server 2008 service pack 1. I don't know why I have three options to download. Don't I just need to just install the sql server 2008 Web R2? Are there any sql 2008 R2 service packs available?   

Can´t set up local system accounts as service accounts in sharepoint 2010

HI I made an inplace upgrade to sharepoint 2010. I want to setup performance point services. but it doesn´t allow me to set a local system account as the application pool account for performance point services application. It doesn´t allow me to register a new account it says The specified user account "domain\username" is a local account. Local accounts should only be used in stand alone mode. The application pool account for the site collection that I upgraded is a local system account so I don´t get it? I tried this http://sharepoint.microsoft.com/blogs/fromthefield/Lists/Posts/Post.aspx?ID=112 However the upgrade fails after this. Is there any way that I do the inplace upgrade and it would allow me to use local system accounts has service accounts? Without Active directory? Thanks      

Linq to SQL - DeferredLoadingEnabled/DataLoadOptions Question

I am reading a book that suggests that when you need data from a child table that you should both: Set DeferredLoadingEnabled to false and Set the DataLoadOptions This seems a bit redundant to me.  If DeferredLoadingEnabled is false, why would you need to set the DataLoadOptions?  Doesn't turning off deferred loading mean that the child tables will automatically get loaded when the query is executed? Thanks

LINQ left outer join question

I can do this in other ways, but am looking for the "LINQ" way of doing this: Table1: People (PersonId,SchoolId)Table2: AssignedPeople (PersonId,SchoolId,RoomId) I want to select the people in Table1 within a particular SchoolId that are not in the assignedPeople table (in a particular Room).  The SQL is: select p.* from people p left outer join assignedpeople ap on p.PersonId=ap.Person and p.SchoolId=ap.SchoolIdand ap.RoomId=@roomId where p.SchoolId=@SchoolId and ap.PersonId is null I tried this LINQ (VB,NET):dim SchoolID as guid=...dim RoomID as guid=... (from p in dc.people where p.SchoolId=SchoolIdgroup join ap in dc.AssignedPeopleon p.PersonId equals ap.PersonId and p.SchoolId equals ap.SchoolId into groupfrom g in group.DefaultIfEmptywhere g.RoomID = nothing) but I can't get the ap.RoomId=@roomId part into the right place, should be something like:group join (from ap in dc.AssignedPeople where ap.RoomId=RoomId) Any help would be appreciated,Reuven

Simple question.... LINQ on Datatable

Hi all,Simple one this I am sure for those who use LINQ! :)I basically have two tables that will be stored in viewstate until I save the data to the database.  I need a way to query the datatables, delete remove etc.  Is this possible in LINQ?So for example, delete/select rows from the DataTable that have a particular ID etc...Thanks,Mark

Linq to SQL Web Service cannot be serialized problem

Hello All, Ok so I'm playing around with Web Services using Linq to SQl. I apparently have  a lot of learning to do. What I'm trying to do below is pull data from the Northwind db Employee Table. I don't need to see the whole table, I'm just trying to select individual(s) but I keep getting the following error  "System.Data.Linq.Binary cannot be serialized because it does not have a parameterless constructor" Code Below: Thanks in advance for any advice <WebMethod()> _ Public Function EmployeeInfo() As List(Of Employee) Dim db As New NorthwindDataContext() Dim output = From cust In db.Employees _ Select cust.EmployeeID, cust.FirstName, cust.LastName Return output End Function  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend