System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

Posts   
 
    
DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 26-Sep-2010 15:34:07   

Hi,

I've created a website with LLBLGen and when I upload it to my shared hosting space I get this error when visiting a page that uses LLBLGen:

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

I believe it's something to do with the trust level, but I can't change that trust level (if I change it via the web.config I get another exception saying that it isn't allowed to change that).

Any ideas?

Thx, Bart

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Sep-2010 17:30:04   

Hi Bart,

  • What is your LLBLGen version and Runtime Library version are you using? (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7717)

  • What is the code that triggers that exception. Please enable debug in your .config to see the stacktrace.

  • What is the shared hosting? Maybe they can provide you with the machine.config with the permissions they are applying to sites.

David Elizondo | LLBLGen Support Team
DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 26-Sep-2010 19:18:13   

Hi,

  • The LLBLGen version is v 2.6 Final, October 9th 2009 (2.6.10.526)

  • As soon as I bind an entitycollection to a repeater I get the error

  • Shared hosting is http://www.hostbasket.com

Thx

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Sep-2010 08:31:38   

Would you please post the complete stack trace.

DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 27-Sep-2010 09:38:47   

Hi,

Here is the stacktrace:

[SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +150
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +284
   System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +69
   System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +150
   System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +30
   System.Threading.CompressedStack.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +40
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +123
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +54

Thx

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Sep-2010 15:07:53   

Are you using DI? Are you using Linq?

I think the the following long thread can be helpful to you. http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15694

DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 27-Sep-2010 19:16:43   

I use Linq to fetch a list of entities, that list I bind to a repeater. That generates the error. I tried to use FastSerialization but it didn't help. I've added this line in the Global.asax Application_Start event:

SD.LLBLGen.Pro.ORMSupportClasses.SerializationHelper.Optimization = SD.LLBLGen.Pro.ORMSupportClasses.SerializationOptimization.Fast;

Here's part of my code (I use the Adapter template):

public static List<NewsItemEntity> GetList(NewsItemSearcher NewsItemSearcher, Int32 ItemsPerPage, Int32 CurrentPageIndex) {
            List<NewsItemEntity> collection = new List<NewsItemEntity>();

            IPrefetchPath2 prefetchpath = new PrefetchPath2(EntityType.NewsItemEntity);
            NewsItemEntityHelper.LoadPrefetchPath(prefetchpath, false);

            using (DataAccessAdapter adapter = new DataAccessAdapter()) {
                LinqMetaData metaData = new LinqMetaData(adapter);
                metaData.ContextToUse = new Context();

                IQueryable<NewsItemEntity> list = NewsItemEntityHelper.GetQueryableList(metaData, NewsItemSearcher);
                list = list.WithPath(prefetchpath);

                if (NewsItemSearcher.Sorter == NewsItemSorter.DateAdded) {
                    if (NewsItemSearcher.SortDescending) {
                        list = list.OrderByDescending(item => item.DateAdded);
                    } else {
                        list = list.OrderBy(item => item.DateAdded);
                    }
                }

                if (ItemsPerPage > 0) {
                    list = list.Skip(ItemsPerPage * CurrentPageIndex).Take(ItemsPerPage);
                }
                collection = list.ToList();
            }

            return collection;
        } /* GetList */

And in the codebehind of the usercontrol:

if (!this.IsPostBack) {
                this.NewsRepeater.DataSource = NewsItemEntityHelper.GetList(new NewsItemSearcher() { WebsiteId = this.PageBase.WebsiteId, OnlineLanguageId = this.LanguageId }, 10, 0);
                this.NewsRepeater.DataBind();
            }
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Sep-2010 08:55:23   

Did you get anything useful from teh thread I've posted?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 28-Sep-2010 10:48:57   

The stacktrace does not show any relation to our code. Your code also simply binds a list to a control, I have no idea how that can be a reflection invoking action, only if the repeater itself has to reflect over the bound elements, but that should do only public member reflection, something which is allowed in medium trust. So I think the hoster has limited the trust level more than medium trust.

Please contact your hoster and explain the problem and let them find out why their security restrictions cause this exception. Again: the repeater will bind the data using reflection to read data from the bound list of objects, but will do so using reflection to obtain public members, which is allowed in medium trust.

Frans Bouma | Lead developer LLBLGen Pro
DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 28-Sep-2010 20:06:31   

Hi,

I've managed to reduce the problem to these lines:

if (NewsItemSearcher.WebsiteId.HasValue) {
                toreturn = toreturn.Where(item => (from newsitemwebsite in metaData.NewsItemWebsite where newsitemwebsite.WebsiteId == NewsItemSearcher.WebsiteId.Value select newsitemwebsite.NewsItemId).Contains(item.Id));
            }

            if (NewsItemSearcher.OnlineLanguageId.HasValue) {
                toreturn = toreturn.Where(item => (from newsitemlanguage in metaData.NewsItemLanguage where newsitemlanguage.LanguageId == NewsItemSearcher.OnlineLanguageId.Value && newsitemlanguage.StatusId == (Int32)Status.Online select newsitemlanguage.NewsItemId).Contains(item.Id));
            }

            if (NewsItemSearcher.Year.HasValue) {
                toreturn = toreturn.Where(item => item.DateAdded.Year == NewsItemSearcher.Year.Value);
            }

If I comment out these lines then I doens't give the error. So there is something wrong with LINQ and the hosting provider, they said that when they test it on their IIS7 machine it works fine... :s

Sorry to have bothered you, I'll find a solution with the hosting provider.

Thanks for the help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 28-Sep-2010 20:47:24   

Is the stacktrace you posted complete? As the origin of the exception is now unclear, according to the stacktrace. I.e. if it originates in the DQE of llblgen pro, more lines have to be present in the stacktrace.

Our linq provider only uses public property reflection, which shouldn't be a problem in any trust environment. So it's a little bit odd why this happens.

if the hosting provider needs more info from us, just post in this thread simple_smile

Frans Bouma | Lead developer LLBLGen Pro
DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 28-Sep-2010 21:21:53   

Yes the stacktrace is complete. I said that the error occured when I bound the repeater, but that is actually not true, because the database is still empty so no results are returned from the method, so no data is bound to the repeater. The exception is thrown from the moment this line is reached:

if (NewsItemSearcher.WebsiteId.HasValue) {
                toreturn = toreturn.Where(item => (from newsitemwebsite in metaData.NewsItemWebsite where newsitemwebsite.WebsiteId == NewsItemSearcher.WebsiteId.Value select newsitemwebsite.NewsItemId).Contains(item.Id));
            }

If I reduce it to this:

//if (NewsItemSearcher.WebsiteId.HasValue) {
                toreturn = toreturn.Where(item => (from newsitemwebsite in metaData.NewsItemWebsite where newsitemwebsite.WebsiteId == 1 select newsitemwebsite.NewsItemId).Contains(item.Id));
            //}

It still throws the exception.

When I delete the only line left the exception is gone simple_smile But that is obviously not what I want..

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Sep-2010 22:05:32   

Has your hoster actually confirmed which level of Trust they have got set (and confirmed it with a screen shot or similar, rather than just telling you...? simple_smile )

Matt

DhooreB
User
Posts: 10
Joined: 27-Sep-2009
# Posted on: 29-Sep-2010 18:45:23   

I'm getting a free upgrade to their IIS7 machine, so we'll never know what the problem was simple_smile

Anyway, thanks for the help guys!