trust level medium for llblgenprodatasource2 - exception: the action that failed was: InheritanceDemand The type of the first permission that failed was: System.Security.PermissionSet

Posts: 5
Joined: 16-Feb-2009
# Posted on: 07-Mar-2009 21:52:26   

Hi guys, I'm getting this exception when I set trust level to high or medium in web.config (VS2008 .NET 3.5 SP1):

EXCEPTION: System.ArgumentException: Error serializing value 'Collection of entities of type 'EntityBase2'. Current number of elements: 1' of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionNonGeneric.' ---> System.Security.SecurityException: Request failed.
   at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
   at System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
   at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
   at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)
   at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()
   at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
   at System.ComponentModel.TypeDescriptor.GetAttributes(Type componentType)
   at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetConverter(Object instance)
   at System.ComponentModel.ReflectTypeDescriptionProvider.GetConverter(Type type, Object instance)
   at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetConverter()
   at System.ComponentModel.TypeDescriptor.GetConverter(Type type)
   at System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value)
The action that failed was:
The type of the first permission that failed was:
The Zone of the assembly that failed was:
   --- End of inner exception stack trace ---
   at System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value)
   at System.Web.UI.ObjectStateFormatter.Serialize(Stream outputStream, Object stateGraph)
   at System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph)
   at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object state)
   at System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph)
   at System.Web.UI.HiddenFieldPageStatePersister.Save()
   at System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state)
   at System.Web.UI.Page.SaveAllState()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have llblgenprodatasource2 on the page:

<llblgenpro:LLBLGenProDataSource2 ID="FromAddressListLDS" runat="server" 
    AdapterTypeName="DAL.DatabaseSpecific.DataAccessAdapter, DALDBSpecific" 
    EntityFactoryTypeName="DAL.FactoryClasses.FromAddressEntityFactory, DAL" 

For trust level set to Full everything's working fine. If I add attribute CacheLocation="Session" for the LLBLGenProDataSource2, it is working fine even for high/medium trust level.

The problem is that I need to have CacheLocation set to 'ViewState' (default value), cannot use Session, and 'None' value breaks it completely.

I'd say this can be easily replicated with a gridview, llblgenprodatasource2, and trust level set to high/medium.

I think the problem is hidden in this:

The action that failed was: InheritanceDemand The type of the first permission that failed was: System.Security.PermissionSet

I googled for couple of hours how to fix this 'InheritanceDemand' for 'PermissionSet', but was not successful.

I'd appreciate some help!! Cheers.

Posts: 5
Joined: 16-Feb-2009
# Posted on: 08-Mar-2009 19:13:02   

I was able to replicate the issue with the most simple example:

aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm5.aspx.cs" Inherits="Web.Stuff.TestForm5" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <form id="form1" runat="server">

        <asp:GridView ID="TemplateListGridView" runat="server" AllowPaging="True" 
            DataKeyNames="TemplateId" DataSourceID="AdminTemplateListLDS"
                <asp:BoundField HeaderText="TemplateId" DataField="TemplateId" />
        <llblgenpro:llblgenprodatasource2 ID="AdminTemplateListLDS" runat="server" 
            AdapterTypeName="DAL.DatabaseSpecific.DataAccessAdapter, DALDBSpecific" 
            EntityFactoryTypeName="DAL.FactoryClasses.TemplateEntityFactory, DAL"

cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.Stuff
    public partial class TestForm5 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)


        protected override void OnError(EventArgs e)
            Exception ex = Server.GetLastError();
            string message = ex.ToString();


with the trust set to high or medium.

I investigated more about 'InheritanceDemand', and it seems to me that under high/medium trust some assembly requires certain permissions on some inherited class, but don't know which one...

daelmo avatar
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Mar-2009 21:33:00   

What LLBLGen version and RuntimeLibrary version are you using? Could you please update to the latest Runtime library version and try again?

David Elizondo | LLBLGen Support Team
Posts: 5
Joined: 16-Feb-2009
# Posted on: 09-Mar-2009 01:06:33   

llblgen 2.6, SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version Cheers.

Walaa avatar
Support Team
Posts: 14825
Joined: 21-Aug-2005
# Posted on: 09-Mar-2009 08:37:24   

Are you hosting this online, on one of the shared hosting sites?

I'm not sure if this gonna help.....please try to switch on fast serialization (as it happens during viewstate data serialization).

Otis avatar
LLBLGen Pro Team
Posts: 38963
Joined: 17-Aug-2003
# Posted on: 09-Mar-2009 10:28:03   

It's a problem we can't address, as our assembly is marked to be used by partial trusted callers, and all other security limitations are set by the app OR the admin. As the ISP runs in medium trust, it forces some restrictions on you. One of them is that you can't use reflection on protected members. As you can see, the default ASP.NET viewstate serializer doesn't care and serializes the data binary using reflection, which fails. FastSerialization could help, but likely gives problems elsewhere as not all data is serialized through that pipeline (e.g. the datasource control's own little data packet isn't)

So: - use the session. You say you can't use it. However I fail to see why, it's there for these kind of things and it also makes your app faster - try these tips: it might not help, but it's worth a try. Please read that post carefully, as your exception might need different config lines in your configuration file.

Frans Bouma | Lead developer LLBLGen Pro