{"action":"created","issue":{"url":"https://api.github.com/repos/castleproject/Core/issues/402","repository_url":"https://api.github.com/repos/castleproject/Core","labels_url":"https://api.github.com/repos/castleproject/Core/issues/402/labels{/name}","comments_url":"https://api.github.com/repos/castleproject/Core/issues/402/comments","events_url":"https://api.github.com/repos/castleproject/Core/issues/402/events","html_url":"https://github.com/castleproject/Core/issues/402","id":343010467,"node_id":"MDU6SXNzdWUzNDMwMTA0Njc=","number":402,"title":"Should DynamicProxy emit IgnoresAccessChecksToAttribute?","user":{"login":"stakx","id":104481,"node_id":"MDQ6VXNlcjEwNDQ4MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/104481?v=4","gravatar_id":"","url":"https://api.github.com/users/stakx","html_url":"https://github.com/stakx","followers_url":"https://api.github.com/users/stakx/followers","following_url":"https://api.github.com/users/stakx/following{/other_user}","gists_url":"https://api.github.com/users/stakx/gists{/gist_id}","starred_url":"https://api.github.com/users/stakx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stakx/subscriptions","organizations_url":"https://api.github.com/users/stakx/orgs","repos_url":"https://api.github.com/users/stakx/repos","events_url":"https://api.github.com/users/stakx/events{/privacy}","received_events_url":"https://api.github.com/users/stakx/received_events","type":"User","site_admin":false},"labels":[{"id":90472406,"node_id":"MDU6TGFiZWw5MDQ3MjQwNg==","url":"https://api.github.com/repos/castleproject/Core/labels/discussion","name":"discussion","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-20T08:01:48Z","updated_at":"2018-07-21T13:39:55Z","closed_at":null,"author_association":"MEMBER","body":"Yesterday, [I was made aware](https://github.com/dotnet/corefx/issues/29365#issuecomment-406348792) of the small wonder that is `[assembly: IgnoresAccessChecksTo(\"AssemblyName\")]`. This attribute might be useful for DynamicProxy.\r\n\r\n### What is it?\r\n\r\nPut simply, this attribute type is the reverse of `InternalsVisibleToAttribute`. It can be applied in a dynamic assembly to get access to the `internal` members of another assembly. It is supported by the .NET Core 1.0+ and the .NET Framework 4.6+ runtimes. The BCL does not pre-define that attribute type, one has to define it e.g. inside the dynamic assembly as follows:\r\n\r\n```csharp\r\nnamespace System.Runtime.CompilerServices\r\n{\r\n    [AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = true)]\r\n    public class IgnoresAccessChecksToAttribute : Attribute\r\n    {\r\n        private string _assemblyName;\r\n        public IgnoresAccessChecksToAttribute(string assemblyName)\r\n        {\r\n            _assemblyName = assemblyName;\r\n        }\r\n        public string AssemblyName \r\n        { \r\n            get { return _assemblyName; } \r\n        } \r\n    }\r\n}\r\n```\r\n\r\nThere isn't a lot of information about this attribute (it appears to be undocumented, unfortunately but perhaps for understandable reasons), here's a few links if you want to learn more:\r\n\r\n* Description of that attribute type in [aelij/IgnoresAccessChecksToGenerator's README](https://github.com/aelij/IgnoresAccessChecksToGenerator/blob/master/README.md)\r\n\r\n* @AArnott posted information about which runtimes support the attribute in https://github.com/Microsoft/vs-mef/pull/10#discussion_r117817248.\r\n\r\n* .NET Core's `DispatchProxyGenerator` already uses it, see e.g. its [`EnsureTypeIsVisible` method](https://github.com/dotnet/corefx/blob/4d915fd1c7bd7242a3f549603d402a27b3b5ab79/src/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs#L243-L258). (DynamicProxy could do something similar.)\r\n\r\n* A [small demo program (Gist)](https://gist.github.com/stakx/994331287188ffd6459f6c988fc72506) by yours truly.\r\n\r\n### What would this be good for?\r\n\r\nIf DynamicProxy automatically emitted that attribute type definition in its dynamic modules, and (recursively) applied it for the assemblies containing proxied types, downstream users running on recent framework versions would no longer need the `[assembly: InternalsVisibleTo(\"DynamicProxyGenAssembly2\")]` bit.\r\n\r\nFor people running on an older platform (.NET Framework <4.6), there would be no change from DynamicProxy's current behavior.\r\n\r\n### Is it a good idea to always have access to `internal` members?\r\n\r\nThat's the one thing I am not sure about. Are there cases where users do *not* want DynamicProxy to see / intercept / be able to proxy internal types or type members? Would there have to be some kind of configuration switch that allows people to opt in/out of DynamicProxy automatically emitting `[IgnoresAccessChecksTo]`?\r\n\r\n/cc @blairconrad, @dtchepak, @thomaslevesque, @zvirja"},"comment":{"url":"https://api.github.com/repos/castleproject/Core/issues/comments/406797403","html_url":"https://github.com/castleproject/Core/issues/402#issuecomment-406797403","issue_url":"https://api.github.com/repos/castleproject/Core/issues/402","id":406797403,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjc5NzQwMw==","user":{"login":"AArnott","id":3548,"node_id":"MDQ6VXNlcjM1NDg=","avatar_url":"https://avatars2.githubusercontent.com/u/3548?v=4","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"created_at":"2018-07-21T13:39:55Z","updated_at":"2018-07-21T13:39:55Z","author_association":"NONE","body":"There is indeed a requirement. Once the CLR has loaded any type from the assembly, the magic attribute can't be added later or it will have no effect. So all the attributes have to be added at once up front or else you have to create a new dynamic assembly."}}
{"actor":{"display_login":"AArnott"}}