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

Circular dependency flagged at compile time

_DS
I have two projects that currently need to refer to each other. More
precisely:

Proj A:
Class 1 refers to Proj B Class 1

Proj B:
Class 1
Class 2 refers to Proj A Class 1

Visual studio, for good reason, doesn't like that.

Obviously I could split Proj B into two separate projects. There are
no crossrefs between the two classes in Proj B, but the classes do
really belong together.

I've read about application of Interfaces to break the full circle but
I don't see any elegant way of applying that in this case.

Or I can kludge it and remove Proj B from Proj A's solution, then
replace 'Project' references with hard refs to DLLs. That would seem
to compromise build integrity (and would have to be changed for
release build).

Any alternatives?

Jan 13 '06 #1
6 1495
_DS,

I would say a bit of refactoring is due here. I would combine the class
from Proj A with Proj B. They can still have separate namespaces. Either
that, or create project C, which Project A and B both reference.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"_DS" <_D*@noemail.com> wrote in message
news:4s********************************@4ax.com...
I have two projects that currently need to refer to each other. More
precisely:

Proj A:
Class 1 refers to Proj B Class 1

Proj B:
Class 1
Class 2 refers to Proj A Class 1

Visual studio, for good reason, doesn't like that.

Obviously I could split Proj B into two separate projects. There are
no crossrefs between the two classes in Proj B, but the classes do
really belong together.

I've read about application of Interfaces to break the full circle but
I don't see any elegant way of applying that in this case.

Or I can kludge it and remove Proj B from Proj A's solution, then
replace 'Project' references with hard refs to DLLs. That would seem
to compromise build integrity (and would have to be changed for
release build).

Any alternatives?

Jan 13 '06 #2
Could you give them more descriptive names than A and B? If I knew a
little more about the domain in which you're working, and what the
classes / assemblies do, I could probably indicate how to solve your
problem using interfaces.

Jan 13 '06 #3
_DS
On 13 Jan 2006 12:40:47 -0800, "Bruce Wood" <br*******@canada.com>
wrote:
Could you give them more descriptive names than A and B? If I knew a
little more about the domain in which you're working, and what the
classes / assemblies do, I could probably indicate how to solve your
problem using interfaces.


To rephrase:

I have two projects that currently need to refer to each other. More
precisely:

Proj A 'ComplexDataType':
ComplexDataTypeCollection - Contains TypeX from proj B Class

Proj B: 'TypeXProcessor':
TypeXFormatConverter
TypeXWriter - Gets data from collection in Proj A

Proj A simply defines a complex data type and collections of that data
type. The data type includes a component of 'TypeX' so the
ComponentBuilder relies on the converter class in Proj B.

Proj B deals only with TypeX (a specific string format). It has a
class for converting to TypeX format, and a class for writing it to a
(specifically formatted) file.

As the ComplexDataType collection is built, it refers to
TypeXFormatConverter to create one of its fields. That's not the
problem. The problem arises because the ProjB's TypeX-derived file
writer needs to take the ComplexDataTypeCollection as an argument.

So Proj A needs to refer to the converter in Proj B.

Proj B needs the data type from Proj A.

The collection in Project A is used for lots of purposes, but happens
to encompass a TypeX field, among other things.

The functions in Project B all relate only to TypeX, so I'd like to
keep them together in one lib.

Aren't you sorry you asked? <g>

Jan 14 '06 #4
SP

"_DS" <_D*@noemail.com> wrote in message
news:cl********************************@4ax.com...
On 13 Jan 2006 12:40:47 -0800, "Bruce Wood" <br*******@canada.com>
wrote:
Could you give them more descriptive names than A and B? If I knew a
little more about the domain in which you're working, and what the
classes / assemblies do, I could probably indicate how to solve your
problem using interfaces.


To rephrase:

I have two projects that currently need to refer to each other. More
precisely:

Proj A 'ComplexDataType':
ComplexDataTypeCollection - Contains TypeX from proj B Class

Proj B: 'TypeXProcessor':
TypeXFormatConverter
TypeXWriter - Gets data from collection in Proj A

