473,583 Members | 3,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how .net references circular references

Hello

If I define two classes in the same cs file. And in each class, I define the
object of other class as a member.

Can anyone explain me how .NET or its compiler will resolve this kind of
reference since one class would not be compiled unless other is compiled.

This is kind of a deadlock. Isnt it ?
--
Madhur

http://madhurahuja.blogspot.com
Jan 12 '08 #1
5 3792
This is kind of a deadlock. Isnt it ?

No - that's fine, as long as they are in the same assembly - the
compiler /broadly/ uses a place-holder in the interim. For example,
all objects have "System.Str ing ToString()" and "System.Int 23
GetHashCode()"; which do you build first? System.String, or
System.Int32? or System.Object (since both inherit from object (give-
or-take)) or all at once?

Circular references between *assemblies* are tougher. You can do it at
the command line, but I don't recommend it...

Marc
Jan 12 '08 #2
Madhur wrote:
If I define two classes in the same cs file. And in each class, I define the
object of other class as a member.

Can anyone explain me how .NET or its compiler will resolve this kind of
reference since one class would not be compiled unless other is compiled.

This is kind of a deadlock. Isnt it ?
They are compiled together. Logically it is not a problem.

Compiler implementation wise they must either do multiple
pass or delay check until everything is processed.

Arne

Jan 12 '08 #3
One caveat - you can't have 2 structs that contain each-other as
fields - simply because it makes no sense - how big would the object
be? Not an issue with classes, since there is just a /reference/ to
the other .

Marc
Jan 12 '08 #4
Circular references between assemblies are not possible in .NET. That
doesn't mean you can't access the types between two assemblies, you just
have to abstract out the types to another shared assembly and have an
external assembly be the factory for the two abstractions.

But at that point, it's not a circular reference anymore.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marc Gravell" <ma**********@g mail.comwrote in message
news:27******** *************** ***********@j78 g2000hsd.google groups.com...
>This is kind of a deadlock. Isnt it ?

No - that's fine, as long as they are in the same assembly - the
compiler /broadly/ uses a place-holder in the interim. For example,
all objects have "System.Str ing ToString()" and "System.Int 23
GetHashCode()"; which do you build first? System.String, or
System.Int32? or System.Object (since both inherit from object (give-
or-take)) or all at once?

Circular references between *assemblies* are tougher. You can do it at
the command line, but I don't recommend it...

Marc
Jan 12 '08 #5
* * Circular references between assemblies are not possible in .NET.
It isn't supported by the IDE, but it is (I believe) possible.
Meaning: I've just done it...

The painful thing is that you must (possibly with #if etc) find a way
of building the two assemblies upwards incrementally such that at each
point at least one of them builds - i.e. I compiled c1.dll with:

using System;
public class A {
}

Then I compiled c2.dll (referencing c1.dll) with:
using System;
public class B {
A test;
}

Then I re-compiled c1.dll (referencing c2.dll) with:
using System;
public class A {
B test;
}

Et voila; circular reference. Very painful, I'll grant - but not
impossible.
Actually, I believe that if you ask the reflection API, there is an
implied circular reference between mscorlib.dll and System.dll - but
reflector doesn't show this, so maybe this one is just the way that
reflection displays it... I believe I found this the hard way when
walking the reference tree (to force-load all libs) - it blew the
stack because of the loop.

Marc
Jan 12 '08 #6

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

Similar topics

4
5544
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects: http://groups.google.com/groups?selm=bcq6fn%24g53%241%248300dec7%40news.demon.co.uk This message summarizes some testing I've done and their...
16
2824
by: Kiuhnm | last post by:
Is there an elegant way to deal with semi-circular definitions? Semi-circular definition: A { B }; B { *A }; Circular reference: A { *B }; B { *A }; The problems arise when there are more semi-circular definitions and
2
7969
by: Earth Worm Jim | last post by:
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular references when the circular reference is contained with in a collection class, specifically I am using a custom ArrayList object. I keep getting a...
8
3495
by: Eric Eggermann | last post by:
I'm having a problem with really large file sizes when serializing the classes that describe my little document. There are some circular references which result in the same object getting written to disk multiple times. Now I'm using just basic serialization as described in MSDN. Clearly, I need to stop serializing these parent references, but...
12
7050
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 issues that I am not seeing (performance wise or garbage collection wise) with circular references? Thanks.
5
6840
by: Gos | last post by:
Hi, It is known that .NET does not allow us to add circular references. Is there a way to workaround this problem by late-binding the objects at run time? Will this create any other problems? One solution to the problem is to re-architect the solution. But, I dont want to do this as there are many modules in the project which are already...
6
5065
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) in search (no record) mode. When the search is executed, frmperson calls frmsearchresult (dim f as new frmsearchresult) which is a listing of...
2
2815
by: Lapu-Lapu | last post by:
I have authored a web service using ASP 2.0. The web services return objects that use generics and that also contain circular references. Programmatically, everything works well, as long as you use the web service proxy client generated by visual studio. However, the default test harness provided by the .asmx file errors out because it seems...
3
2910
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 better than the amount of errors I was originally getting on builds before I consilidated by UC's though :-) "Paul Hale" wrote:
0
7896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7827
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5375
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3820
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.