0

Is there a way to set/adjust the Assembly Security levels (Transparent, critical, etc...) on a project? According to this MS article we can define them by adding a line like this to the top of the namespace:

using System.SomeOtherNameSpace;

[assembly: System.Security.SecurityTransparent]
namespace MyProject.MyTransparentNameSpace
{
   //whole bunch of classes and enums
}

But is there a setting somewhere that I can add this attribute to my project rather than defining this in the code?


A little bit background:

I have a MS.Net FrameWork 4.7.2 project (let's call it Project High-Level) that references a .Net Standard 2.0 project (let's call it project low-level) and in project low-level, there are some public namespaces, classes and enums that are used throughout High-Levelproject.

I was getting MethodAccessException on a line in the High-Level project that references an enum from low-level (.NetStandard) project. All my methods, classes and interfaces were public, even looking at the values through Watches worked fine, however, I kept getting Method HighLevel.XXX cannot access method LowLevel.get_enum() exception. I tried many things and at the end of the day, using that [assembly: ....] got rid of the issue.

timmebee
  • 89
  • 1
  • 2
  • 12
AleX_
  • 508
  • 1
  • 6
  • 20

1 Answers1

1

we can define them by adding a line like this to the top of the namespace

That attribute is on the assembly (the project). The attribute is prefixed with assembly:, not namespace:. It's position there is coincidental and can be moved elsewhere (as long as it is outside of a namespace). You can move it into the project's AssemblyInfo.cs file, next to the project's AssemblyVersion attribute. It should be (but doesn't have to be) located inside your projects Properties folder.

See: What is AssemblyInfo.cs used for?