Proj A simply defines a complex data type and collections of that data
type. The data type includes a component of 'TypeX' so the
ComponentBuilder relies on the converter class in Proj B.

Proj B deals only with TypeX (a specific string format). It has a
class for converting to TypeX format, and a class for writing it to a
(specifically formatted) file.

As the ComplexDataType collection is built, it refers to
TypeXFormatConverter to create one of its fields. That's not the
problem. The problem arises because the ProjB's TypeX-derived file
writer needs to take the ComplexDataTypeCollection as an argument.

So Proj A needs to refer to the converter in Proj B.

Proj B needs the data type from Proj A.

The collection in Project A is used for lots of purposes, but happens
to encompass a TypeX field, among other things.

The functions in Project B all relate only to TypeX, so I'd like to
keep them together in one lib.


Pass a list (array / array list...) of TypeX to ProjectB from the
ComplexDataTypeCollection. You have already stated that "ProjectB deals only
with TypeX" so there is no need for it to know anything about
ComplexDataTypeCollection so all you want is a simple list of TypeX's to
allow ProjectB to do it's stuff on the TypeX's.

SP
Jan 14 '06 #5
_DS wrote:
I have two projects that currently need to refer to each other. More
precisely: <snip> Any alternatives?


You could always combine them into a single project/assembly...

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Jan 14 '06 #6
I have two projects that currently need to refer to each other. More
precisely:

Proj A:
Class 1 refers to Proj B Class 1

Proj B:
Class 1
Class 2 refers to Proj A Class 1

Visual studio, for good reason, doesn't like that.

Obviously I could split Proj B into two separate projects. There are
no crossrefs between the two classes in Proj B, but the classes do
really belong together.

I've read about application of Interfaces to break the full circle but
I don't see any elegant way of applying that in this case.

Or I can kludge it and remove Proj B from Proj A's solution, then
replace 'Project' references with hard refs to DLLs. That would seem
to compromise build integrity (and would have to be changed for
release build).

Any alternatives?
The problem is not the mutual reference -- it's the VS project system.
An easy fix is to NOT add the refererences as PROJECT references.
Add them simply as files (using the Browse tab in the Add Reference dialog box).
You will lose the automatic dependency checking between the projects (the depended-upon project won't be automatically rebuilt). But it's a very minor inconvenience to solve an nasty problem.
I have tried this and it works.
May 10 '06 #7

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

Similar topics

4
by: Evelyne | last post by:
On a server W2K, IIS5, I have many messages from ASP : cirdular dependency between types/modules. Which can be the origin of the problem? Example : Event Type: Warning Event Source: Active...
0
by: David Sandor | last post by:
Has anyone come up with a solution to curcular dependency issues? For those who might not know this is what I am talking about: Class A compiles to assembly A Next, you build Class B that...
1
by: Henry Miller | last post by:
I have the following code (much simplified for this post). Note that SessionKey uses DataAccess, and DataAccess requires SessionKey in it's constructor. Public Class SessionKey Public...
6
by: Markus Dehmann | last post by:
I have a circular dependency between two classes. The FAQ hint about a forward declaration does not help in my case ( How can I create two classes that both know about each other?) Error:...
2
by: ernesto basc?n pantoja | last post by:
Hi everybody: I'm implementing a general C++ framework and I have a basic question about circular dependencies: I am creating a base class Object, my Object class has a method defined as:...
4
by: ro86 | last post by:
Hello everyone! I am a newbie to C++ (~1 Week experience) and I have a few months of experience with object-oriented languages (Objective-C). I am currently working just for fun on a particle...
4
by: Henke | last post by:
I have this scenario. public class A { public int numbers; public class A() { }
2
by: Mike | last post by:
I ran into a problem with circular dependencies. My code looks somthing like: using B namespace A { class formA { void foo() {
7
by: barias | last post by:
Although circular dependencies are something developers should normally avoid, unfortunately they are very easy to create accidentally between classes in a VS project (i.e. circular compile-time...
3
by: donnyma | last post by:
I have a problem that looks like it has not been discussed before in these groups. I have a simple SQLAgent job that runs sp_who (could be anything, but let's just say sp_who for this example). ...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...

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.