locked
that assembly does not allow partially trusted callers. RRS feed

  • Question

  • I have a web part that calls into Microsoft.Office.Interop.Outlook compiles with no warnings or errors.  When run in SharePoint I recieve the error: "that assembly does not allow partially trusted callers"

     

    What I am doing is sending a mailitem w/appointment.ForwardAsVcal() ....

     

    This is SharePoint 2007 and Outlook 2007 installed on the same Windows 2003 server.  Simply creating an instance of  Outlook.Application will cause the error.

     

    What to do?

     

    My humble thanks in advance,

    Monday, May 12, 2008 7:29 PM

Answers

  • You'll need to deploy your webpart to the GAC so it's not called by a partial trust application.

     

     

    Tuesday, May 13, 2008 8:38 PM
  • At first glance it looks like your assembly is failing code access security checks. First steps,

    1. sign your assembly
    2. add the following attribute to your AssemblyInfo.cs file (if you're in C#)
    [assembly: AllowPartiallyTrustedCallers()]
    or
    <Assembly:AssemblyName("MyAssembly")>
    in vb

    rebuild and try again. That, I believe, should do the trick if your code is the failing point. If that doesn't work please provide as much error detail as you safely can and I'll take a look (or someone smarter than I will jump in here! Smile )

    HTH,

    Leon
    Monday, May 12, 2008 8:50 PM
  • The assembly is signed.  I have tried with and without AllowPartiallyTrustedCallers.  With it true the error talks about the conflict with the outlook object which does NOT allow partially trusted callers ....

     

    Here is the code that  causes the error.  As I said simply instatiating the outlook obj will cause the error. 

     

    Microsoft.Office.InterOp.Outlook.Application outlookApp =

    new Microsoft.Office.InterOp.Outlook.Application ();

     

    Microsoft.Office.InterOp.Outlook.AppointmentItem oAppointment =

    (Microsoft.Office.InterOp.Outlook.AppointmentItem) outlookApp.CreateItem(Microsoft.Office.InterOp.Outlook.OlItemType.olAppointmentItem);

     

    oAppointment.Subject = "This is the subject for my appointment";
    oAppointment.Body = "This is the body text for my appointment";
    oAppointment.Location = "Appointment location";

    oAppointment.Start = Convert.ToDateTime ("10/10/2004 10:00:00 AM");
    oAppointment.End = Convert.ToDateTime ("10/10/2004 2:00:00 PM");
    oAppointment.Importance = Microsoft.Office.InterOp.Outlook.OlImportance.olImportanceHigh;

    oAppointment.BusyStatus = Microsoft.Office.InterOp.Outlook.OlBusyStatus.olBusy;

    Microsoft.Office.InterOp.Outlook.MailItem mailItem = oAppointment.ForwardAsVcal ();
    mailItem.To =
    not@all.funny;
    mailItem.Send ();

    Same error message

     

    Thanks for your help,

    Tuesday, May 13, 2008 4:48 PM

All replies

  • At first glance it looks like your assembly is failing code access security checks. First steps,

    1. sign your assembly
    2. add the following attribute to your AssemblyInfo.cs file (if you're in C#)
    [assembly: AllowPartiallyTrustedCallers()]
    or
    <Assembly:AssemblyName("MyAssembly")>
    in vb

    rebuild and try again. That, I believe, should do the trick if your code is the failing point. If that doesn't work please provide as much error detail as you safely can and I'll take a look (or someone smarter than I will jump in here! Smile )

    HTH,

    Leon
    Monday, May 12, 2008 8:50 PM
  • The assembly is signed.  I have tried with and without AllowPartiallyTrustedCallers.  With it true the error talks about the conflict with the outlook object which does NOT allow partially trusted callers ....

     

    Here is the code that  causes the error.  As I said simply instatiating the outlook obj will cause the error. 

     

    Microsoft.Office.InterOp.Outlook.Application outlookApp =

    new Microsoft.Office.InterOp.Outlook.Application ();

     

    Microsoft.Office.InterOp.Outlook.AppointmentItem oAppointment =

    (Microsoft.Office.InterOp.Outlook.AppointmentItem) outlookApp.CreateItem(Microsoft.Office.InterOp.Outlook.OlItemType.olAppointmentItem);

     

    oAppointment.Subject = "This is the subject for my appointment";
    oAppointment.Body = "This is the body text for my appointment";
    oAppointment.Location = "Appointment location";

    oAppointment.Start = Convert.ToDateTime ("10/10/2004 10:00:00 AM");
    oAppointment.End = Convert.ToDateTime ("10/10/2004 2:00:00 PM");
    oAppointment.Importance = Microsoft.Office.InterOp.Outlook.OlImportance.olImportanceHigh;

    oAppointment.BusyStatus = Microsoft.Office.InterOp.Outlook.OlBusyStatus.olBusy;

    Microsoft.Office.InterOp.Outlook.MailItem mailItem = oAppointment.ForwardAsVcal ();
    mailItem.To =
    not@all.funny;
    mailItem.Send ();

    Same error message

     

    Thanks for your help,

    Tuesday, May 13, 2008 4:48 PM
  • You'll need to deploy your webpart to the GAC so it's not called by a partial trust application.

     

     

    Tuesday, May 13, 2008 8:38 PM
  • This is the real solution. 

     

    Thanks,

    Wednesday, May 14, 2008 10:06 PM