Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 337393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:19:55+00:00 2026-05-12T10:19:55+00:00

I’m a C# newbie, so please bear with me. OK, so I have two

  • 0

I’m a C# newbie, so please bear with me.

OK, so I have two classes in different assemblies that need to reference each other:

namespace AssemblyA
{
  class A 
  {
    private B MyB { get; set; }
  }
}

namespace AssemblyB
{
  class B
  {
    private A MyA { get; set; }
  }
}

I understand that circular references aren’t allowed, so I’m using an interface:

namespace AssemblyA
{
  public interface IB
  {
     // whatever 'A' needs of 'B'
  }

  class A 
  {
    private IB MyB { get; set; }
  }
}

namespace AssemblyB
{
  class B : AssemblyA.IB
  {
    private A MyA { get; set; }
  }
}

This works, but it has the disadvantage that it exposes IB to the rest of the world. What I would like to do instead is to make IB internal. But then B cannot derive from it.

In C++, I’d make B a friend and be done. I understand that C# doesn’t have friends (pun not intended, but noted), so I have to make do without. I’ve read that there is an attribute for that, but this will make the whole of assembly A accessible to the whole of assembly B, which I don’t like. Is there a way to avoid that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:19:55+00:00Added an answer on May 12, 2026 at 10:19 am

    It seems that the big issue here is letting assembly B see one specific member of assembly A.

    This negates, according to the comments reiterating part of the original question, the feasibility of using the well-documented InternalsVisibleTo attribute.

    Or does it?

    Have you considered making a new assembly, C, with the IB interface marked internal and its own InternalsVisibleTo attributes out to A and B?

    This at least exposes IB in a controlled fashion, without exposing all of A to B. I’m not a huge fan of the solution (I would personally just go ahead and use InternalsVisibleTo on A as has been suggested, then document the rest of my internals to keep others in line), but I understand where you’re coming from — and this at least solves the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.