Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create list of tuples in assemblies marked as partial trust #7618

Closed
jbogard opened this issue Mar 11, 2017 · 3 comments
Closed

Cannot create list of tuples in assemblies marked as partial trust #7618

jbogard opened this issue Mar 11, 2017 · 3 comments
Assignees

Comments

@jbogard
Copy link
Contributor

jbogard commented Mar 11, 2017

In a .NET 4.5.2 application (console in this case), trying to create a list of tuples results in a method access exception, if the assembly is marked for allowing partial trusted callers:

using System;
using System.Collections.Generic;
using System.Security;

[assembly: AllowPartiallyTrustedCallers]

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = (i: 5, j: 6);

            var foo = new List<(int i, int j)>
            {
                t,
                (i: 7, j: 8)
            };
            Console.WriteLine(foo[0].i);
        }
    }
}

Exception returned:

Unhandled Exception: System.MethodAccessException: Attempt by method 'ConsoleApp2.Program.Main(System.String[])' to access method 'System.Collections.Generic.List`1<System.ValueTuple`2<ConsoleApp2.Foo,System.__Canon>>..ctor()' failed.
   at ConsoleApp2.Program.Main(String[] args) in c:\ConsoleApp2\Program.cs:line 17

I only see this in .NET 4.5.x applications, not in .NET Core.

@stephentoub
Copy link
Member

cc: @jcouv

@jcouv
Copy link
Member

jcouv commented Mar 11, 2017

Thanks @jbogard for reporting this.
I'm able to repro (copied exception details below). I'll investigate.

System.MethodAccessException occurred
  HResult=0x80131510
  Message=Attempt by security transparent method 'ConsoleApp1.Program.Main(System.String[])' to access security critical method 'System.ValueTuple`2<System.Int32,System.Int32>..ctor(Int32, Int32)' failed.

Assembly 'CsPartialTrust, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
  Source=CsPartialTrust
  StackTrace:
   at ConsoleApp1.Program.Main(String[] args) in d:\issues\PartialTrust\CsPartialTrust\Program.cs:line 13

@jcouv jcouv self-assigned this Mar 11, 2017
@gkhanna79
Copy link
Member

Issue moved to dotnet/roslyn dotnet/coreclr#17783 via ZenHub

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants