0

I have two C# projects, LibraryA and LibraryB, each producing a separate DLL.

LibraryA makes use of the classes in LibraryB.
LibraryB needs to make a TypeForwardedTo reference to class in LibraryA.
(See this question for background.)

Normally, I would resolve either issue by adding a project reference, but I can't do both because VS doesn't allow circular references.

The only reason I need the B-to-A reference is for the TypeForwardedTo link. I've tried using Type.GetType(string) but the attribute doesn't allow that type of function call.

Is there a way I can add a TypeForwardedToAttribute without using a project reference?

billpg
  • 3,195
  • 3
  • 30
  • 57
  • So which assembly is original one (before the split)? LibraryA? – Evk Dec 05 '17 at 13:15
  • @Evk - In this example, B. (So code referencing classes that used to be in B are forwarded to A.) – billpg Dec 05 '17 at 13:19
  • Note that the link to my other question is only there to answer why I'd ever want to do such a thing. I *could* split the original library into two new projects, leaving the original one only as a set of type-forwards, but I'm hoping to avoid that scenario. – billpg Dec 05 '17 at 13:21
  • That's quite strange, cannot you make LibraryB reference LibraryA then and not visa versa? – Evk Dec 05 '17 at 13:22
  • @Evk - That's another possibility, but undesirable for many reasons. If there is no answer to my question, I'll have to fall-back to one or the other alternatives and put up with cost of that approach. – billpg Dec 05 '17 at 13:25
  • I don't think there is any non-hacky way to do this (or even any way at all). You can only use `typeof()` in that attribute, and for that you need to introduce circular dependency. So I'd suggest to use "normal" way and make Library B reference LibraryA. – Evk Dec 05 '17 at 13:42
  • You *can* create circular references in [VS](https://stackoverflow.com/a/44431210/15498). – Damien_The_Unbeliever Dec 05 '17 at 14:07
  • @Damien_The_Unbeliever but is it a good idea in this case? – Evk Dec 05 '17 at 14:19
  • @Evk - if you're in a corner where restructuring isn't possible (as indicated in the first para of my answer) then yes, I'd do this. If there are other options on the table, I'd definitely look at those first. I just get irked at the assertion that circular references aren't possible - especially since there are circular references within framework assemblies. – Damien_The_Unbeliever Dec 05 '17 at 18:12

0 Answers0