Errors showing up around cast to IPermission RRS feed

  • Question

  • We have noticed an uptick in errors generated from our application that all display the following error with differing stack traces:

    Description: System.Exception: Unable to cast object of type 'System.Runtime.CompilerServices.TrueReadOnlyCollection`1[System.Linq.Expressions.Expression]' to type 'System.Security.IPermission'. in data service xxx ---> System.InvalidCastException: Unable to cast object of type 'System.Runtime.CompilerServices.TrueReadOnlyCollection`1[System.Linq.Expressions.Expression]' to type 'System.Security.IPermission'.
       at System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo method)
       at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType, Object target)
       at lambda_method(Closure )
       at System.Linq.EnumerableQuery`1.GetEnumerator()
       at System.Linq.EnumerableQuery`1.System.Collections.IEnumerable.GetEnumerator()
       at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)
       at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService)
       at System.Data.Services.DataService`1.HandleRequest()

    we have tried to reproduce but have not been able to, these errors appear to be increasing in volume.  The only trend we've been able to really see is that these errors are occurring after customers load pages that access data.  We get different flavors of this cast error, with the following objects (as an example) showing up in the error description as not castable to IPermission:

    RTDynamicMethod, System.Runtime.CompilerServices.TrueReadOnlyCollection, System.Web.UI.WebControls.Repeater, System.Runtime.CompilerServices.Closure, and our own Buildium.Enterprise.Web.Shared.DataServices.Tasks.TasksDataService and Buildium.Enterprise.Web.Shared.DataServices.Residents.ResidentDataService

    If anyone has seen this before or has any insight into this error I would appreciate any help as we're pretty stuck with this one right now.


    Tuesday, February 17, 2015 11:57 PM


  • Hello buildBos,

    It is hard to say what causes this exception since we cannot reproduce this exception due to the complexities of your application which seems to be a production one. For this, from your provided code, it shows this exception is thrown in the RuntimeHelpers._CompileMethod, fortunately, since Microsoft has open the source of .NET framework, and according to this blog, you could try to debug the .NET source, in your case, you could debug the RuntimeHelpers._CompileMethod to see which code causes this exception.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Monday, March 2, 2015 11:07 AM
    Wednesday, February 18, 2015 8:49 AM