//Wcf service, .New Framework 4.0
..
var pdfDocument = new Document();
....
var bmpImageData=new BitmapImageData((Bitmap)pageImage);
....
Exception message:
Attempt by security transparent method 'ceTe.DynamicPDF.Imaging.BitmapImageData.a(System.Drawing.Bitmap)' to access security critical method 'System.Runtime.InteropServices.Marshal.Copy(IntPtr, Byte[], Int32, Int32)' failed.
Assembly 'ceTe.DynamicPDF.40, Version=6.0.2.40, Culture=neutral, PublicKeyToken=09b5ce0d5c0a9d8b' 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.
Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Re: Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Support · Nov 30, 2010Hello,
Can you please send over the input image and the sample code which you are using to our support team at [^a|mailto:support@cete.com|opennewiwndow|support@cete.com^] so that they can look into it further? Also please send over more details about your requirements and tell us what you are trying to achieve using our DynamicPDF products. This information will help us to give you the exact details.
Thanks,
ceTe Software Support Team.
Re: Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Forum member · Dec 1, 2010
Code example web server side:
// Web Application
// .Net Framework 4.0
// DynamicPdf 4.0
// Client Silverlight 4.0 application
public void Print(string outputPath)
{
var pdfDocument = GetPdfDocument(DrawPageImages());
pdfDocument.Draw(outputPath);
}
private IEnumerable<Image> DrawPageImages()
{
Bitmap pageImage = new Bitmap(m_PageLayout.Width, m_PageLayout.Heigth);
pageImage.SetResolution(dpi, dpi);
using (Graphics g = Graphics.FromImage(pageImage))
{
g.Clear(System.Drawing.Color.White);
// draw ...
}
yield return pageImage;
}
private Document GetPdfDocument(IEnumerable<Image> pages)
{
var pdfDocument = new Document();
var pageDimensions = new PageDimensions(
m_PageLayout.PdfPageSize.Width,
m_PageLayout.PdfPageSize.Height);
pageDimensions.SetMargins(m_PageLayout.PdfMarginsLeft, m_PageLayout.PdfMarginsTop, m_PageLayout.PdfMarginsRight, m_PageLayout.PdfMarginsBottom);
foreach (Image pageImage in pages)
{
var pdfPage = new Page(pageDimensions);
// At this point there is an error
var bmpImageData=new BitmapImageData((Bitmap)pageImage);
var pdfImage = new ceTe.DynamicPDF.PageElements.Image(bmpImageData, 0, 0);
pdfImage.SetDpi((float)m_PageLayout.Dpi);
pdfPage.Elements.Add(pdfImage);
pdfDocument.Pages.Add(pdfPage);
}
return pdfDocument;
}
P.S.:
DynamicPdf 2.0 version worked perfectly under Framework 2.0, but with the Framework 4.0 to work declined.
Re: Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Support · Dec 16, 2010Hello,
Our developers are looking into this issue and we will let you know once a fix is available.
Thanks,
ceTe Software Support Team.
Re: Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Forum member · Dec 17, 2010Hi!
I also have the same problem. I found that when creating an Image based on a bitmap I got the same error, ie this would be a problem:
var image = new Image(bitmap, 0,0, 0.5f);
But if I chose to use a memorystream instead everything worked fine:
var image = new Image(new MemoryStream(bytearray), 0, 0, 0.5f);
Hope this might be of help in finding a solution.
Re: Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Support · Dec 17, 2010Hello,
Thanks for the info, we will pass this on to our developers.
Thanks,
ceTe Software Support Team
Re: Error. Creating BitmapImageData to WebApplication .Net Framework 4.0
Support · Jan 19, 2011Hello,
The bug discussed in this post regarding the .NET 4.0 security exception while using the Image and BitmapImageData classes has been fixed and a new build has been released. You can download the new build at: http://www.DynamicPDF.com/downloads/20110119/dynamicpdfcoresuitenetversion602build17388.zip
Thanks,
ceTe Software Support Team.