Jason Stangroome

Hello,

I am writing a class library project that will ultimately be referenced and used by an ASP.NET website in a Medium-Trust environment. Can I include something in my class library project to prevent it from compiling if it has (or a non-GAC project it references has) code that will require higher permissions If I cannot get a build error when I write full trust code, can I force the library to fail on load

Last resort, is there a way to get a unit test to verify that production code does not require certain permissions For example, the unit test project itself may require private reflection capabilities to do the testing but in it I want to test that the production code will not fail if I somehow temporarily retract the reflection permission.

Thanks,

--

Jason Stangroome



Re: Common Language Runtime Enforcing trust levels early

BinaryCoder

The Visual Studio Security settings in the Project properties let you specify the expected level for your code to run.

If you hit Enable ClickOnce Security Settings and This is a partial trust application when you debug your app in Visual Studio, these are the settings that will be applied.

It can make sense to use this feature to test your code even if you are not using ClickOnce.





Re: Common Language Runtime Enforcing trust levels early

Jason Stangroome

The Security "tab" in the project properties designer window is only available for Windows Forms projects in my Visual Studio 2005 SP1 Team System installation. Class Library projects do not have this option. Any idea on achieving the same result for a class library

Thanks,

--

Jason Stangroome





Re: Common Language Runtime Enforcing trust levels early

BinaryCoder

No, it does not require the team system. I have it working in the Standard Edition.

I think you can get past this by making an EXE project that references your DLL as a "project reference". Then, do your testing by starting that EXE.





Re: Common Language Runtime Enforcing trust levels early

Jason Stangroome

I think I'll see if there are any nicer solutions available before I resort to introducing an "exe" project. I've tried various Code Access Security permission attribute declarations at the assembly and method level with no success.





Re: Common Language Runtime Enforcing trust levels early

Feng Chen - MSFT

Hi Jason,

BinaryCoder is right, you can write a little test application to call it, and put them on a zone with restricted permission set, like local intranet zone. If your library need more permission than you have expected, security exceptions will thrown.

Hope this helps!

Thanks!