Title

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help
in Search

Eralper's Blog on Software Development



System.Security.SecurityException: That assembly does not allow partially trusted callers.

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:
 LinkDemand
 The assembly or AppDomain that failed was:
 myReportingServicesAssembly.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d376d63c16300201
 The method that caused the failure was:
 System.DateTime get_StartDateTime()
 The Zone of the assembly that failed was:
 MyComputer
 

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

<Assembly: AllowPartiallyTrustedCallers()>

[assembly: AllowPartiallyTrustedCallers]
 

Prior adding the AllowPartiallyTrustedCallers attribute you should check that you have imported the System.Security namespace

Imports System.Security

or

using System.Security

 

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 :)

 

Published Sunday, October 15, 2006 1:59 PM by eralper
Filed Under:

Comments

No Comments
Anonymous comments are disabled
Copyright © 2004 - 2008 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems