Aspose Cells security critical exception

Attempting to convert an XLSX file to TIFF but we are receiving the following error. Our application also runs under IIS if that matters.








{“Attempt by security transparent method ‘Š.“.™(System.Drawing.Bitmap)’ to access security critical method ‘System.Runtime.InteropServices.Marshal.Copy(Byte[], Int32, IntPtr, Int32)’ failed.\n\nAssembly ‘Aspose.Cells, Version=8.6.2.0, 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.”}





Throws with a basic excel file such as having “123” in a cell.



Same exception using the WorkBookRender or SheetRender.



Our code is similar to

Stream converted = new MemoryStream();

Workbook book = new Workbook(pathToXlsxInputFile);

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();



foreach (Worksheet sheet in book.Worksheets)

{

SheetRender sr = new SheetRender(sheet, imgOptions);

sr.ToImage(0, converted);

}



imgOptions.SaveFormat = SaveFormat.TIFF;

imgOptions.ImageFormat = ImageFormat.Tiff;

imgOptions.VerticalResolution = 100;

imgOptions.HorizontalResolution = 100;

imgOptions.TiffCompression = TiffCompression.CompressionLZW;

imgOptions.OnePagePerSheet = false;



Worksheet wst = book.Worksheets[0];

SheetRender srt = new SheetRender(wst, imgOptions);

srt.ToImage(0,“test.tiff”);



It does not throw in a test app only on our server. Does Aspose require us to mark security attributes on our assemblies?

Hi,

Thanks for your posting and using Aspose.Cells.

Aspose.Cells needs full trust level to function properly. So if you are running your application in medium trust, then it will give similar exceptions as you have posted. Please run your application in full trust level and see if it makes any difference and resolves your issue.

Please also take a look at this documentation article relating to this topic.

( Declaration|Documentation )

I double checked our IIS settings and our application is running in full trust.



We upgraded from version 8.4.1.0 to 8.6.2.0.



8.4.1.0 works fine but 8.6.2.0 fails.



I noticed there was an update in 8.6.0 (CELLSNET-43869) - Aspose.Cells is not able to run in the Medium Trust



Was Aspose.Cells marked with the AllowPartiallyTrustedCallersAttribute in that fix?

Hi,

Thanks for your posting and using Aspose.Cells.

Yes, this issue CELLSNET-43869 is fixed. Please download and use the latest version:
Aspose.Cells for .NET 8.7.0 it should resolve your issue. Let us know your feedback.

Hi Shakeel,



8.7.0 also throws the same error.



I did some digging and found the following.



Our server houses the Aspose dlls and does all the work. We have a web client, desktop client, API, and multiple test applications.



Our desktop client and API both fail with 8.6.2

Our web client and test application both work with 8.6.2



I found this post from 2011 which said he used the client profile dlls

System.MethodAccessException



I tried the client profile for 8.6.2 which targets .net 3.5 and everything works, I am assuming due it still being level 1 security.

Hi,

Thanks for sharing your valuable findings and using Aspose.Cells.

It seems your issue is resolved with the client profile dlls. Let us know if you are still encountering any issue, we will look into it and help you asap.

Is there a reason behind having the client dll compiled with a different security level?



Is that your intent?



Although the client profile one works for now, with inconsistent behavior based on the one deployed, we are concerned for future releases of dlls.

Hi,


Sorry for replying you late.

Well, our all Aspose.Cells assemblies including client profile Dlls are compiled the same way with similar set of attributes. We provide different Dlls compiled on different .NET framework versions for the users, see the document for your reference. Aspose.Cells assemblies for .NET Framework Client Profile are provided for client applications. You may use it for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Console Applications, Windows Communication Foundation (WCF), etc. This would surely enable faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.

So, you are good to use .NET client profile Dll(s) of Aspose.Cells component for your desktop applications on your production server, there should be no issue.

Thank you.