Serialize Linq To SQL Entities For Use In Out - Of - Proc Session State?
Mar 11, 2010
I need to put some of the entities created via a.dbml Linq-To-Sql file into Session State. Because I am using out-of-proc State Server, they need to be serializable. How can I achieve this? I have tried setting the Serialization mode in the .dbml file to 'Unidirectional'.
I am new to .net 4.0 and am using EF Model and SessionState Mode=SqlServer and I am getting this error below:
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
I checked the stack trace and its complaining about
I marked it as serializable but then it complains about System.Data.Objects.ObjectContext is not marked as serializable and hence throws the same error.
We have been receiving reports of the following server error periodically from users. [OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.] [HttpException (0x80004005): Unable to serialize the session state.] Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is "StateServer" or "SQLServer".
Once in a state where this error appears, it appears to be hit or miss whether the errors are reproducible locally. If they are, then we can usually reproduce them for a couple minutes, but not on every page hit. This usually tapers off on its own and usually has resolved itself by the time we get back in contact with the users. The Web Service has around 90-100 active connections during business hours. The only other site on this server is the staging version of this site, which gets hit very infrequently. The Session State is stored on the same SQLServer instance as the application database which is housed on a fairly large cluster of virtual machines.
Neither the Web Server or the SQLServer seemed to be taxed (either processor or memory-wise) while this is going on. The distribution of which pages are erroring seems to be comparable to the normal distribution for each page. There doesn't appear to be any pattern in terms of times of occurrence. We do have less errors on average on weekends (which correlates to normal site load), but even this appears to not be consistent. There also doesn't appear to be a correlation between the errors logged and any kind of logged performance monitor events. This includes an array of perfmon counters including:
.NET CLR Jit(w3wp) otal # of IL Bytes Jitted .NET CLR Jit(w3wp)IL Bytes Jitted / sec .NET CLR Jit(w3wp)\% Time in Jit .NET CLR Jit(w3wp)# of Methods Jitted .NET CLR Jit(w3wp)# of IL Bytes Jitted ASP.NET Apps v1.1.4322(__Total__)Requests Failed ASP.NET Apps v1.1.4322(__Total__)Errors Unhandled During Execution/Sec ASP.NET Apps v1.1.4322(__Total__)Errors Unhandled During Execution ASP.NET Apps v1.1.4322(__Total__)Cache Total Turnover Rate ASP.NET Apps v1.1.4322(__Total__)Errors During Preprocessing ASP.NET Apps v1.1.4322(__Total__)Errors During Execution ASP.NET Apps v1.1.4322(__Total__)Requests Executing ASP.NET Apps v1.1.4322(__Total__)Requests Total ASP.NET Apps v1.1.4322(__Total__)Errors Total ASP.NET Apps v1.1.4322(__Total__)Sessions Abandoned ASP.NET Apps v1.1.4322(__Total__)Errors Total/Sec ASP.NET Apps v1.1.4322(__Total__)Anonymous Requests/Sec ASP.NET Apps v1.1.4322(__Total__)Requests/Sec ASP.NET Apps v1.1.4322(__Total__)Session SQL Server connections total ASP.NET Apps v1.1.4322(__Total__)Cache Total Hit Ratio ASP.NET v1.1.4322Requests Current ASP.NET v1.1.4322Request Execution Time MemoryPages/sec Bytes Total/sec PhysicalDisk(_Total)Avg. Disk Queue Length Processor(_Total)\% Processor Time Web Service CacheFile Cache Hits % Web Service CacheFile Cache Misses Web Service CacheFile Cache Hits Web Service(_Total)Current Connections Web Service(_Total)Post Requests/sec)
The only pattern I can see in the logs doesn't correlate to the occurrence of these errors, but is the only pattern I can see. Looking at the perfmon logs we are seeing a pattern where the "Total # of IL Bytes Jitted", "IL Bytes Jitted / sec", "% Time in Jit", "# of Methods Jitted", and "# of IL Bytes Jitted" counters for the staging site (which shouldn't be getting any traffic) doesn't pull data for a 20-50 minute period after which there is an immediate spike in "IL Bytes Jitted / sec" and a jump in "% Time in Jit" for 2-20 minute of up to 99% for the main site.
I'm trying to save a custom class in a session, but it just never gets saved, along with other sessions. Note that my SessionMode = STATESERVER, and i cannot change it to INPROC as per our business requirement. This is my class
/*******START*******/ [Serializable] public class User : ISerializable { private int _userId; public int UserId { get { return _userId; } set { _userId = value; } } //custom class private TDB.tdbUser _tdbUserDetails; public TDB.tdbUser tdbUserDetails { get { return _tdbUserDetails; } set { _tdbUserDetails = value; } } //collection of custom class Sites private List<Sites> _assignedSites; public List<Sites> AssignedSites { get { return _assignedSites; } set { _assignedSites = value; } } public User() { //Constructor code } /******SERIALIZATION*****/ protected User(SerializationInfo info, StreamingContext context) { this._userId = (int)info.GetValue("_userId", typeof(int)); this._assignedSites = (List<Sites>)info.GetValue("_assignedSites", typeof(List<Sites>)); this._tdbUserDetails = (TDB.tdbUser)info.GetValue("_tdbUserDetails", typeof(TDB.tdbUser)); } [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("_userId", this._userId); info.AddValue("_assignedSites", this._assignedSites); info.AddValue("_tdbUserDetails", this._tdbUserDetails); } } /*******END*******/
The calling code is just this: (User)HttpContext.Current.Session["TDBUSER"];
Type 'System.Data.Linq.ChangeTracker+StandardChangeTracker' in Assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable
have read all threads but still cant solve the error. I can do insert update and delete but dont know where exactly the error occurs and how??
Private Sub MakeMeSomeXmlBeforeRyanGetsAngry() Dim db As New MyDBDataContext Dim customer = From c In db.Customers Select c Dim dcs As New DataContractSerializer(GetType(Customer)) Dim sb As StringBuilder = New StringBuilder Dim writer As XmlWriter = XmlWriter.Create(sb) dcs.WriteObject(writer, customer) Dim xml As String = sb.ToString Response.Write(xml) End Sub
I am attempting to serialize my linq collection of customers. But it keeps throwing
Type 'System.Data.Linq.DataQuery`1[MyDB.Customer]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
My issue is that I have already marked the dbml Serialization Mode to UniDirectional and when I check the dbml codebehind all of the DataContract()> and DataMember()> elements are there.
I am not sure how to proceed. I have tried adding various dataloadoptions and setting deferredloading to false, but no luck.
Currently I am working on SessionState with SQL. I have problem. I would like to serialize TreeNode. This TreeNode pbject will be assigned to Session and this is declare as below.
Is there any way or process to serialize the the objects?? i am trying to store the instance of few control in viewstate but it shows error msg that it is not a serialized object. should i perform some steps to serialize the objects ???
I had an xml-serialization which worked fine, but as I have just knew it doesn't work in Opera browser. I think, it's security rules don't allow to write to cookies xml-content.What can I do? Can I use binary serialization or something else?
Trying to pass in my DataTable to a stored proc using LINQ. Below is my code.
var sqlCommand = new System.Data.SqlClient.SqlCommand { CommandType = System.Data.CommandType.StoredProcedure, CommandText = "UserIdList" }; var dataTable = new System.Data.DataTable("IdList"); dataTable.Columns.Add("AttributeIds", typeof(Int32)); dataTable.Rows.Add(26); dataTable.Rows.Add(40); dataTable.Rows.Add(41); dataTable.Rows.Add(45); dataTable.Rows.Add(78); dataTable.Rows.Add(33); dataTable.Rows.Add(36); //The parameter for the SP must be of SqlDbType.Structured var parameter = new System.Data.SqlClient.SqlParameter { ParameterName = "@AttributeIds", SqlDbType = System.Data.SqlDbType.Structured, TypeName = "ecs.IDList", Value = dataTable, }; sqlCommand.Parameters.Add(parameter); var user = myDC.DC.ExecuteQuery("exec ecs.udpUserAttributeDetails {0}, {1}", sqlCommand, userId).SingleOrDefault();
Have not run the ASP.NET Development Server for a while. Today I copied a production website to my workstation and ran it with VS 2008. The following error message popped up. What is the problem with the ASP.NET development Server on my workstation? The website on the Production server still ran okay.Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of KEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesaspnet_stateParametersAllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.
I am Developing A Application . I want to develop this Application with Linq and used Stored proc in linq Plz give me Some suggestion How we used And If You Have Some Related Topic
We have three web servers in our web farm that are load balanced using the Network Load Balancing Manager in Windows 2003. The sites that run on these boxes use In-Proc ASP.NET session. Our assumption is that the balancing uses a "sticky" session because users seem to be assigned to a given server during their use of the application as well as there doesn't appear to be any session error where the session data is residing on a previous machine. My question is how can I 1) verify that our balancing configuration is using "sticky" sessions and 2) can someone explain the load balancing feature in Windows 2003 relative to ASP.NET web applications?
How to use Stored Procedures with Linq to Entities? I prefer an example with input and output The videos on asp.net only show how to do this with Linq to SQL.
SELECT * FROM MessageAlerts AS A LEFT OUTER JOIN Contacts AS C ON A.ContactId = C.Id LEFT OUTER JOIN Users AS U ON A.UserId = U.Id INNER JOIN Businesses AS B ON B.Id = C.BusinessId OR B.UserId = U.Id
how to do this : ON B.Id = C.BusinessId OR B.UserId = U.Id with linq in entity framework.
I've got an ASP.NET MVC app running under IIS7. It's using the default in-proc session management, which, according to all that I read, should lose the users' session after an app pool recycle.It doesn't seem to be losing it though. Even an IIS reset doesn't lose the session.Has something changed in IIS7 that keeps the session alive?
WHY are all the examples on this site linq to SQL? Did ms not themselves announce dropping support for l2SQL over a year ago? i really don't get it. Examples are great.. but really not helping me since i've gone ahead and listened to MS. And can someone at MS clarify what the position is for linq 2 SQL.. Is it supported? Recommended? What the hell.
I am trying to learn LINQ to entities, and am working out how to best structure my BLL layer. I have generated the entity model and have created a generic repository in my DAL that returns results as IList<T>. I initially created the BLL to also return
results as IList<T>:
public IList<DAL.Customer> SelectAll() { [code]...
Now I am working on the aspx page, and I can create an ObjectDataSource and configure it to use my BLL, but since I am returning IList, I can't sort since I am not using a DataView. I have seen some articles on the web for converting IList to DataView, but that seems like a lot of overhead for every query.My goal is to keep a clean separation between layers without making things overly complicated. I would like to know how others have done this, or maybe a link to a good tutorial that shows how to structure all three layers.
I read the solutioin for this error, at the following link :http://forums.asp.net/p/1046935/1576341.aspxbut I am still not clear what exactly causes the error. I have two doubts :1. Can anyone please elaborate a bit on this issue, with any example ????2. Is there any drawback of this approach ?
I am building a web application in asp.Net 4.0 and entity framework. I am trying to retrieve a list of products based on a collection of id's. I first gather all the id's in a collection and then pass it to the linq query. I am trying to get a functionality similar to the IN clause in SQL. The problem seems to be with the Contains() method in the Linq to entities query. Here is my Linq code:
[Code]....
I got the above Linq to entities method from here: [URL]
I have a message table that self joins to itself where Message.ID == Message.Parent. So I have 1 Message with several ChildMessages. This is set up nicely with a Navigation property.
The code is currently:
var message = from m in soe.Messages.Include("ChildMessages") where m.ID == id && m.IsActive select m; return message.FirstOrDefault();
What I really want is to only return 1 Message (that is equal to a particular ID and isActive) with all of its Active ChildMessages and I want to do it in one call to the database.