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

  • SEARCH
  • Home
  • 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 115625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:02:58+00:00 2026-05-11T03:02:58+00:00

InternalsVisibleTo is not working for my managed C++ projects, but it is for my

  • 0

InternalsVisibleTo is not working for my managed C++ projects, but it is for my C# projects. Any help would be appreciated. Here is a simplified layout.

Project A – C#, has an internal property I want to access from B/C.
Project B – Managed C++. References A.
Project C – C#, references A.

All projects are signed with the same key. Looking at the compiled assemblies with ILDASM or Reflector show that they are all signed correctly (when I comment out the internal property usage).

In AssemblyInfo.cs in Project A, I have the following InternalsVisibleTo;

[assembly: InternalsVisibleTo( 'B, ' +    'PublicKey=00240000048000009400000006020000002400005253413100040000010001007' +    '50098646D1C04C2A041FAAF801521A769535DE9A04CD3B4DEDCCBF73D1A6456BF4FE5881451' +    '0E84983C72D0460B8BA85C52A9CACDC4A0785A08E247C335884C2049ECFE6B2C5E20A18FE4B' +    '9BFF009ADA232E980D220B3C9586C9C5EE29C29AEE8853DB7BB90CF5A4C704F5244E1A1085C' +    '4306008535049A0EBB00FE47E78DCB' )]  [assembly: InternalsVisibleTo( 'C, ' +    'PublicKey=00240000048000009400000006020000002400005253413100040000010001007' +    '50098646D1C04C2A041FAAF801521A769535DE9A04CD3B4DEDCCBF73D1A6456BF4FE5881451' +    '0E84983C72D0460B8BA85C52A9CACDC4A0785A08E247C335884C2049ECFE6B2C5E20A18FE4B' +    '9BFF009ADA232E980D220B3C9586C9C5EE29C29AEE8853DB7BB90CF5A4C704F5244E1A1085C' +    '4306008535049A0EBB00FE47E78DCB' )] 

The keys are cut’n’pasted, so I know they are correct.

When I try to compile, A & C compile fine, but project B fails with

Error 1 error C3767: 'A::MyClass::MyProperty::get': candidate function(s) not accessible c:\Users\<snip>\CppClass.cpp 201 B 

The MSDN docs say this works with C++. Is there a bug or something else I need to do?

Is there another way that I can protect a property so that it can only be used by assemblies signed by me? I know I can protect all of my assembly, but can I do it on a granular level like this?

EDIT

Based on comments in MSDN, I changed the attribute to the following, but that still doesn’t work.

[assembly: InternalsVisibleTo( 'B, ' +    'PublicKey=00240000048000009400000006020000002400005253413100040000010001007' +    '50098646D1C04C2A041FAAF801521A769535DE9A04CD3B4DEDCCBF73D1A6456BF4FE5881451' +    '0E84983C72D0460B8BA85C52A9CACDC4A0785A08E247C335884C2049ECFE6B2C5E20A18FE4B' +    '9BFF009ADA232E980D220B3C9586C9C5EE29C29AEE8853DB7BB90CF5A4C704F5244E1A1085C' +    '4306008535049A0EBB00FE47E78DCB' ), InternalsVisibleTo( 'C, ' +    'PublicKey=00240000048000009400000006020000002400005253413100040000010001007' +    '50098646D1C04C2A041FAAF801521A769535DE9A04CD3B4DEDCCBF73D1A6456BF4FE5881451' +    '0E84983C72D0460B8BA85C52A9CACDC4A0785A08E247C335884C2049ECFE6B2C5E20A18FE4B' +    '9BFF009ADA232E980D220B3C9586C9C5EE29C29AEE8853DB7BB90CF5A4C704F5244E1A1085C' +    '4306008535049A0EBB00FE47E78DCB' )] 
  • 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. 2026-05-11T03:02:58+00:00Added an answer on May 11, 2026 at 3:02 am

    I found the answer to this. C++ works differently than the other languages. In addition to the InternalsVisibleTo, you must reference assembly A with the as_friend keyword. Since as_friend is not an option in the Add References dialog, you cannot add a project reference, instead, you need to add a reference in each CPP file that you needs it.

    #using <A.dll> as_friend 

    You then also need to change your assembly search path to include the build directory of project A.

    IMHO, this is broken and typical of managed C++ being a second class language. Without the ability to do project references, you end up referencing the assembly in the build debug or release directory. This breaks dependencies and the only way you can get it to reference the correct DLL when you change your configuration from debug to release is with ugly #IFDEF DEBUG and relative paths for the #using.

    I was also disappointed that this wasn’t mentioned in the InternalsVisibleToAttribute documentation. I needed to dig around in the C++ documentation to find the information.

    Edit: The documentation for InternalsVisisbleTo has since been updated with a link to the Friend Assemblies (C++) document.

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

Sidebar

Related Questions

I am working on two projects: A Business Logic Layer that is a class
I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes
[ Of course, the question is not restricted to a specific friend implementation, feel
My IntelliSense is coming up with a boolean named parameter AllInternalsVisible= in an [assembly:InternalsVisibleTo(AssemblyName)]
In general, I design classes in such a manner as to not require access
In my most recent question: Unit Testing Best Practice? / C# InternalsVisibleTo() attribute for
I have seen many posts and questions about Mocking a private method but still
I would like to make all my public variables variables/methods/classes internal when compiling my
For one of my projects, I need to generate at run time some classes,
Following up on InternalsVisibleTo . I have looked at c# Instantiating Internal class with

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.