Recently, while I was trying to create a subscription in SQL Server 2005 Reporting Services by using the CLR stored procedure which calls the web service API of Reporting Services, I got the following error message.
The error occured when I called the CLR stored procedure from the SQL Server Management Studio Query Editor:
Command execution failed: There was an error generating the XML document.
System.InvalidOperationException: There was an error generating the XML document. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReportingService.Write17_ScheduleDefinition(String n, String ns, ScheduleDefinition o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterReportingService.Write177_CreateSchedule(Object p)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer216.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
The action that failed was:
The assembly or AppDomain that failed was:
myReportingServicesAssembly.XmlSerializers, Version=220.127.116.11, Culture=neutral, PublicKeyToken=d376d63c16300201
The method that caused the failure was:
The Zone of the assembly that failed was:
I found that the main error message here is: System.Security.SecurityException: That assembly does not allow partially trusted callers.
To solve this security exception I mark my assembly by using the AllowPartiallyTrustedCallersAttribute (APTCA)
I used the AllowPartiallyTrustedCallersAttribute (APTCA) in the Assemblyinfo.vb file since my project was developed in VB.NET. You can add the attribute AllowPartiallyTrustedCallersAttribute in Assemblyinfo.cs for C# applications.
Use the below code line in vb.net
Prior adding the AllowPartiallyTrustedCallers attribute you should check that you have imported the System.Security namespace
I could solve the "That assembly does not allow partially trusted callers" exception by adding the <Assembly: AllowPartiallyTrustedCallers()> in the Assemblyinfo.vb. Hope it works for you also :)