473,545 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Circular references ?

Anyone know how to get round the problem of circular references in VB.NET
(sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass a
parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it can
call the class in the second project.

This doesn't seem to be allowed in .NET even though Java could easily do
this.

See code below :
(1st project : namespace = MyClass.Test1)

Public Class MyHandler
Public Function DoSomething(ByV al obj As MyObject) As String
Dim a As New [MyClass].Test2.MyAction
Return a.DoMethod(obj)

End Function
End Class

Public Class MyObject
Private a, b As String
Public Property attrib1() As String
Get
Return a
End Get
Set(ByVal Value As String)
a = Value
End Set
End Property
Public Property attrib2() As String
Get
Return b
End Get
Set(ByVal Value As String)
b = Value
End Set
End Property
End Class
(2nd project : namespace = MyClass.Test2)

Imports [MyClass].Test1

Public Class MyAction
Public Function DoMethod(ByVal obj As MyObject) As String
Return obj.attrib1
End Function
End Class

The line highlighted in red above fails because according to .NET it doesn't
know what type the value called 'obj' is when it comes to passing it to the
method in the 2nd project.
The error I get is :

H:\Work\testbed \MyClass.Test1\ MyHandler.vb(4) : Reference required to
assembly 'MyClass.Test1' containing the type 'MyClass.Test1. MyObject'. Add
one to your project.


This seems a really basic piece of functionality and I must be declaring
something incorrectly here

Any ideas ??
Nov 20 '05 #1
16 3961
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in VB.NET
(sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass a parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it can
call the class in the second project.


Typically this is adressed by creating a third project that contains your
business types in it.

Then have your other two projects refer to this new project, to have access
to the common type (so in your case, put MyObject in the third project).

Also, keep in mind that even if you have three projects in a solution, you
still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik
Nov 20 '05 #2
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in VB.NET
(sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass a parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it can
call the class in the second project.


Typically this is adressed by creating a third project that contains your
business types in it.

Then have your other two projects refer to this new project, to have access
to the common type (so in your case, put MyObject in the third project).

Also, keep in mind that even if you have three projects in a solution, you
still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik
Nov 20 '05 #3
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it
with just 2 projects.
I tried moving my object into another project (so it's sort of an interface
project) and then each of the other projects can reference that project
without causing the circular reference problem.
I just thought it was a bit messy when in Java you could easily do this
without a middleman package containing the object you want to pass between
the classes.
At least I know that it wasn't something I'd missed out when declaring the 2
projects initially.
Will have to remember this one in future (I've been struggling with this all
afternoon)

Dave


"Erik Frey" <er*******@hotm ail.com> wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in VB.NET (sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass
a
parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it
can call the class in the second project.


Typically this is adressed by creating a third project that contains your
business types in it.

Then have your other two projects refer to this new project, to have

access to the common type (so in your case, put MyObject in the third project).

Also, keep in mind that even if you have three projects in a solution, you
still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik

Nov 20 '05 #4
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it
with just 2 projects.
I tried moving my object into another project (so it's sort of an interface
project) and then each of the other projects can reference that project
without causing the circular reference problem.
I just thought it was a bit messy when in Java you could easily do this
without a middleman package containing the object you want to pass between
the classes.
At least I know that it wasn't something I'd missed out when declaring the 2
projects initially.
Will have to remember this one in future (I've been struggling with this all
afternoon)

Dave


"Erik Frey" <er*******@hotm ail.com> wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in VB.NET (sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass
a
parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it
can call the class in the second project.


Typically this is adressed by creating a third project that contains your
business types in it.

Then have your other two projects refer to this new project, to have

access to the common type (so in your case, put MyObject in the third project).

Also, keep in mind that even if you have three projects in a solution, you
still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik

Nov 20 '05 #5
"Dave S" <da********@hot mail.com> wrote in message
news:5c******** *************** *******@news.te ranews.com...
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it
with just 2 projects.


If you don't want a third common class, your other option is to move the
MyObject class declaration into the second project that you're trying to
send it to. Then, just reference from your first project (that still
contains MyHandler).

But no - two projects cannot reference eachother.

Erik
Nov 20 '05 #6
"Dave S" <da********@hot mail.com> wrote in message
news:5c******** *************** *******@news.te ranews.com...
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it
with just 2 projects.


If you don't want a third common class, your other option is to move the
MyObject class declaration into the second project that you're trying to
send it to. Then, just reference from your first project (that still
contains MyHandler).

But no - two projects cannot reference eachother.

Erik
Nov 20 '05 #7
You can't directly call from B to A, but you can pass back events with the
package as a parameter, and this is the standard approach to your original
problem.
MyHandler simply raises the event without requiring intimate knowledge
(i.e. dependency) on project B.

This is not a VB.Net specific issue. It applies to all OO languages. Java
uses interfaces or events to avoid the issue, and you can do the same in
VB.

Cheers,
Jason

On Wed, 07 Apr 2004 22:09:35 GMT, Dave S wrote:
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it
with just 2 projects.
I tried moving my object into another project (so it's sort of an interface
project) and then each of the other projects can reference that project
without causing the circular reference problem.
I just thought it was a bit messy when in Java you could easily do this
without a middleman package containing the object you want to pass between
the classes.
At least I know that it wasn't something I'd missed out when declaring the 2
projects initially.
Will have to remember this one in future (I've been struggling with this all
afternoon)

Dave


"Erik Frey" <er*******@hotm ail.com> wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in VB.NET (sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass
a
parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it

can call the class in the second project.


Typically this is adressed by creating a third project that contains your
business types in it.

Then have your other two projects refer to this new project, to have

access
to the common type (so in your case, put MyObject in the third project).

Also, keep in mind that even if you have three projects in a solution, you
still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik

Nov 20 '05 #8
You can't directly call from B to A, but you can pass back events with the
package as a parameter, and this is the standard approach to your original
problem.
MyHandler simply raises the event without requiring intimate knowledge
(i.e. dependency) on project B.

This is not a VB.Net specific issue. It applies to all OO languages. Java
uses interfaces or events to avoid the issue, and you can do the same in
VB.

Cheers,
Jason

On Wed, 07 Apr 2004 22:09:35 GMT, Dave S wrote:
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it
with just 2 projects.
I tried moving my object into another project (so it's sort of an interface
project) and then each of the other projects can reference that project
without causing the circular reference problem.
I just thought it was a bit messy when in Java you could easily do this
without a middleman package containing the object you want to pass between
the classes.
At least I know that it wasn't something I'd missed out when declaring the 2
projects initially.
Will have to remember this one in future (I've been struggling with this all
afternoon)

Dave


"Erik Frey" <er*******@hotm ail.com> wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in VB.NET (sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject.
MyHandler just needs to call another class in a different project and pass
a
parameter of type MyObject to it.
So the class in the different project needs to import the first project
namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it

can call the class in the second project.


Typically this is adressed by creating a third project that contains your
business types in it.

Then have your other two projects refer to this new project, to have

access
to the common type (so in your case, put MyObject in the third project).

Also, keep in mind that even if you have three projects in a solution, you
still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik

Nov 20 '05 #9
Jason,

Not sure I understand that one but I can try and look into raising events.
Any code examples of this anywhere ?

Thanks
Dave

"Jason Sobell" <iG******@hotma il.com> wrote in message
news:70******** *************** *****@40tude.ne t...
You can't directly call from B to A, but you can pass back events with the
package as a parameter, and this is the standard approach to your original
problem.
MyHandler simply raises the event without requiring intimate knowledge
(i.e. dependency) on project B.

This is not a VB.Net specific issue. It applies to all OO languages. Java
uses interfaces or events to avoid the issue, and you can do the same in
VB.

Cheers,
Jason

On Wed, 07 Apr 2004 22:09:35 GMT, Dave S wrote:
Erik,

Thanks for this, I just wanted to confirm that it's not possible to do it with just 2 projects.
I tried moving my object into another project (so it's sort of an interface project) and then each of the other projects can reference that project
without causing the circular reference problem.
I just thought it was a bit messy when in Java you could easily do this
without a middleman package containing the object you want to pass between the classes.
At least I know that it wasn't something I'd missed out when declaring the 2 projects initially.
Will have to remember this one in future (I've been struggling with this all afternoon)

Dave


"Erik Frey" <er*******@hotm ail.com> wrote in message
news:uC******** ******@TK2MSFTN GP10.phx.gbl...
"Dave S" <da********@hot mail.com> wrote in message
news:ac******** *************** *******@news.te ranews.com...
Anyone know how to get round the problem of circular references in

VB.NET
(sorry I'm a .NET newbie).
I create one project which has 2 classes in it, MyHandler and MyObject. MyHandler just needs to call another class in a different project and

pass
a
parameter of type MyObject to it.
So the class in the different project needs to import the first project namespace so it know what MyObject is.
The MyHandler class needs to import the second project namespace so it

can
call the class in the second project.

Typically this is adressed by creating a third project that contains your business types in it.

Then have your other two projects refer to this new project, to have

access
to the common type (so in your case, put MyObject in the third project).
Also, keep in mind that even if you have three projects in a solution, you still have to add the project references manually (right click on
References - > Add References -> Projects tab)

Erik

Nov 20 '05 #10

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

Similar topics

16
2819
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
7959
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
3491
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
7047
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
6838
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
5063
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
2808
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...
5
3788
by: Madhur | last post by:
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 ?
3
2908
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:
2
1849
by: Dansk | last post by:
Hi all, I am currently writing some code that explores assemblies dependencies. I start loading the first assembly with Assmebly.LoadFrom which gives me an Assembly instance. Then, I enumerate the AssemblyNames from the GetReferencedAssemblies() collection.
0
7459
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
7393
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
7803
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
7411
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...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4942
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
3444
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...
0
3439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
695
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.