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 3946270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:06:48+00:00 2026-05-20T01:06:48+00:00

I have a project that uses dynamic code generation to create a proxy class.

  • 0

I have a project that uses dynamic code generation to create a proxy class. This proxy class makes use of internal classes of the project (so that implementation details are not exposed) and so I use InternalsVisibleTo with the name of my dynamically generated assembly. This worked fine until recently, when my client imposed the requirement that all shipped assemblies be strong-named.

The issue arises because, in order to use InternalsVisibleTo with a strong-named assembly, the assemblies it references must also be strong-named and you must provide a public key. Where I’m getting stuck is how to provide a strong name for the dynamically generated assembly. Here is what I’ve done so far:

  1. I’ve created a new key pair for dynamic assemblies, so that the .snk can be shipped with the product (obviously we don’t want to ship the .snk being used for signing the rest of the project assemblies.)
  2. I’ve extracted the PublicKey and updated my InternalsVisibleTo to use the new dynamic PublicKey for dynamically referenced assemblies.
  3. I’ve attempted to sign the dynamically-generated assemblies like this:

        var name = new AssemblyName("ProxyBuilderAssembly");
        var attributes = new CustomAttributeBuilder[1];
        attributes[0] =
            new CustomAttributeBuilder(typeof(AssemblyKeyFileAttribute).GetConstructor(new[] {typeof(string)}),
                                       new object[] {"Dynamic.snk"});
        _assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave, attributes);
        _module = _assembly.DefineDynamicModule("ProxyBuilderAssembly", "ProxyBuilderAssembly.dll");
    

Unfortunately this is not working and I have been having a very hard time finding any documentation on how this should work. Does anybody know how to sign a dynamically generated assembly so that it can be given access via InternalsVisibleTo? I can just make the necessary classes public, but that ends up leaking implementation details that would be better left encapsulated.

  • 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-20T01:06:49+00:00Added an answer on May 20, 2026 at 1:06 am

    There is a “How to: Use Full Signing to Give a Dynamic Assembly a Strong Name” article on MSDN that shows how to sign assemblies generated with Reflection.Emit.

    StrongNameKeyPair kp;
    // Getting this from a resource would be a good idea.
    using(stream = GetStreamForKeyPair())
    {
        kp = new StrongNameKeyPair(fs);
    }
    AssemblyName an = new AssemblyName();
    an.KeyPair = kp;
    AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that has a dynamic-class system in C++ that has a
I have a project ongoing at the moment that uses dynamic text blocks to
I have an older project that uses the sun.net.ftp.FtpClient class to download a file
I have a project that uses the maven-assembly-plugin to create source and binary tar
I have a project that uses Java and Groovy intermixed. This works very well.
I have Midas project that uses a TDataSetProvider in one of RemoteDataModules in the
I have inherited a project that uses LLBLGen Pro for the DB layer. The
I have inherited a project that uses the following pattern for passing parameters from
We have an old project that requires occasional maintenance that uses VS2003 and Dot
I have a .net interop project that uses an app.config file. When I am

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.