473,382 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

circular reference problem

Hi all

I am new to .NET and webservice so I wish someone can shed some light
on me.

I have a Project class and a Product class, the Project can contain
multiple Products (as an ArrayList). In my WebMethod I Initialize my
project as following:
<WebMethod()> Public Function ProjectInitial()
As Project

'Public Function ProjectInitial(ByVal inputProduct As
Product) As Project
Dim myProject As New Project
myProject = InitialProject("Test Project")

Dim myProduct As New Product
myProduct.cost = 100
myProduct.masterQty = 1000

Dim myProduct2 As New Product
myProduct2.cost = 200
myProduct2.masterQty = 2000
myProject.AddFinishProduct(myProduct)
myProject.AddFinishProduct(myProduct2)

Return myProject
End Function
The following is the structure of my Project class

[code:1:bb159c481b]

Imports System.Xml.Serialization

<XmlInclude(GetType(Product))> Public Class
Project

#Region " Project Properties "

Public projectID As Int32
Public projectName As String
Public projectStatus As Int32
Public projectCreateDate As DateTime
Public projectModifyDate As DateTime

Public ProductList As New ArrayList

#End Region

Public Sub AddFinishProduct(ByVal inputProduct As
Product)
'Add Product into the arraylist "ProductList "
....
....
End Sub
End Class
[/code:1:bb159c481b]

The following is the structure of my Product class

[code:1:bb159c481b]

Imports System.Xml.Serialization

<XmlInclude(GetType(Properties)),
SoapInclude(GetType(Product))> Public Class
Product
' Product properties
Public masterQty As Int32
Public cost As Double ' temperary cost, will use config costs to
replace
Public PropertyList As New ArrayList

' ArrayList stores it's component product
Public componentProduct As New ArrayList

Public Sub AddProduct(ByVal inputProduct As Product)
'Add Product object into componentProduct
....
....
End Sub
End Class
[/code:1:bb159c481b]

As you can see the I wish the Product can also contain a list of
Products because in my logic some Product can be constructed by a
list of Component Product but I want them to be in the same structure
because they have the same properties, also a Component Product can be
constructed by other Component Product.

If I don't add Product object into the Product, every
thing goes ok. But if I add a Project object inside a Product I have
the following error message

System.InvalidOperationException: There was an error
generating the XML document. --->
System.InvalidOperationException: A circular reference was detected
while serializing an object of type
ProjectInitialize.Product.

Is there any work around I can do to solve the problem? :?

Thanks in advance for your tips

Nov 12 '05 #1
1 6437
Has anyone found a solution to this web service circular reference problem?

Here's a simplified example:

Person him=new Person();
Person her=new Person();

him.Friend=her;
her.Friend=him;

Now try to serialize one of those object through an ASMX web service and
you'll get the following:

System.InvalidOperationException: There was an error generating the XML
document. --->
System.InvalidOperationException: A circular reference was detected while
serializing an object of type Person.

This article on IBM's site implies that .NET can do this somehow:
http://www-106.ibm.com/developerwork...-tip-j2eenet1/

Any ideas?

-Ben
http://www.benday.com

"dotnetnewbie" wrote:
Hi all

I am new to .NET and webservice so I wish someone can shed some light
on me.

I have a Project class and a Product class, the Project can contain
multiple Products (as an ArrayList). In my WebMethod I Initialize my
project as following:
<WebMethod()> Public Function ProjectInitial()
As Project

'Public Function ProjectInitial(ByVal inputProduct As
Product) As Project
Dim myProject As New Project
myProject = InitialProject("Test Project")

Dim myProduct As New Product
myProduct.cost = 100
myProduct.masterQty = 1000

Dim myProduct2 As New Product
myProduct2.cost = 200
myProduct2.masterQty = 2000
myProject.AddFinishProduct(myProduct)
myProject.AddFinishProduct(myProduct2)

Return myProject
End Function
The following is the structure of my Project class

[code:1:bb159c481b]

Imports System.Xml.Serialization

<XmlInclude(GetType(Product))> Public Class
Project

#Region " Project Properties "

Public projectID As Int32
Public projectName As String
Public projectStatus As Int32
Public projectCreateDate As DateTime
Public projectModifyDate As DateTime

Public ProductList As New ArrayList

#End Region

Public Sub AddFinishProduct(ByVal inputProduct As
Product)
'Add Product into the arraylist "ProductList "
....
....
End Sub
End Class
[/code:1:bb159c481b]

The following is the structure of my Product class

[code:1:bb159c481b]

Imports System.Xml.Serialization

<XmlInclude(GetType(Properties)),
SoapInclude(GetType(Product))> Public Class
Product
' Product properties
Public masterQty As Int32
Public cost As Double ' temperary cost, will use config costs to
replace
Public PropertyList As New ArrayList

' ArrayList stores it's component product
Public componentProduct As New ArrayList

Public Sub AddProduct(ByVal inputProduct As Product)
'Add Product object into componentProduct
....
....
End Sub
End Class
[/code:1:bb159c481b]

As you can see the I wish the Product can also contain a list of
Products because in my logic some Product can be constructed by a
list of Component Product but I want them to be in the same structure
because they have the same properties, also a Component Product can be
constructed by other Component Product.

If I don't add Product object into the Product, every
thing goes ok. But if I add a Project object inside a Product I have
the following error message

System.InvalidOperationException: There was an error
generating the XML document. --->
System.InvalidOperationException: A circular reference was detected
while serializing an object of type
ProjectInitialize.Product.

Is there any work around I can do to solve the problem? :?

Thanks in advance for your tips

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vera | last post by:
I have two assemblies that each consist of several classes. Each object instantiated from those classes can have one or more child- and/or parentobjects that are also instantiated from those...
11
by: Steve Jorgensen | last post by:
I just came up with a really tidy little solution to the VB/VBA circular reference issue. It only works with Access 2000 or newer, but that's about the only down-side. The issue... You need an...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
4
by: Henke | last post by:
I have this scenario. public class A { public int numbers; public class A() { }
12
by: Frank Rizzo | last post by:
I have a circular reference between 2 classes in the same project (i.e. each class refers to the other). The app runs fine and I am seeing no issues, which kind of surprised me. Are there any...
6
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson)...
3
by: Solution Seeker | last post by:
Hi All, I am here with a Query and need a Solution for it. The Query is as Follows, We have 3 Projects in a Solution - Say UI, CMN and PRD First One Deals with UI Forms Second One Deals...
2
by: Jeremy Kitchen | last post by:
I have inherited a project and I am trying to figure out why the failing units tests that exist fail. I a, getting the following error when I attempt serialization. Any advice on what I should...
3
by: =?Utf-8?B?UGF1bCBIYWxl?= | last post by:
Moving all User Controls to a single directory has solved my problem - Thanks Eliyahu. That said, I still got one Circular ref error yesterday, rebuilt again and the build was fine? Far far...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.