0

How can I access a class which is in another project in C#. Please keep in mind that I cannot add any reference due to creating circular referencing.

Is there any way?

5
  • 5
    "I cannot add any reference due to creating circular referencing" - In short, You don't. You either move the common code to a common project. or return an event, or use an interface to share a contract Commented Feb 19, 2020 at 6:19
  • "Please keep in mind that I cannot add any reference due to creating circular referencing" in this case it is impossible. This should be avoided and it can easily avoided, but to be able to help more I'd need your project structure Commented Feb 19, 2020 at 6:19
  • 1
    Reflection is your friend if your code organisation has screwed so badly. Commented Feb 19, 2020 at 6:20
  • 2
    No to reflection, and that's coming from someone who has "reflection" in his name. Straighten out your references. Refactor your code to have a clear and direct line of references. Commented Feb 19, 2020 at 6:22
  • 1
    Not sure why this is getting upvoted, seems there is a glitch in the matrix Commented Feb 19, 2020 at 6:52

1 Answer 1

1

Not without some refactoring. Reflection could help but you still wouldn't be able to extend from that class or use it in any non runtime way.

I have found that this can happen with minimum refactoring

  1. Identify the shared code
  2. Extract it to a new shared project
  3. Add the new project as a reference to all projects that need it
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.