[RESOLVED]level 2 transparency causes all methods in AllowPartiallyTrustedCallers

Hi,

i am using PagedList Nuget package in my asp.net mvc 5 application.

below is my source which i am trying to:

@Html.PagedListPager(Model, page => Url.Action("StudentList",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))

when i am using it on my view, it is throwing an exception:

System.TypeAccessException was unhandled by user code
  HResult=-2146233021
  Message=Attempt by security transparent method 'PagedList.Mvc.HtmlHelper.PagedListPager(System.Web.Mvc.HtmlHelper, PagedList.IPagedList, System.Func`2<Int32,System.String>)' to access security critical type 'System.Web.Mvc.MvcHtmlString' failed.

Assembly 'PagedList.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=abbb863e9397c5e1' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.  Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
  Source=PagedList.Mvc
  TypeName=""
  StackTrace:
       at PagedList.Mvc.HtmlHelper.PagedListPager(HtmlHelper html, IPagedList list, Func`2 generatePageUrl)
       at ASP._Page_Views_Registration_StudentList_cshtml.Execute() in c:UsersmaifsSkyDriveSchoolManagementSystemSMSAppViewsRegistrationStudentList.cshtml:line 57
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.StartPage.RunPage()
       at System.Web.WebPages.StartPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
  InnerException: 

i tried to use these attributes in assemblyinfo.cs

[assembly: SecurityRules(SecurityRuleSet.Level2)]

and 

[assembly: AllowPartiallyTrustedCallersAttribute] but it didn’t work. Kindly guide me . thanks

Hi softech,

For this issue, it seems there is the issue in that PagedList.MVC package.

Please upgrade the package to the least version. (PagedList.Mvc 4.5)

# PagedList.Mvc 4.5.0

https://www.nuget.org/packages/PagedList.Mvc

There is a related thread that can help you:

http://forums.asp.net/t/1939805.aspx

Best Regards

Starain Chen

Thanks Starain.

Leave a Reply