Home

InternalsVisibleTo on DataContext in signed assembly?

Maybe this is pushing my feature request a bit, but maybe I'm allowed to after it has been at Uservoice for over a year :)

I'm trying to use my internal datacontext with LINQpad. I can expose my internal datacontext using the InternalsVisibleTo attribute. Unfortunately my assembly is signed.

https://linqpad.uservoice.com/forums/18302-linqpad-feature-suggestions/suggestions/4837733-sign-assemblies-to-support-internalsvisibleto-for

I have already tried exposing the internals to the LinqPad signed executable:
[assembly: InternalsVisibleTo("LINQPad, PublicKey=0024000004800000940000000602000000240000525341310004000001000100018e7a717fb9c3d0e478b2f037b06cf257015a857e98f0e2b5b7a7c96e5017ab7721833e9b50fb2992709a29227511c88587ef22763e928bece6d886d174ff8abd8c43a2993e2634e8d57c9e563b2c65c5f9c79f817b177778263416739817e617776f9a0d8809ed287959e5d471ba6b333969cf83f92617086958604d8b4bae")]
This allows the datacontext to be registered in LINQpad, and make the DbSets browsable.

However, when I try to execute a lambda expresson, I get the following error message:
'MyDbContextTypeName' is inaccessible due to its protection level
Inconsistent accessibility: base class 'MyDbContextTypeName' is less accessible than class 'UserQuery'
I cannot find where the class 'UserQuery' resides, and to what other assembly I should expose my internals to. Is 'UserQuery' a LINQpad class, and if so, is it in some other signed assembly? I did not find the class using DotPeek.
The only reference I see is at : QueryCompiler.ShouldUserQueryBeInternal(...)

Any pointers?

Comments

  • UserQuery is your query.

    For example, if you create a C# Program like
        void Main()
        {
    	System.Reflection.Assembly.GetExecutingAssembly().Location.Dump();
    	
    	this.GetType().Dump();	
        }
    
    You will see the location of the dll and you can use DotPeek/Reflector to look inside it.

    Also this.GetType.Dump() should show you that the current class is called UserQuery.
  • You need to make your assembly accessible not to the LINQPad host, but the query assemblies that LINQPad creates:
    
    [assembly: InternalsVisibleTo ("LINQPadQuery")]
    Unfortunately, this won't work if your assembly is signed, because LINQPad does not sign the UserQuery assemblies to maximize compilation performance and to simplify specifying InternalsVisibleTo in the common case of unsigned assemblies. The only workaround at this stage is not to sign your assembly in debug builds (or to make the data contexts public).

Sign In or Register to comment.