473,320 Members | 1,713 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,320 software developers and data experts.

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(ByVal 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 3929
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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********@hotmail.com> wrote in message
news:5c******************************@news.teranew s.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********@hotmail.com> wrote in message
news:5c******************************@news.teranew s.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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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******@hotmail.com> wrote in message
news:70****************************@40tude.net...
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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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
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******@hotmail.com> wrote in message
news:70****************************@40tude.net...
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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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 #11
Erik,

Yes that's another approach.
Haven't tried that one out but I'm sure it will work because it removes the
need for project 2 being dependent on project 1.

Thanks
Dave
"Erik Frey" <er*******@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:5c******************************@news.teranew s.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 #12
Erik,

Yes that's another approach.
Haven't tried that one out but I'm sure it will work because it removes the
need for project 2 being dependent on project 1.

Thanks
Dave
"Erik Frey" <er*******@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:5c******************************@news.teranew s.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 #13
Hi,
It's something along the lines of:

Project 1:
Public Class MyObject
blah
End Class

Public Class MyHandler
Public Event RequestData(dataObj as MyObject

Public Sub Doeventplease()
Dim obj As New MyObject(blah)
RaiseEvent RequestData(obj)
'obj may have been modified by the event handler...
End Sub
End Class
In you main Project2 app you can reference Project1.
Then, you can call your Project1 function, and if it needs to obtain more
info from Project1 it can do so via the event.

E.g.
Project2:

Private WithEvents P1object As New Project1.MyHandler

Public Sub Main()
P1object.DoSomething
'If the P1object requires some data from you, it may now generate an event
'that will be caught by the event handler below:

End Sub

Private Sub RequestDataHandler(ByValue myob As Project1.MyObject) _
Handles P1object.RequestData
'Do something with myob, or alter values in it etc.
End Sub
A typical place I use this is if I'm writing a custom control.
The control may require data from the form on which it's placed, and I
can't have a direct link from the control to a custom method on my form, so
I have events such as "RequestLanguageEditor" or "RequestValidation" that
pass enough information to allow the underlying form to perform a
calculation, and I might have a 'ByRef Cancel As Boolean' to allow me to
easily return a status to the control itself.

I'm afraid this is mainly a mindset problem rather than technical, but
hopefully this gives an idea. If you give a more concrete problem
description then a few people may give alternative architectures.

Cheers,
Jason

p.s. The VB.Net code above is typed from memory, so the syntax may be dodgy
:)
On Wed, 07 Apr 2004 22:56:05 GMT, Dave S wrote:
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******@hotmail.com> wrote in message
news:70****************************@40tude.net...
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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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 #14
Hi,
It's something along the lines of:

Project 1:
Public Class MyObject
blah
End Class

Public Class MyHandler
Public Event RequestData(dataObj as MyObject

Public Sub Doeventplease()
Dim obj As New MyObject(blah)
RaiseEvent RequestData(obj)
'obj may have been modified by the event handler...
End Sub
End Class
In you main Project2 app you can reference Project1.
Then, you can call your Project1 function, and if it needs to obtain more
info from Project1 it can do so via the event.

E.g.
Project2:

Private WithEvents P1object As New Project1.MyHandler

Public Sub Main()
P1object.DoSomething
'If the P1object requires some data from you, it may now generate an event
'that will be caught by the event handler below:

End Sub

Private Sub RequestDataHandler(ByValue myob As Project1.MyObject) _
Handles P1object.RequestData
'Do something with myob, or alter values in it etc.
End Sub
A typical place I use this is if I'm writing a custom control.
The control may require data from the form on which it's placed, and I
can't have a direct link from the control to a custom method on my form, so
I have events such as "RequestLanguageEditor" or "RequestValidation" that
pass enough information to allow the underlying form to perform a
calculation, and I might have a 'ByRef Cancel As Boolean' to allow me to
easily return a status to the control itself.

I'm afraid this is mainly a mindset problem rather than technical, but
hopefully this gives an idea. If you give a more concrete problem
description then a few people may give alternative architectures.

Cheers,
Jason

p.s. The VB.Net code above is typed from memory, so the syntax may be dodgy
:)
On Wed, 07 Apr 2004 22:56:05 GMT, Dave S wrote:
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******@hotmail.com> wrote in message
news:70****************************@40tude.net...
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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Dave S" <da********@hotmail.com> wrote in message
news:ac******************************@news.teranew s.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 #15
Jason

That's great, thanks for your help.
I'll give it a go

Dave
"Jason Sobell" <iG******@hotmail.com> wrote in message
news:1a*******************************@40tude.net. ..
Hi,
It's something along the lines of:

Project 1:
Public Class MyObject
blah
End Class

Public Class MyHandler
Public Event RequestData(dataObj as MyObject

Public Sub Doeventplease()
Dim obj As New MyObject(blah)
RaiseEvent RequestData(obj)
'obj may have been modified by the event handler...
End Sub
End Class
In you main Project2 app you can reference Project1.
Then, you can call your Project1 function, and if it needs to obtain more
info from Project1 it can do so via the event.

E.g.
Project2:

Private WithEvents P1object As New Project1.MyHandler

Public Sub Main()
P1object.DoSomething
'If the P1object requires some data from you, it may now generate an event 'that will be caught by the event handler below:

End Sub

Private Sub RequestDataHandler(ByValue myob As Project1.MyObject) _
Handles P1object.RequestData
'Do something with myob, or alter values in it etc.
End Sub
A typical place I use this is if I'm writing a custom control.
The control may require data from the form on which it's placed, and I
can't have a direct link from the control to a custom method on my form, so I have events such as "RequestLanguageEditor" or "RequestValidation" that
pass enough information to allow the underlying form to perform a
calculation, and I might have a 'ByRef Cancel As Boolean' to allow me to
easily return a status to the control itself.

I'm afraid this is mainly a mindset problem rather than technical, but
hopefully this gives an idea. If you give a more concrete problem
description then a few people may give alternative architectures.

Cheers,
Jason

p.s. The VB.Net code above is typed from memory, so the syntax may be dodgy :)
On Wed, 07 Apr 2004 22:56:05 GMT, Dave S wrote:
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******@hotmail.com> wrote in message
news:70****************************@40tude.net...
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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
> "Dave S" <da********@hotmail.com> wrote in message
> news:ac******************************@news.teranew s.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 #16
Jason

That's great, thanks for your help.
I'll give it a go

Dave
"Jason Sobell" <iG******@hotmail.com> wrote in message
news:1a*******************************@40tude.net. ..
Hi,
It's something along the lines of:

Project 1:
Public Class MyObject
blah
End Class

Public Class MyHandler
Public Event RequestData(dataObj as MyObject

Public Sub Doeventplease()
Dim obj As New MyObject(blah)
RaiseEvent RequestData(obj)
'obj may have been modified by the event handler...
End Sub
End Class
In you main Project2 app you can reference Project1.
Then, you can call your Project1 function, and if it needs to obtain more
info from Project1 it can do so via the event.

E.g.
Project2:

Private WithEvents P1object As New Project1.MyHandler

Public Sub Main()
P1object.DoSomething
'If the P1object requires some data from you, it may now generate an event 'that will be caught by the event handler below:

End Sub

Private Sub RequestDataHandler(ByValue myob As Project1.MyObject) _
Handles P1object.RequestData
'Do something with myob, or alter values in it etc.
End Sub
A typical place I use this is if I'm writing a custom control.
The control may require data from the form on which it's placed, and I
can't have a direct link from the control to a custom method on my form, so I have events such as "RequestLanguageEditor" or "RequestValidation" that
pass enough information to allow the underlying form to perform a
calculation, and I might have a 'ByRef Cancel As Boolean' to allow me to
easily return a status to the control itself.

I'm afraid this is mainly a mindset problem rather than technical, but
hopefully this gives an idea. If you give a more concrete problem
description then a few people may give alternative architectures.

Cheers,
Jason

p.s. The VB.Net code above is typed from memory, so the syntax may be dodgy :)
On Wed, 07 Apr 2004 22:56:05 GMT, Dave S wrote:
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******@hotmail.com> wrote in message
news:70****************************@40tude.net...
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*******@hotmail.com> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
> "Dave S" <da********@hotmail.com> wrote in message
> news:ac******************************@news.teranew s.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 #17

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

Similar topics

16
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...
2
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...
8
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...
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...
5
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? ...
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)...
2
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...
5
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...
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...
2
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.