chinacat456
asked on
Custom assembly - Request for the permission of type 'System.Security.Permissions.FileIOPermission' failed.
I have a Sql Server Reporting Services 2005 report that access a custom assembly that I wrote. The custom assembly reads a .txt file for a connection string, and then makes calls to an Analysis Services data warehouse using ADOMD.Net.
I can run the report that calls the assembly locally without error. However, when I deploy the report and dll to the report server, I am getting the following error:
Request for the permission of type 'System.Security.Permissio ns.FileIOP ermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193 4e089' failed.
I have done the following::
1. Added permission assertions to the method in my assembly (one for reading the .txt file containing the connection string, and one for writing errors to)
[FileIOPermission(Security Action.Ass ert, All = @"c:\ARA\WarehouseConnecti on.txt")]
[FileIOPermission(Security Action.Ass ert, All = @"c:\ARA\Errors.txt")]
2. Added this to the AssemblyInfo.cs file:
[assembly: AllowPartiallyTrustedCalle rs]
3. Strong named the assembly.
4. Copied the dll to the report server (C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin)
5. Copied the .txt file containing the connection string to a folder on the report server (C:\ARA)
6. Added the aspnet user account (with Full Control) to the security tab for the folder containing the .txt files (C:\ARA).
7. Modified the rssrvpolicy.config file on the report server to contain a new CodeGroup element for my dll (using the publickeyblob for my SN'd assembly):
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTru st"
Name="ARACodeGroup"
Description="">
<IMembershipCondition class="StrongNameMembershi pCondition "
version="1"
PublicKeyBlob="00240000048 0000094000 0000602000 0002400005 2534131000 4000001000 1009D2F511 E1EEFE5B39 58795356B9 136A9B33D8 6E17C90EE4 DE804C6196 34857FAE0D 9C4BCD8496 23E8A46CC0 F5B2ED5111 FB292F5BCF AD74CB6162 4C6E3236DB 8027163A80 203683256C 4D759BC63B F58B5B5096 F9B88C8096 F0E2600EB8 31FEBA100D 32CC028928 42B798851A 03FD979292 1D03B9BFE4 FF04A1CF6D 5407554B3" />
</CodeGroup>
The strange thing is that my assembly writes to an Errors.txt file in the Catch block without any problem. But it's writing the error shown above. How could the code have a problem accessing the FileIOPermission object when it seems to be using it for writing out to the text file?
I have searched Google for the past 2 days for a resolution to this. I am at my whits end!! HELP!
My assembly code is below.
Thank you in advance!!
I can run the report that calls the assembly locally without error. However, when I deploy the report and dll to the report server, I am getting the following error:
Request for the permission of type 'System.Security.Permissio
I have done the following::
1. Added permission assertions to the method in my assembly (one for reading the .txt file containing the connection string, and one for writing errors to)
[FileIOPermission(Security
[FileIOPermission(Security
2. Added this to the AssemblyInfo.cs file:
[assembly: AllowPartiallyTrustedCalle
3. Strong named the assembly.
4. Copied the dll to the report server (C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin)
5. Copied the .txt file containing the connection string to a folder on the report server (C:\ARA)
6. Added the aspnet user account (with Full Control) to the security tab for the folder containing the .txt files (C:\ARA).
7. Modified the rssrvpolicy.config file on the report server to contain a new CodeGroup element for my dll (using the publickeyblob for my SN'd assembly):
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTru
Name="ARACodeGroup"
Description="">
<IMembershipCondition class="StrongNameMembershi
version="1"
PublicKeyBlob="00240000048
</CodeGroup>
The strange thing is that my assembly writes to an Errors.txt file in the Catch block without any problem. But it's writing the error shown above. How could the code have a problem accessing the FileIOPermission object when it seems to be using it for writing out to the text file?
I have searched Google for the past 2 days for a resolution to this. I am at my whits end!! HELP!
My assembly code is below.
Thank you in advance!!
//-------------ASSEMBLY---------------
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AnalysisServices.AdomdClient;
using System.IO;
using System.Security.Permissions;
using System.Data.SqlClient;
using System.Diagnostics;
namespace ARACustomReportFunctions
{
public class CustomFormulaFunctions
{
public static string GetPreviousQuarter(string currentQuarter, int previousCount)
{
int counter = 1;
int quarterNumber = Convert.ToInt32(currentQuarter.Substring(1, 1));
int quarterYear = Convert.ToInt32(currentQuarter.Substring(currentQuarter.Length - 4, 4));
do
{
switch (quarterNumber)
{
case 1:
quarterNumber = 4;
quarterYear--;
break;
case 2:
case 3:
case 4:
quarterNumber--;
break;
}
counter++;
} while (counter <= previousCount);
return "Q" + quarterNumber + " " + quarterYear;
}
//[FileIOPermissionAttribute(SecurityAction.Assert, Read = "WarehouseConnection.txt")]
//[FileIOPermissionAttribute(SecurityAction.Assert, Write = "ARAErrors.txt")]
//[FileIOPermissionAttribute(SecurityAction.Assert, All = "c:\\ARA\\WarehouseConnection.txt")]
//[FileIOPermissionAttribute(SecurityAction.Assert, All = "c:\\ARA\\Errors.txt")]
//[FileIOPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
//[FileIOPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
[FileIOPermission(SecurityAction.Assert, All = @"c:\ARA\WarehouseConnection.txt")]
[FileIOPermission(SecurityAction.Assert, All = @"c:\ARA\Errors.txt")]
public static string QuarterlyReturn(string vehicleId, string formulaName, int yearlyFactor, string reportQuarter)
{
//SqlClientPermission sqlPermission = new SqlClientPermission(PermissionState.Unrestricted);
//FileIOPermission filePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, "c:\\ARA\\WarehouseConnection.txt");
//FileIOPermission fileWritePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess, "c:\\ARA\\Errors.txt");
double quarterlyReturn = 0;
try
{
//throw new Exception("Testing exception throwing");
//build query string (selects all returns for the vehicle)
StringBuilder query = new StringBuilder();
query.Append("SELECT NON EMPTY { [Measures].[IV Eval Value] } ON COLUMNS, NON EMPTY { ([Investment Vehicle].[Investment Vehicle Alternate Key].[Investment Vehicle Alternate Key].ALLMEMBERS * [Formula].[Dim Formula].[Dim Formula].ALLMEMBERS * [Period].[Period Quarter].[Period Quarter].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( [Formula].[Dim Formula].[");
query.Append(formulaName);
query.Append("] ) ON COLUMNS FROM ( SELECT ([Investment Vehicle].[Investment Vehicle Alternate Key].&[");
query.Append(vehicleId);
query.Append("] ) ON COLUMNS FROM [IMPACT DW Formula])) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS");
//open connection to OLAP
//sqlPermission.Assert();
//filePermission.Assert();
AdomdConnection adomdConn = new AdomdConnection();
//retrieve connection string from text file
string connectionStr = "";
using (StreamReader reader = new StreamReader("c:\\ARA\\WarehouseConnection.txt"))
//using (StreamReader reader = new StreamReader("WarehouseConnection.txt"))
{
connectionStr = reader.ReadToEnd();
}
adomdConn.ConnectionString = connectionStr; //"Data Source=http://SD031/olap/msmdpump.dll;Initial Catalog=ARA Data Warehouse";
//adomdConn.ConnectionString = "Data Source=http://SD031/olap/msmdpump.dll;Initial Catalog=ARA Data Warehouse";
adomdConn.Open();
//execute query
AdomdCommand myCmd = adomdConn.CreateCommand();
myCmd.CommandText = query.ToString();
AdomdDataReader myReader = myCmd.ExecuteReader();
double geometricallyLinkedReturn = 1;
//int counter = 1;
//int periodsSinceInception = 0;
string quarterName = "";
double quarterCounter = yearlyFactor * 4; //total # of quarters for the calculation
while (myReader.Read())
{
//multiply all 1 plus returns together for the quarters included in the calc
if (!myReader.IsDBNull(0))
{
//Retrieve quarter name from record
quarterName = myReader.GetString(4);
//if yearly factor is 0, just return current quarter's return
if (yearlyFactor == 0)
{
if (quarterName.ToUpper() == reportQuarter.ToUpper())
{
geometricallyLinkedReturn = Convert.ToDouble(myReader.GetString(6));
}
}
else
{
for (int quarters = 1; quarters < quarterCounter; quarters++)
{
//if quarter name matches current quarter or any previous quarter included in the calculation, link returns
if (quarterName.ToUpper() == reportQuarter.ToUpper() ||
quarterName.ToUpper() == GetPreviousQuarter(reportQuarter, quarters).ToUpper())
{
//retrieve evalvalue, add 1, and multiply by current geometricallyLinkedReturn
geometricallyLinkedReturn = geometricallyLinkedReturn * (Convert.ToDouble(myReader.GetString(6)) + 1);
break;
}
}
}
}
}
//calculate annualization factor
double annualizationFactor = 4 / quarterCounter;
//calculate return: (geometrically linked returns ^ annualization factor) - 1
if (yearlyFactor != 0)
{
quarterlyReturn = (Math.Pow(geometricallyLinkedReturn, annualizationFactor) - 1) * 100;
}
else
{
quarterlyReturn = geometricallyLinkedReturn * 100;
}
myReader.Close();
adomdConn.Close();
adomdConn.Dispose();
}
catch (Exception ex)
{
//throw ex;
//EventLog.WriteEntry("SSRS_ARA", ex.Message);
//System.Diagnostics.EventLog appLog =
// new System.Diagnostics.EventLog();
//appLog.Source = "ARACustomReportFunctions";
//appLog.WriteEntry(ex.Message);
//fileWritePermission.Assert();
using (StreamWriter writer = new StreamWriter("c:\\ARA\\Errors.txt"))
//using (StreamWriter writer = new StreamWriter("ARAErrors.txt"))
{
writer.Write(ex.Message);
}
}
return quarterlyReturn.ToString("N2") + "%";
}
}
}
//-------------AssemblyInfo.cs---------------
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ARACustomReportFunctions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SMART")]
[assembly: AssemblyProduct("ARACustomReportFunctions")]
[assembly: AssemblyCopyright("Copyright © SMART 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d9de2e07-b23e-4981-84ec-c4c2d3671fc0")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AllowPartiallyTrustedCallers]
This is a Code Access Security (CAS) issue.... you need to adjust the CAS settings on the local PC to allow it to trust the assembly when it's run from a network
http://www.emmet-gray.com/Articles/CodeAccessSecurity.htm
http://www.emmet-gray.com/Articles/CodeAccessSecurity.htm
ASKER
According to the instructions, I did the following on both my development laptop and on the report server:
* From a development PC, open the Control Panel, navigate to the "Administrative Tools" section
* Click on the "Microsoft .Net Framework 2.0 Configuration" applet
* Click on the "Configure Code Access Security Policy" link
* Click on the "Adjust Zone Security" link
* Keep the default "Make changes to this computer", click the "Next" button
* Click on the "Local Intranet" icon
* Move the vertical slider to "Full Trust", Click the "Next" button
* Click "Finish" at the summary screen
However, I am still getting the same error. :-(
* From a development PC, open the Control Panel, navigate to the "Administrative Tools" section
* Click on the "Microsoft .Net Framework 2.0 Configuration" applet
* Click on the "Configure Code Access Security Policy" link
* Click on the "Adjust Zone Security" link
* Keep the default "Make changes to this computer", click the "Next" button
* Click on the "Local Intranet" icon
* Move the vertical slider to "Full Trust", Click the "Next" button
* Click "Finish" at the summary screen
However, I am still getting the same error. :-(
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER