Attempt by security transparent method when using the Voting Module

Topics: Troubleshooting, Writing modules
Aug 20, 2011 at 4:10 PM

Hi All,

I am recieving this error

Attempt by security transparent method 'NGM.Forum.Services.ThreadService..ctor(Orchard.ContentManagement.IContentManager, NGM.Forum.Services.IPostService, Contrib.Voting.Services.IVotingService)' to access security critical type 'Contrib.Voting.Services.IVotingService' failed.

I have in my modules assemblyinfo.cs both:

[assembly: SecurityTransparent]
[assembly: AllowPartiallyTrustedCallers]

The error seems to be coming when using IVotingService within a handler or anyother class that uses an interface that uses IDependency.

here is the code

    public interface IThreadService : IDependency { /*Stuff*/ }

    public class ThreadService : IThreadService {
        private readonly IContentManager _contentManager;
        private readonly IPostService _postService;
        private readonly IVotingService _votingService;

        public ThreadService(IContentManager contentManager,
            IPostService postService,
            IVotingService votingService) {
            _contentManager = contentManager;
            _postService = postService;
            _votingService = votingService;



Any ideas yall?


Aug 20, 2011 at 8:47 PM

I saw a weird problem where I added [assembly: SecurityTransparent] to my AssemblyInfo.cs file, recompiled and I still got security exceptions with my custom module.  Then tried:

  1. Delete the Properties/AssemblyInfo.cs file.
  2. Right click on your custom module project and select Properties.
  3. Click Assembly Information on the Application tab of the properties window.
  4. Fill in a title and whatever else you'd like.
  5. Click OK.  This will re-create the AssemblyInfo.cs file.
  6. Append [assembly: SecurityTransparent] to the end of the file.

Once I did this, the security errors magically went away.  I can't explain why as the AssemblyInfo.cs files looked exactly the same...

It's a shot in the dark for you anyways...

Good luck!


Aug 20, 2011 at 11:17 PM

Hey Steve, jsut tried your steps but with no luck :( ARGH!! so close to getting a populatiy algorithm in my Forum module!!

Aug 20, 2011 at 11:22 PM

Sorted.. I needed to add

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

to my Forum module. Im not sure this is the end fix, but for now its working.

Can any of the Orchard lads let me know why I would need to do this?
Aug 20, 2011 at 11:26 PM

Oh I see! - Setting that attribute by-passes .net 4 security transparenty and uses .net 2.0's transparenty stuff. Any idea on how I can get around this with out using this hack?

Aug 21, 2011 at 10:16 AM

Got it working!! removed [assembly: SecurityTransparent] from the assemblyinfo.cs file and it works. Epic!