Cannot access non-public members
krafs opened this issue · 6 comments
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:
- Create a new .NET472 library project.
- Add PackageReference OpenSesame.Net.Compilers.Toolset v.3.7.0.
- Add PackageReference Newtonsoft.Json v.13.0.1. (As an example)
- Create a new method and add
int? privateMaxDepth = Newtonsoft.Json.JsonSerializer._maxDepth;
. (_maxDepth is a private field). - 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'
}
}
}
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
Yes.
Only Visual Studio Code with Csc-Manager supports it.
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!