Manuel Rivera
Manuel Rivera

Reputation: 523

Attempt by security transparent method xxx to access security critical yy

I'm just starting to learn ASP.NET MVC and following an ASP.NET MVC tutorials.

I'm using Visual Studio Express 2013 RC for Web and think that could be the reason for my problem, because the tutorial for paging is written using VS2012.

Everything is works fine; but when I add paging to one of the pages, using all the instructions in the tutorial for adding PagedList.mvc, everything compiles fine; when I get to the specific page, I receive this error message:

Attempt by security transparent method 'PagedList.Mvc.HtmlHelper.PagedListPager(System.Web.Mvc.HtmlHelper, PagedList.IPagedList, System.Func2) to access security critical type 'System.Web.Mvc.MvcHtmlString' failed.

Assembly 'PagedList.Mvc, Version=4.3.0.0, Culture=neutral, enter code here 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.

Anybody can give some reason why this situation is happening? Many thanks in advance and bye ...

Upvotes: 4

Views: 4971

Answers (3)

shanabus
shanabus

Reputation: 13115

For me, the page was dying in the same way on Html.ActionLink helpers:

Attempt by security transparent method 'Microsoft.Web.Mvc.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression1<System.Action1>, System.String, System.Object)' to access security critical type 'System.Web.Mvc.MvcHtmlString' failed.

The solution was to do the following:

Uninstall-Package Mvc4Futures

Then:

Install-Package Microsoft.AspNet.Mvc.Futures -Version 5.0.0

https://www.nuget.org/packages/Microsoft.AspNet.Mvc.Futures/5.0.0

Upvotes: 5

Willy
Willy

Reputation: 1729

I have the same problem, then I update to PagedList.Mvc.4.5.0.0 and it's work

Upvotes: 2

Mikhail
Mikhail

Reputation: 9300

It looks like that this issue is caused by specifics of the MVC 5.

Check MVC5 - System.TypeAccessException error occurs when using extension methods of HtmlHelper class from external class library with AllowPartiallyTrustedCallers attribute thread to find possible solutions.

Upvotes: 1

Related Questions