Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Friday, March 9, 2012

Reporting Service Custom Code Error - Request for the permission of type

I have added some Custom Code in Reporting Service.
Reports - Report Properties - Code Tab - Custom Code
Here is my code.
public Function Please(d as DateTime, CultureFormat as String) as
String
dim returnvalue as String
Try
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo(CultureFormat)
dim ci as System.Globalization.CultureInfo
ci = new System.Globalization.CultureInfo(CultureFormat)
returnvalue = d.ToString("D",ci)
Catch ex As Exception
returnvalue = ex.ToString()
End Try
Return returnvalue
End Function
If I preview this report it works fine, but when I deploy this report,
I get this error message.
System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 failed.
at
System.Security.CodeAccessSecurityEngine.CheckTokenBasedSetHelper(Boolean
ignoreGrants,
TokenBasedSet grants, TokenBasedSet denied, TokenBasedSet demands)
at
System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
grants, PermissionSet
denied, PermissionSet demands)
at System.Threading.Thread.set_CurrentCulture(CultureInfo value)
at CustomCodeProxy.Please(DateTime d, String CultureFormat)
Has anyone run into this before?
Thanks, JonThe code security permission do not allow you to set the current threads
culture. Since you are passing the culture info into the ToString method
you should not need to do this so I would just remove this line of code:
System.Threading.Thread.CurrentThread.CurrentCulture = new
System.Globalization.CultureInfo(CultureFormat)
--
-Daniel
This posting is provided "AS IS" with no warranties, and confers no rights.
<jonknutsonhome@.yahoo.com> wrote in message
news:1126125095.372193.270750@.g14g2000cwa.googlegroups.com...
>I have added some Custom Code in Reporting Service.
> Reports - Report Properties - Code Tab - Custom Code
> Here is my code.
> public Function Please(d as DateTime, CultureFormat as String) as
> String
> dim returnvalue as String
> Try
> System.Threading.Thread.CurrentThread.CurrentCulture = new
> System.Globalization.CultureInfo(CultureFormat)
> dim ci as System.Globalization.CultureInfo
> ci = new System.Globalization.CultureInfo(CultureFormat)
> returnvalue = d.ToString("D",ci)
> Catch ex As Exception
> returnvalue = ex.ToString()
> End Try
> Return returnvalue
> End Function
>
> If I preview this report it works fine, but when I deploy this report,
> I get this error message.
>
> System.Security.SecurityException: Request for the permission of type
> System.Security.Permissions.SecurityPermission, mscorlib,
> Version=1.0.5000.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089 failed.
> at
> System.Security.CodeAccessSecurityEngine.CheckTokenBasedSetHelper(Boolean
> ignoreGrants,
> TokenBasedSet grants, TokenBasedSet denied, TokenBasedSet demands)
> at
> System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
> grants, PermissionSet
> denied, PermissionSet demands)
> at System.Threading.Thread.set_CurrentCulture(CultureInfo value)
> at CustomCodeProxy.Please(DateTime d, String CultureFormat)
> Has anyone run into this before?
> Thanks, Jon
>