-1

So I have many projects in my solution.

  • AppName
  • AppName.Game
  • AppName.Common
  • AppName.Core

I'm currently hosting networking in AppName.Common because AppName requires it to initialize it, and AppName.Game requires certain classes from it to store propertys based on them classes.

The problem comes when I can't reference AppName.Common and AppName.Game both ways. Common requires the Game's classes to know what to call when a new packet comes in, and the game project needs the networking (DotNetty) to use the classes for the propertys.

I can't see why Microsoft have blocked referencing both ways, it seems like such a struggle to get to where you want to be? Is there any workaround for this?

serialize
  • 33
  • 1
  • 2
  • 5
    Sounds like you put some classes in the wrong project. You've got two potential courses of action here: 1. Put the classes in the right project. 2. Start a campaign to make Microsoft redesign .NET more to your liking. Do you have a particular decade when this project needs to be released? – 15ee8f99-57ff-4f92-890c-b56153 Jun 04 '18 at 14:42
  • 1
    If you get to a point where you need to reference "both ways", then you have gone wrong somewhere. Try to think of it as being there to protect you from bad design decisions – musefan Jun 04 '18 at 14:43
  • 1
    This is a problem with your solution design, not Microsoft's framework design – maccettura Jun 04 '18 at 14:45
  • I guess the workaround would be to reference AppName.API instead of AppName.Game in AppName.Common and use an interface of the class in `AppName.Game` instead of the actual class which would require referencing. – serialize Jun 04 '18 at 14:46
  • 1
    'many'? I have over 45 assemblies in a project I'm working on. – Steve Harris Jun 04 '18 at 14:58
  • 4
    "I can't see why Microsoft have blocked referencing both ways" - If Project A references Project B then Project B must be built before Project A to be able to see the things that are being referenced. If you have them reference in both directions then both of them now need to be built first (due to being referenced by the other) which just doesn't work. While there may be ways to get around this when you are designing your language MS took the reasonable approach of just saying no. – Chris Jun 04 '18 at 15:05
  • related: https://stackoverflow.com/questions/1316518/how-did-microsoft-create-assemblies-that-have-circular-references – rene Dec 16 '18 at 19:17

1 Answers1

3

The simplest and best way to do what you need is to move the code that both projects need somewhere that they can both access without having a circular reference. Add another project to your solution:

AppName.Networking

Put all the network stuff that both projects need into that and reference it.

Steve Harris
  • 5,014
  • 1
  • 10
  • 25