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:
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:
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?
User contributions licensed under CC BY-SA 3.0