Security Transparent Error

Topics: Writing modules
Mar 12, 2012 at 5:42 PM

Hi Guys,

I get following security exception when I trying to type cast ContentFields to NumericField in a Controller.

FYI: I'm using Orchard 1.4. both Orchard.Fields module and mine have [assembly: SecurityTransparent] in their AssemblyInfo class and <trust level Medium> is commented in web.config file.

As you see I also used "TextField" cast in following code which runs without any problems, but ImageFields and all Field types in Orchard.Fields Namespace have same issue.

Any Ideas?

return Json(deals.Select(o=>

                new {Title= o.Title,

                     Link = ((TextField)o.Fields.First(p => p.Name == "Link")).Value,

                     Price = ((NumericField)o.Fields.First(p => p.Name == "Price")).Value,

                     Value = ((NumericField)o.Fields.First(p => p.Name == "Value")).Value,

                }),JsonRequestBehavior.AllowGet);

 

 

Attempt by security transparent method 'Prototype.DealProviders.Controllers.DealController.<GetDeals>b__1e(Prototype.DealProviders.Models.DealPart)' to access security critical type 'Orchard.Fields.Fields.NumericField' failed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeAccessException: Attempt by security transparent method 'Prototype.DealProviders.Controllers.DealController.<GetDeals>b__1e(Prototype.DealProviders.Models.DealPart)' to access security critical type 'Orchard.Fields.Fields.NumericField' failed.

Source Error: 

Line 136:
Line 137:            return Json(deals.Select(o=> 
Line 138:                new {Title= o.Title,
Line 139:                     Link = ((TextField)o.Fields.First(p => p.Name == "Link")).Value,
Line 140:                     Price = ((NumericField)o.Fields.First(p => p.Name == "Price")).Value,

 

 

Mar 14, 2012 at 6:22 AM

I've changed the logic to using dynamic object, and it works pretty fine now

 

var deals = _dealService.Get(pager.GetStartIndex(), pager.PageSize).Select(o=>(dynamic)o); 

            return Json(deals.Select(o=>

                new {Title= o.Title,

                     Link = o.Link.Value,

                     EndedAt = o.EndedAt.DateTime,

                     ImageUrl = o.Image.FileName,

                     ProviderImageUrl = Url.Content(o.DealProviderPart.Image.FileName),

                }),JsonRequestBehavior.AllowGet);