Exception while debugging using windows MAF (AddIn pipeline)

0

I have been trying to build a AddIn architecture and was using the MAF. The basics that I have followed are given here on Microsoft docs

Brief background about the application:

  1. I have a wpf host application, which will load the addIn assembly at runtime. The addIns implement a contract (Interface) and is decorated with an attribute which helps the host to discover it. These are standard thing under MAF so do not want to put more here, but if it will help will clarity then happy to put more in. The application Host/AddIns are all on my laptop which I am running under admin profile.

While loading the AddIns, the main code in the host is:

    string appPath = Environment.CurrentDirectory + "\\Pipeline";
    string[] warnings = AddInStore.Rebuild(appPath);
       if (warnings.Length > 0)
          {
             string msg = "Could not rebuild pipeline:";
             foreach (string warning in warnings) msg += "\n" + warning;
             MessageBox.Show(msg);
             return;
          }

   Collection<AddInToken> addInTokens = AddInStore.FindAddIns(typeof(IWPFAddInHostView), appPath);

   AddInToken wpfAddInToken = addInTokens[0];

   // the only line I can see that has something to do with
   // security permissions
   this._wpfAddInHostView = wpfAddInToken.Activate<IWPFAddInHostView>(AddInSecurityLevel.Internet);

   FrameworkElement addInUI = this._wpfAddInHostView.GetAddInUI();
                this.addInUIHostGrid.Children.Add(addInUI);

This code works fine (loads addIn and on the click of a button in addIn UI pops the expected message box) when I run it, but in debug mode it gives the following exception and crashes (it loads the addIn properly but on clicking the button the exception happens), I have marked the only line having to do with security permissions above, not sure why this should happen only in debug mode and even why it is happening.

Also, I know not 2 questions in a question, but I have not seen many people use MAF and the product page says no active support, wonder if I am making the wrong choice.

System.Security.SecurityException HResult=0x8013150A
Message=Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source= StackTrace:

c#
wpf
add-in
maf
asked on Stack Overflow Apr 7, 2019 by peeyush singh • edited Apr 7, 2019 by peeyush singh

1 Answer

0

Changing the security permission

 this._wpfAddInHostView = wpfAddInToken.Activate<IWPFAddInHostView>(AddInSecurityLevel.Internet);

to full trust works.

this._wpfAddInHostView = wpfAddInToken.Activate<IWPFAddInHostView>(AddInSecurityLevel.FullTrust);

So, apparently this has to do with internet security level would be partial trust. But I am still curios that why this exception occurs only when I run the system in debug mode?

answered on Stack Overflow Apr 7, 2019 by peeyush singh

User contributions licensed under CC BY-SA 3.0