Skip to content

System.Security.Policy.Evidence missing in .NET Platform Extensions for .net framework #99447

@viktorgobbi

Description

@viktorgobbi

Description

I'm trying to build a class library that targets .net Standard 2.0 which requires System.Security.Policy.Evidence and some other types from the System.Security.Policy namespace (it only needs to run on windows). I added the System.Security.Permissions nuget package to the class library project and it compiles as expected but when I try to unit test the library in a .net framework project (targeting net47) by passing a System.Security.Policy.Evidence instance to a type from the class library the compilation fails with a:

CS7069 Reference to type 'Evidence' claims it is defined in 'System.Security.AccessControl', but it could not be found

After some investigation I found out that the System.Security.Permissions assembly for .net standard 2.0 forwards the Evidence type from System.Security.AccessControl and the System.Security.AccessControl assembly for .net standard 2.0 contains a stub for the Evidence type but the System.Security.AccessControl assembly for .net framework does not contain a definition or forward the Evidence type.
I also saw that the System.Security.Permissions for .net framework would forward Evidence from mscorlib (what I assume is correct).
Other types like System.Security.Policy.Publisher seem to work with fine.

Reproduction Steps

Create a class library project that targets .net Standard 2.0 and add the System.Security.Permissions nuget package and a class using the System.Security.Policy.Evidence .

using System.Security.Policy;
namespace Lib
{
	public class ClassUsingEvidence
	{
		public ClassUsingEvidence(Evidence evidence)
		{
		}
	}
}

Create a 'NUnit test project' that targets .net framework 4.8 and add a project reference to the .net standard class library project and pass a Evidence instance to the ClassUsingEvidence in a test:

using NUnit.Framework;
using Lib;
using System.Security.Policy;
namespace Lib.Tests
{
	public class Tests
	{
		[Test]
		public void PassEvidence()
		{
			var foo = new ClassUsingEvidence(new Evidence());
		}
	}
}

Leads to compiler error:

CS7069 Reference to type 'Evidence' claims it is defined in 'System.Security.AccessControl', but it could not be found

Even when adding the System.Security.AccessControl or System.Security.Permissions packages to the unit test project the error persists.

Expected behavior

The solution should compile and the System.Security.Policy.Evidence type from mscorlib should be used in the .net framework project.

Actual behavior

The compilation fails with

CS7069 Reference to type 'Evidence' claims it is defined in 'System.Security.AccessControl', but it could not be found

when used in a .net framework project

Regression?

No response

Known Workarounds

No response

Configuration

  • Microsoft Visual Studio Professional 2022 (64-bit) Version 17.9.2
  • Windows 10 22H2
  • System.Security.Permissions package version 8.0.0

Other information

I'm not sure if this is a bug in System.Security.AccessControl / System.Security.Permissions packages or if I am using it wrongly.
If this is not the right repository for this issue please let me know where I should report this, I couldn't anything better fitting.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions