mob-sakai/OpenSesame

Cannot access non-public members

krafs opened this issue · 6 comments

krafs commented

I can't access any non-public members with OpenSesame.Net.Compilers.Toolset referenced in my project.

Using:
Visual Studio Version 16.10.3

Steps to reproduce:

  1. Create a new .NET472 library project.
  2. Add PackageReference OpenSesame.Net.Compilers.Toolset v.3.7.0.
  3. Add PackageReference Newtonsoft.Json v.13.0.1. (As an example)
  4. Create a new method and add int? privateMaxDepth = Newtonsoft.Json.JsonSerializer._maxDepth;. (_maxDepth is a private field).
  5. Compiler complains about there not being a definition for _maxDepth in JsonSerializer.

I tried the same thing with a .NET Core 3.1 and .NET5.0 library, and put [assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo("<TargetAssemblyName>")] above the namespace in my class, and the compiler cannot find a type called IgnoresAccessChecksToAttribute.

@krafs
_maxDepth is an instance member.
Try the following code:

[assembly: System.Runtime.CompilerServices.IgnoresAccessChecksTo("Newtonsoft.Json")]
namespace PrivateLibrary.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var serializer = new Newtonsoft.Json.JsonSerializer();
            serializer.MaxDepth = 9999;
            System.Console.WriteLine(serializer._maxDepth ?? -1); // '9999'
        }
    }
}
krafs commented

Here's my entire csproj and class.
image

image

It can't find the IgnoreAccessChecksToAttribute.

Am I missing something?

Did you install OpenSesame.Net.Compilers.Toolset without using Nuget Manager, right?

My csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="OpenSesame.Net.Compilers.Toolset" Version="3.7.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Install OpenSesame.Net.Compilers.Toolset via Nuget Manager on Visual Studio or execute following command in the project directory:
dotnet add package OpenSesame.Net.Compilers.Toolset

krafs commented

I tried to compile, and it works. Works without the assembly attribute too.
But it's still red. Is it supposed to be red?
image

Yes.
Only Visual Studio Code with Csc-Manager supports it.

krafs commented

Oh. Well, ok then. Maybe you can add a small comment about that in the readme. I thought it didn't work.

Thanks for the help!