0

(The context of this question is specific to XNA, but the principle is general.)

I have a Project A with a Game class that extends Microsoft.Xna.Framework.Game. Project A is a class library and outputs a DLL.

I then have a project B that extends the A.Game class and has a reference to A.dll. When I try and compile B, I get this error:

The type 'Microsoft.Xna.Framework.Game' is defined in an assembly that is not referenced. You must add a reference to assembly [...]

I don't understand why this is the case; B only depends on A, which internally depends on Xna. Is it because A.Game is a subclass? Is there a way to remove this dependency requirement?

What I'm aiming for is to make A self-publishing; it outputs only one DLL, and any project references it; whatever it uses internally isn't required by end-users (developers).

I also checked out this question on transitive dependencies, but I don't expose any fields in A.Game yet -- only subclass.

Community
  • 1
  • 1
ashes999
  • 9,925
  • 16
  • 73
  • 124

2 Answers2

2

There's no way to avoid this. You cannot statically link the Xna library into A, so that means that in order for A to run, you need the Xna dll available as well. Note that you can publish A on its own and then tell any users of A that they need the Xna dll as well, but that's about the best you can do.

Image you had A, but no Xna dll. How could you instantiate the Game class? It's a subclass of a Type that is contained in the Xna dll, so that means it's base constructor is also in that dll.

dlev
  • 48,024
  • 5
  • 125
  • 132
  • What about using inheritance by composition and redirecting all the necessary calls? Would that resolve the dependency sufficiently? – ashes999 Jul 05 '11 at 13:42
  • @ashes999 I'm not 100% sure what your suggesting (feel free to edit the question to clarify,) but I think you`re asking "what if I add a member of type Xna.Game to my own Game class?" If so, then you haven't removed the dependency, because to create A, you still need to load the Xna.Game Type whenever you load your custom Type. – dlev Jul 05 '11 at 13:57
  • I think I realize what you're saying. In Java, you "add a reference" by adding a copy of the referenced JAR into your project. In .NET, references don't work like that; that's why you need the DLL. You can build and deploy a DLL without the referenced DLLs. – ashes999 Jul 05 '11 at 17:18
0

You need to add in B a dependency to the XNA Framework as well.

lollancf37
  • 1,105
  • 3
  • 15
  • 27