Error "That assembly does not allow partially trusted callers"

The error i get is "System.Security.SecurityException: That assembly does not allow partially trusted callers"

The Code Is as follows

 Dim doc As Document = New Document
        Dim PDFMemoryStream As MemoryStream = New MemoryStream()
        'PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\1.pdf", FileMode.Create))
        Dim MyPdfWriter = PdfWriter.GetInstance(doc, PDFMemoryStream)
        MyPdfWriter.CloseStream = False

        doc.Add(New Paragraph("This Is A Test"))

        PDFMemoryStream.Position = 0

        Dim bytes As Byte() = PDFMemoryStream.ToArray

        'Use the following to create on the fly without saving
        Response.ContentType = "application/pdf"
        Response.AddHeader("Content-Disposition", "attachment;filename=\Invoice.pdf")
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
It looks like you are using an assembly which is not signed (the one housing PDFMemoryStream). You may have to change the security policy for .NET on your web server, but you might try this first:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
taz8020Author Commented:
I have checked the trust level in IIS7 and its set to full(internal) any ideas?
taz8020Author Commented:
Hi Thanks all, it was the trust isssue. Iw was set to full intenal but when set to just full then it worked.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.