Free Support Forum -


We started getting the following exception when we updated our environment from ASP.NET 2.0 to ASP.NET 2.0:


Attempt by security transparent method ’ . + . ()’ to access security critical method ‘System.Runtime.InteropServices.Marshal.Copy(IntPtr, Byte[], Int32, Int32)’ failed.

Assembly ‘Aspose.Pdf, Version=, Culture=neutral, PublicKeyToken=716fcc553a201e56’ is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.

This seems to be the exact same issue as there was with Pdf.Kit library (

Below is the code snippet that produced the error:

        private float _pageHeight = PageSize.A4Height;
private float _pageWidth = PageSize.A4Width;
private const float _marginSize = .1F * 72; //.1 inches. The small margin size is for images that have already been scanned with margins
    <span style="color:blue;">public</span> Aspose.Pdf.<span style="color:#2b91af;">Image</span> ToAsposeImage(<span style="color:blue;">byte</span>[] imageBytes)
        <span style="color:#2b91af;">MemoryStream</span> imageStream = <span style="color:blue;">null</span>;

        <span style="color:blue;">try</span>
            imageStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>(imageBytes);

            Aspose.Pdf.<span style="color:#2b91af;">Image</span> image = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">Image</span>();

            <span style="color:green;">//Set the image properties</span>
            image.ImageInfo.ImageStream = imageStream;
            image.ImageInfo.ImageFileType = Aspose.Pdf.<span style="color:#2b91af;">ImageFileType</span>.Tiff;
            image.ImageInfo.TiffFrame = -1;
            image.ImageScale = 10000f; <span style="color:green;">//just scale to fill the page</span>

            <span style="color:blue;">return</span> image;
        <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
            <span style="color:blue;">if</span> (imageStream != <span style="color:blue;">null</span>) imageStream.Dispose();
            <span style="color:blue;">throw</span> ex;

    <span style="color:blue;">public</span> <span style="color:blue;">byte</span>[] Convert(<span style="color:blue;">byte</span>[] originalContent)
        <span style="color:#2b91af;">MemoryStream</span> outStream = <span style="color:blue;">null</span>;
        Aspose.Pdf.<span style="color:#2b91af;">Image</span> image = <span style="color:blue;">null</span>;

        <span style="color:blue;">try</span>
            <span style="color:#2b91af;">LicenseManager</span>.Initialize();

            <span style="color:green;">//Instantiate a Pdf object by calling its empty constructor</span>
            <span style="color:#2b91af;">Pdf</span> pdf = <span style="color:blue;">new</span> <span style="color:#2b91af;">Pdf</span>();

            <span style="color:green;">//Create a section in the Pdf object</span>
            <span style="color:#2b91af;">Section</span> section = pdf.Sections.Add();
            section.PageInfo.PageHeight = _pageHeight;
            section.PageInfo.PageWidth = _pageWidth;
            section.PageInfo.Margin.Left = _marginSize;
            section.PageInfo.Margin.Right = _marginSize;
            section.PageInfo.Margin.Top = _marginSize;
            section.PageInfo.Margin.Bottom = _marginSize;

            image = ToAsposeImage(originalContent);

            <span style="color:green;">//Add image object into the Paragraphs collection of the section</span>

            <span style="color:green;">//Save</span>
            outStream = <span style="color:blue;">new</span> <span style="color:#2b91af;">MemoryStream</span>();

            <span style="color:blue;">return</span> outStream.ToArray();
        <span style="color:blue;">finally</span>
            <span style="color:blue;">if</span> (image != <span style="color:blue;">null</span> && image.ImageInfo.ImageStream != <span style="color:blue;">null</span>) image.ImageInfo.ImageStream.Dispose();
            <span style="color:blue;">if</span> (outStream != <span style="color:blue;">null</span>) outStream.Dispose();

This is the line that causes the error:

Attached is the TIFF file that was being placed into the PDF. It was passed as a byte array into the Convert method.

Thank you for your help.


Thanks for using our products.

As far as I can see from the exception message, are you trying to run the application in Medium/Partial trust environment ? Please confirm this so I may share the details about this problem in more appropriate manner. We are really sorry for this inconvenience.

Thank you for your help.

We are running in a full trust environment.

Also because of how our sites are structured right now, the DLL is loaded from GAC and not from the \bin folder.


We are working over this query and will get back to you soon. Please be patient and spare us little time. Currently I have tested the scenario while accessing the product from \bin directory and I am unable to notice any problem. However I am trying to replicate the scenario suing GAC. As soon as we have some updates, I will let you know.

We apologize for this delay and inconvenience.

I am loading from BIN and I am getting this error too.

This happens only when I am converting TIFF to PDF . Actual error comes on Save method.

See attachment.

Any update ...

Hello Vikash,

In case you are trying to access the product from bin directory and only facing issues while converting TIFF image into PDF, then I think there might be some problem with source images. Can you please share the image file causing this problem so that we can test the scenario at our end. We apologize for your inconvenience.


I am creating a console application where I am converting TIFF into PDF and I get this MEthod access exception.

Imput file is attached.

here is the code .... basically a copy from ur documents. I am using evaluation version. Please help me resolve this befor my boss looses patience and decide to move to other product.

static string ConvertTiffToPDF(string filename)


//Instantiate a Pdf object by calling its empty constructor

Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();

//Create a section in the Pdf object

Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

//Create an image object in the section

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image(sec1);

//Add image object into the Paragraphs collection of the section


//Set the path of image file

image1.ImageInfo.File = filename;

//what is the image extension

string targetFilename = string.Empty;

string destfileName = string.Empty;

string extname = string.Empty;

int nextIndex = filename.LastIndexOf('.');

string originalfileName = filename.Substring(0, nextIndex);

extname = filename.Substring(nextIndex, 4);

//Set the type of image using ImageFileType enumeration

image1.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Tiff;

image1.ImageInfo.TiffFrame = -1;

//Save the Pdf

targetFilename = originalfileName + ".pdf";

destfileName = targetFilename;


return destfileName;


Hello Vikash,

Thanks for sharing the resource files. In order to test the scenario, I have placed my Aspose.Pdf.dll v5.1.0 in GAC and in my windows application, I have provided the reference of Aspose.Pdf.dll from $InstallDir\Aspose\Aspose.Pdf for .NET\Bin\net2.0 folder and as per my observations, I am unable to notice any problem. I have tested it over Windows XP SP3 while using Visual Studio 2005. Please take a look over the attached PDF document that I have generated. We apologize for your inconvenience.

However, I will further test the similar scenario over Windows7 using Visual Studio 2010 and will update you with my findings over it.

Did u see the exception screenshot i had attached?... or u think i m just making this up for fun.

by the way, I am doing it in VS2010 Framework 4.0. I guess u r testing on 2.0

Aspose.pdf dlls are in a folder named "Component" ......

lemme know asap if aspose will have any solution or not .... my project is time critical and we can't wait if this is not resolved soon ... we might have to move to some other 3rd party solution

Hello Vikash,

First of all, please accept our humble apologies for the inconvenience that you have been facing in this regard.

I have again tested the scenario using Aspose.Pdf for .NET 5.1.0 over Windows7 Professional 64Bit using Visual Studio 2010 Ultimate and I am still unable to notice the problem.

I have used Aspose.pdf.dll placed under $InstallDir\Aspose.Pdf for .NET\Aspose.Pdf 5.1.0\Bin\net4.0 and I have specified the target framework for my application as .NET Framework 4.0. As per my observations, the PDF document is properly being generated. I think still there might be some other configuration which are missing over my end. Currently if we need to add reference of Apsose.Pdf.dll in our solution in Visual Studio 2010 project, and if the list is filtered to display assemblies targeting .NET Framework 4.0, the product API is not appearing under .NET Tab of "Add reference" dialog. I have logged this problem as PDFNET-26392 in our issue tracking system.

Please take a look over the screen shots of my VisualStudio solution and also the resultant PDF that I have generated. We try our level best to assist each of our customer in best possible way and try our level best to resolve their problems. Please help us in replicating this problem so that we can rectify this issue.

Well. I solved my problem. I guess it was multiplicity of DLL

I am writing a console application. and I was taking .NET 4.0 DLL. I chnaged that to .Net4.0_ClientProfile and it worked.

Note that I am still specifying my Framework as 4.0

Don't know what the difference is but it worked for now.

Question is: If I buy this stuff, will I get all the framework DLL's or there is seperate pricing for this.

Thanks & Regards,


Hello Vikash,

I am glad to hear that your problem is resolved. When you purchase our product, you can use either of .dll present in installation folders. However, I am still not sure about the reasons of this problem and until or unless we are able to replicate it over our end, we might not be able to fix that issue.

Please try using our products and in case you still face any problem or in the event of any further query, please feel free to contact.

Hello Vikash,

I have further investigated this problem and I have managed to reproduce this problem. The issue is occurring when I am using Aspose.Pdf.dll from net4.0 folder and it does not seem to occur, when I have used Aspose.Pdf.dll from net4.0_ClientProfile. For the sake of correction, I have logged it as PDFNET-26494 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. We are really sorry for this inconvenience.

The issues you have found earlier (filed as 26494) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.