"The EntityReference Object Could Not Be Serialized" When Serializing From .NET Web Site,?

Mar 22, 2010

I have an Entity Framework data model. Part of the model is a Customer entity. The web service provides a method to get a customer, and to receive an updated version of this customer to be persisted.

To test this, I created a new ASP.NET web Application, (Solution > Add > New Project > ASP.NET Web Application), then added a reference to my service reference using the standard Add Service Reference dialog. I then call the service using the following code:

var client = new CustomerServiceClient();
var customer = client.GetCustomerByID(18); // get it
customer.LimitDown = 100; // change it
client.SaveCustomer(customer); // persist it


Everything works as expected.

Now, I do exactly the same thing, but this time with as ASP.NET Web Site (Solution > Add > New Web Site > ASP.NET Web Site). I add the reference in a similar fashion and copy and paste the code above into the new site. But now I get the following exception thrown on the 4th line:

System.InvalidOperationException The EntityReference object could not be serialized. This type of object cannot be serialized when t RelationshipManager belongs to an entity object that does not implement IEntityWithRelationships.

Source Error:

Line 2474: Line 2475:
public
SkyWalkerCustomerService.OperationResult
SaveCustomer(SkyWalkerCustomerService.Customer[code]....

Googling for this error returns very little. Why doesn't this work?I guess one answer would be to use a web application instead of a web site, but I have an large existing site to which I need to add the service reference, and I'd rather not convert it.

View 1 Replies


Similar Messages:

C# - Deserializing An Object That Is Different Than When It Was Serialized?

Mar 29, 2011

I have an issue with deserializing an object. I get an error 'System.Int32' cannot be converted to type 'System.Decimal'. This object has many child objects and since this object has been serialized, a new version of the object has one or many fields that have been changed from int to decimal and now I can't deserialize the object because it doesn't match my original object.

I have tried using the OnDeserializing method but the context parameter.

Is there a way around this? I've found some examples online but it doesn't really apply to my situation. I would just like to know if there is a way to view my serialized object even if my object has now changed or if there is a way to find out which variable needs to be changed to decimal and how to go about doing it.

I've added your code but I'm not quite sure how to call it from my code. Here's what I've got:

public static Application LoadSnapshot(int appID, int statusID)
{
ApplicationSnapshotCollection AppSnap = new ApplicationSnapshotCollection();
AppSnap.LoadByAppAndSnapshotStatusID(appID, statusID);

[Code]....

How do I go about calling the constructor with the proper parameters in my scenario?

View 1 Replies

SQL Server :: Deserializing Object That Is Different Than When It Was Serialized

Mar 29, 2011

I have an issue with deserializing an object. I get an error 'System.Int32' cannot be converted to type 'System.Decimal'. This object has many child objects and since this object has been serialized, a new version of the object has one or many fields that have been changed to decimal and now I can't open or view the object because it doesn't match my original object. Is there a way around this? I've found some examples online but it doesn't really apply to my situation. I would post some code but I don't think it would really help...I would just like to know if there is a way to view my serialized object even if my object has now changed and how to go about doing it.

View 2 Replies

Best Way To Determine Type Of Object Serialized To XML?

Jan 2, 2011

I have a table in my SQL Server DB that holds auditing information for certain actions a user takes within my system. Things like who performed the action, when it was performed, and what action are all pieces of information that can easily span multiple actions. But depending on the action performed, there may be other information that I want to capture, that is specific to the action. To handle this, I elected to add an "XML Metadata" column to the table that holds serialized XML of different metadata objects that I've created. I created a metadata object for each of the actions that I'm interested in tracking extra for. So each object is responsible for tracking specific extra information (metadata) for it's action. The objects are serialized and written to my new column.

I have SystemAction objects that I use to store information from this table, and I've added a string field that holds the XML string from the DB. The problem is, when I'm reading this XML back from the SystemAction objects, I'm struggling with a way to generically translate it back into it's correct metadata object. Each metadata object is going to have different fields, and each object has it's own static method that takes an XML string and attempts to return the metadata object type. So I could say:

SomeActionMetadata mdObj = SomeActionMetadata.BuildFromXML(xmlStringFromDB);

But I really don't know of a way to say "Here's some XML that could translate to any number of different objects. Figure it out and give me the right object back."

Given my current implementation, I could always just assign a unique ID to each metadata object that is stored as a field in each object, then use a case statement to switch on that ID and use the appropriate class's static build method to build the right object. But I was hoping for something a little more automatic than that. What if I have a List of SystemAction objects and just want to loop through them and generate the correct metadata object type?

View 1 Replies

Serializing Only Parts Of An Object With Json?

Feb 14, 2011

I have an object called MyObject that has several properties. MyList is a list of MyObject that I populate with a linq query and then I serialize MyList into json. I end up with something like this

List<MyObject> MyList = new List<MyObject>();

MyList = TheLinqQuery(TheParam);

var TheJson = new System.Web.Script.Serialization.JavaScriptSerializer();

string MyJson = TheJson.Serialize(MyList);

What I want to do is serialize only parts of MyObject. For instance, I might have Property1, Property2...Propertyn and I want MyJson to only include Property3, Property5 and Property8.
I thought of a way to do this by creating a new object with only the properties I want and from there create a new list for the serialization.

View 1 Replies

WCF / ASMX :: Object Properties Serializing With PropertyName + Specified

Feb 22, 2011

I have a WCF service that when the objects serialize to clients an extra property is getting added with a 'Speficied' suffix. At first I thought it had to to with a couple of nullable type properties, but it is happening to all of my value types even if it is not declared Nullable. How can I get rid of this?

View 1 Replies

Visual Studio :: Serializing Object Direct From Debug Window

Jan 11, 2010

Is it possible to serialize object direct from Visual Studio .NET Debug window. I have a very complex object structure which contains multiple sub objects along with List item etc. I mean the Hierarchy is complex. And I need to analyze the object graph closely for that I need an offline view (may be in the from of XML/ Serialization). I can not do that from VS.

(One can reccomend me to use XMLSeriliazation in my code to generate but please consider that may not be alwways possible because of

1. with default .NET Serialization class a complex object which has manu sub objcts with Collection. is not get serialized properly. So need custom serialization & deserilazation code for that, does not come witf Microsoft Librarry.)

2. I am using it somewhere (Silverlift app) where such operation may be not possible.

3. I do not want to spent time creating or evaluating any ones custom serilaization code/tool

View 1 Replies

Crystal Reports :: Error Object Reference Not Set To An Instance Of An Object When Run The Site

May 27, 2010

I have the following code in my form load that loads the reports and assigns it to crystalreportviewer control. If Not IsPostBack Then

[Code]....

Following is the ApplyCRLogin Class

[Code]....

Now when I run the site it prompts me for the parameters and when I enter them and click on OK, I get the following error. "Object reference not set to an instance of an object." But the strange thing is if I comment the "If Not IsPostBack Then" condition, my report works fine. The problem is even when I want to go to the next page in report, the code get executed again and this takes time. Is there any other way to fix this?

View 3 Replies

Web Forms :: Object Reference Not Set To An Instance Of An Object Error When Remove Reference To Site Master Page

Sep 30, 2010

in my default.aspx page i have a dropdown List and a textbox with a submit button below that there are 2 listbox... and the dropdown list holds the names of the listbox

my logic here is to select an item from the dropdown list and put some text in the text box and submit the form which will add an item to the listbox selected.. but when i do this i get an error saying Object reference not set to an instance of an object. i tried to figure out the problem and found that when i remove the reference to the Site Master Page it works fine and when i undo and apply my reference back to the Site Master Page i get the same error.

[Code]....

View 2 Replies

Serialized Objects In View State?

Mar 10, 2011

i have been going through the documentation of viewstate. [URL]It was mentioned that objects that can be serialized are stored in viewstate. What is the meaning of serializing of objects ??

View 2 Replies

Parse JQuery Serialized Data In C#?

Oct 13, 2010

I have a ListBox on my page. I'm making an AJAX call to a C# function, and I need to pass the values of the selected items. Here's what I have:

$('#btnSubmit').click(function() {
$.ajax({
type: "POST",
url: 'Default.aspx/GetSelectedValues',
data: '{selectedValues: ' + $('#lbItems').serialize() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess
});
});
<select id="lbItems" multiple="multiple">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
[System.Web.Services.WebMethod]
public static string GetSelectedValues(string selectedValues)
{
//
}

The data being passed to the C# function looks like:

lbItems=1&lbItems=3&lbItems=5

Is there any built-in C# function that can deserialize that easily, to convert the values into an array of some sort? Or maybe there's a better way to pass the data from jQuery?

View 3 Replies

WCF / ASMX :: Linq To SQL Web Service Cannot Be Serialized?

Feb 6, 2010

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:

<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

View 7 Replies

Write Serialized XML To String And Display In Browser?

Aug 1, 2010

I have a serialized object which needs to be sent as an encrypted XML string. I am able to save the serialized object to a well-formed XML file, but this is not what I want. I have already got Rijndael encrypt/decrypt working for a sample string.

Person person = new Person("Irish", "Chieftain");
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
// Write serialized XML to file
System.Guid guid = System.Guid.NewGuid();

[Code]....

View 1 Replies

C# - Passing JSON Serialized Data Via Hidden Field?

Mar 2, 2011

In ASP.NET WebForms I want to pass arbitrary data from server to client and back again. I am serializing to JSON and have been simply producing JavaScript that creates the object on the client. I have no problem sending data to the server with ajax, but there are situations where I also want to send a Javascript object data back to the server on postbacks. So I guess it needs to be in a hidden field.

1) What is the best way to do this in terms of minimizing complexity and optimizing space and efficiency? In researching this I discovered Protocol Buffers but there does not seem to be a good C# implementation. I did find one, but it was a couple years old and self-described as buggy so that scared me.

2) If I just pass a JSON string, how can I be sure it will be safe to include as the value for a hidden field? Is there any reason I might not want to do this? I could Base64 encode, but it seems like this adds a lot of overhead. What is considered the best or preferred method?

View 1 Replies

Object Orientation In Web Site?

Feb 4, 2010

I was just wondering when it would be appropriate to undertake an object orientated approach when building a dynamic ASP.net website. How is it done? Could a website such as Amazon.com be object oriented? I'm just quite curious as to how it is done, because in any of the simple ASP.net websites I have created, I have never created a "user" class, and then in turn created a "user" object for each new user for example..I have instead just created stored the new user in the database.

View 4 Replies

C# - Serializing Data From A RSS Feed?

May 20, 2010

I'd like the user to specify a RSS feed address and serialize the information from it. I am not interested in the XML format, but populate a strongly typed object from the XML. My question is, is there a standard that all RSS feeds support (Do all of them have date, title etc)? If so, is there a XSD that describes this.If not, how do I handle serializing a RSS feed to an object in ASP.NET?

EDIT:
The SyndicationFeed's Items have the following properties:

Title.Text -> Gives us the title
Summary.Text -> Gives the Summary

Q1 - The Summary includes the html tags. Is there a way to strip them? I am interested only in the text
Q2 - Do all RSS feeds have full content in the Summary element? I see that some RSS feeds have only a few lines for Summary while others have the entire content of the post.

View 6 Replies

WCF / ASMX :: Implement The Chunking While Serializing?

May 28, 2010

I have an ASMX web service that returns a large dataset. The objects are custom. That is, I am not sending DataSets or other complex objects. I need to chunk the response because it could be large. Following this: http://support.microsoft.com/kb/278998, I have enabled chunked transfer encoding on the server. The client is java. I am doing something along these lines:

connection.setRequestProperty("Range", "bytes=" + rangeStart + "-" + rangeEnd);
int responseCode = connection.getResponseCode();

I see the request property come in on the server side. I see the server build the response. I am tracing the outbound soap, and it appears to be created. I expected to get a response code of 206 back when the response is large. But, I always get 200 (or an error if the request is too large, Request Entity too large on the BlackBerry).What do I need to do on the server side to chunk? I can explore moving to WCF if I have to, but, would rather avoid it. I am guessing I need to implement the chunking while serializing or possibly write a custom HTTP Handler to do it for me. The problem with the serializer approach is, the web service framework is doing the serilization for me. I can take this approach if needed.

View 2 Replies

Serializing A Javascript Array With Jquery?

Sep 28, 2010

I have the following code:

<script type="text/javascript">
var checksSinceLastPostBack = new Array();
function clientSelectedIndexChanged(sender, eventArgs) {
var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
var serializedCheckData = checksSinceLastPostBack.serializeArray();
if (ajaxManager != null)
ajaxManager.ajaxRequest(serializedCheckData);
}
</script>

The

var serializedCheckData = checksSinceLastPostBack.serializeArray();

doesn't seem to work. Am I misunderstanding this?

Also if this works, how would I deserialize it in the code behind?

View 1 Replies

C# - Serializing Request.Form To A Dictionary Or Something?

Jan 7, 2011

i need to pass my Request.Form as a parameter, but first i have to add some key/value pairs to it. I get the exception that the Collection is readonly.

I've tried:

System.Collections.Specialized.NameValueCollection myform = Request.Form;

and i get the same error.

and i've tried:

foreach(KeyValuePair<string, string> pair in Request.Form)
{
Response.Write(Convert.ToString(pair.Key) + " - " + Convert.ToString(pair.Value) + "<br />");
}

to test if i can pass it one by one to another dictionary, but i get:

System.InvalidCastException: Specified cast is not valid.

View 3 Replies

Serializing Two Dimensional Array With Newtonsoft.json

Apr 20, 2010

I am getting an error when trying to serialize an object products.
Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[3,2] { {"Small","40"}, {"Medium","44"}, {"Large","50"} };
string json = JsonConvert.SerializeObject(product);//this line is throwing an error

Array was not a one-dimensional array. Is there any way to serialize a two dimensional array with Newtonsoft.json.

View 2 Replies

Cannot Create A Process In A COM Object (written In .Net4) From An Asp (vbscript) Site

Jan 14, 2011

I'm updating an old process that already exists, which works as follows:

The user submits a form which runs the following asp (simplified, names changed):

<%
set rb = Server.CreateObject("RecordBuilder.SomeObject")
rb.Calculate()
rb.StartProcess()
%>

The RecordBuilder.SomeObject was an old VB6 DLL, I don't have VB6, so I converted it to VB.NeT 4.0

The call to Calculate() works as expected, the call to StartProcess() fails.

StartProcess() is the following:

Public Function StartProcess()
Try
strProcess = "Starting process"
Dim proc = New Process()
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.UseShellExecute = False
proc.StartInfo.CreateNoWindow = True
proc.StartInfo.FileName = "d:AppRecordProcessor.exe"
Dim procHandle = proc.Start()
strProcess = "Started process"
Catch ex As Exception
Err.Raise(vbObjectError + 9999, "RecordBuilder.SomeObject", strProcess & " failed: " & ex.Message & "<hr />Stack Trace:<br />" & ex.StackTrace)
End Try
End Function

This fails with the call to proc.Start(), however if I copy the test ASP to a .vbs file it will work as expected.

I have changed the permissions on d:AppRecordProcessor.exe to grant execute permission to the group Everyone.

View 1 Replies

JQuery Object Expected Error In .net Page With Master Site?

Oct 27, 2010

The error i get seems to be centered around jquery finding what it's in (window,document, etc.). Right now i'm just trying to implement the jQuery datepicker. the project has a master page, where i placed my script references.

<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />[code]...

I have tried document and window for jquery context, but they both throw the same error.

View 1 Replies

Web Forms :: Serializing The Value From A Textbox In Aspx.cs File To JavaScript Code?

Feb 19, 2011

I have a list in a textbox in aspx.cs file and I want to pass it in the javascript code in the second web form.

View 12 Replies

Web Forms :: Serializing An Array From Code Behind Of One Web Form To JavaScript Of Another Web Form

Feb 16, 2011

I have a web form where I create an array of type structure.

In this form I have:

[code]....

but this is not OK.

View 1 Replies

State Management :: Serializing To File System To Maintain State?

Oct 25, 2010

I have a system that has several large objects that need to be built and populated each and every time, and these objects may be accessed quite often as well. As a strategy, caching would not be that good for me because there are potentially thousands of these objects which are fairly large. So I propose to serialize the objects to the file system and then deserialize it when I need those objects again. I have several classes that need this serialization functionality.

These objects change as well, so on the next access I check if there were any changes and then I grab only the changes and edit the object, and then reserialize the object.

My question is what is the best way to do this, since I have several classes ..

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved