Trying to write exceptions to the event log in custom SSRS assembly and get error.
Hi All, Can do with some assistancce with a custom assembly I have ceated for SSRS Reports the assembly works based on the code functionailty, but when I want to write to the event log, so that I can catch any exceptions from the code and write the exception to the event logs I get the following error. Request for the permission of type 'System.Diagnostics.EventLogPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed I have created the code group for my custom dll (please see below) and have added my custom assebly to the GAC, but every time the line executes to add log entry to the application log I get the above error. <CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="FullTrust"> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Report_Expressions_Default_Permissions" Description="This code group grants default permissions for code in report expressions and Code element. "> <CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="FullTrust" Description="This code group grants MyComputer code Execution permission. "> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Microsoft_Strong_Name" Description="This code group grants code signed with the Microsoft strong name full trust. "> </CodeGroup> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Ecma_Strong_Name" Description="This code group grants code signed with the ECMA strong name full trust. "> </CodeGroup> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Report_Server_Strong_Name" Description="This code group grants Report Server code full trust. "> </CodeGroup> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust"> </CodeGroup> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="SharePoint_Server_Strong_Name" Description="This code group grants SharePoint Server code full trust. "> </CodeGroup> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="XXX.Apps.SSRS" Description="XXX SSRS Utility Class. "> </CodeGroup> </CodeGroup> </CodeGroup> I am running SSRS on SQL 2008 R2. I have also changed the ssrs policy file as you can see above (I condensed the policy file so that I can post this in the article) and I have given full trust to FirstMatchCodeGroup & UnionCodeGroup & FirstMatchCodeGroup too and not having much success. The line of code failing is; Any pointers or help would be appreciated. EventLog.WriteEntry(EventSource, logMessage, et, 0786); Many Thanks Bobby H :O) Bobby Habib SharePoint .Net Technical Lead / Developer
August 2nd, 2012 9:41am

Hello Bobby, Thank you to post your question on TechNet forum. Based on my experience, we need check two points. First, we need use AllowPartiallyTrustedCallersAttribute attribute for the strong-named assembly. Since the code in report is partially trusted, it is not allowed to access the strong-named assembly due to .net framework restrict. For more information, please look into the following MSDN article. http://msdn.microsoft.com/en-us/library/ms155030(v=sql.105) Second, we need to check whether the Access permission in custom code is granted. For example, if the custom assembly need access the local folder, then it need the different PermissionSet in the reporting service policy file. Meanwhile, IMembershipCondition of the code group is necessary for the code group to set. Please check whether you select the properly membership condition. For more information about this topic, please refer to the following article. http://msdn.microsoft.com/en-us/library/ms153587(v=sql.105) I hope it is helpful to you. If you have further questions about this issue, please tell us freely. Regards, EdwardEdward Zhu TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
August 3rd, 2012 5:30am

Hi Edward, Thank you for your response. I already had AllowPartiallyTrustedCallerAttribute in the Assembly.info file already, I have added a custom permission set which looks like this (See Below) and still not having much luck here and getting the same error. I have rebooted the server to test and make effect but still no joy. I think I might be missing somethign fundamental <PermissionSet class="NamedPermissionSet" version="1" Name="XXXCustom" Description="Permission Set for Custom XXX Assemblies."> <IPermission class="XXX.Apps.SSRS.Utility, XXX.Apps.SSRS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=57c88e9567872c4e" version="1" Unrestricted="true" /> </PermissionSet> </NamedPermissionSets> <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="XXXCustom" Name="XXX.Apps.SSRS" Description="XXX SSRS Utility Class. "> <IMembershipCondition class="StrongNameMembershipCondition" version="1" PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100576abb2d1806442c249a6a35bb622cabf60e32b63a0dce7ec5773b4baa4252fe4e56734a79c7a741577020b2e02d7b602b710ede6f354b93fad3d8708950faee5725b4fdf68f3f886a2c0d9845088fccc6d7937dbdf0ceafdd91c9f6839a2acf4b6a224567d19b8f79f87c80d1a41a7a5a755c5e70b044b19c71af6a4e546cd6" /> Help really appreciated. Bobby Habib SharePoint .Net Technical Lead / Developer
August 6th, 2012 9:41am

Calling code that is failing; if (!EventLog.SourceExists(EventSource)) { var sourceData = new EventSourceCreationData(EventSource, EventLogType); EventLog.CreateEventSource(sourceData); } var eventLogPerm = new EventLogPermission(EventLogPermissionAccess.Administer, "."); eventLogPerm.Assert(); EventLog.WriteEntry(EventSource, logMessage, et, 0786);Bobby Habib SharePoint .Net Technical Lead / Developer
Free Windows Admin Tool Kit Click here and download it now
August 6th, 2012 9:43am

This got my solution working; http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/9af8f39a-9dc5-49ab-91af-2f64198c8477/ For security reason, you should change following two groups to FullTrust in three configure files, please follow these steps to allow executing the custom code: 1.Open these three files: 1).RSPreviewPolicy which located at C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies 2). rsmgrpolicy which located at C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportManager 3). rssrvpolicy which located at C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer 2. Change the PermissionSetName of the following 2 groups from Execution to FullTrust: <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Report_Expressions_Default_Permissions" Description="This code group grants default permissions for code in report expressions and Code element. "> </CodeGroup> <CodeGroup class="FirstMatchCodeGroup" version="1" PermissionSetName="FullTrust" Description="This code group grants MyComputer code Execution permission. "> <IMembershipCondition class="ZoneMembershipCondition" version="1" Zone="MyComputer" /> </CodeGroup> If you are referencing custom code in SQL expressions then the above looks to me that it is required. Bobby Habib SharePoint .Net Technical Lead / Developer
August 6th, 2012 11:24am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics