SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz Development Resources
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.

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
Filed Under:

Comments

No Comments
Anonymous comments are disabled

About eralper

SQL Server administrator and T-SQL developer including BI components Web programming with HTML, HTML5 and ASP, ASP.NET and .NET Framework developer SAP ABAP and SAPUI5 development, Web Dynpro and Smart Form Siemens HiPath Center CTI development
Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems