Udostępnij za pośrednictwem


Getting “Derived types must either match the security accessibility of the base type or be less accessible” exception after migrating VSTO add-in project to Visual Studio 2010 and targeting it to .Net 4.0 Framework.

We are getting following exception after migrating Outlook 2007 VSTO add-in project to Visual Studio 2010 and targeting it to .Net 4.0 Framework for
Outlook 2010: Inheritance security rules violated by type: 'VS2008_FR_OLAddIn.ThisAddIn'. Derived types must either match the security accessibility of the base type or be less accessible.

************** Exception Text **************

System.TypeLoadException: Inheritance security rules violated by type: 'VS2008_FR_OLAddIn.ThisAddIn'. Derived types must either match the security accessibility of the base type or be less accessible.

at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)

at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)

at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.CreateEntryPoint(String entryPointTypeName)

at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.LoadEntryPoints(IntPtr serviceProvider)

 

The above issue is happening in case if we upgrade an Office project from Visual Studio 2008. In this case, you must remove the SecurityTransparentAttribute.

Visual Studio does not automatically remove these attributes when the target framework is changed.

StepsTo remove the SecurityTransparentAttribute

  • With the project open in Visual Studio, open Solution Explorer.
  • Under the Properties node (for C#) or the My Project node (for Visual Basic), double-click the AssemblyInfo code file to open it in the code editor.
  • Locate the SecurityTransparentAttribute and either remove it from the file or comment it out.

For more detail refer @ Removing Obsolete Attributes from Office Projects that You Migrate to the .NET Framework 4.

 

We would also need to keep in consideration Required Changes to Run Office Projects that You Migrate to the .NET Framework 4 to avoid other issue.

Hope this helps!!!

Comments

  • Anonymous
    May 30, 2010
    Thank you very much! I had no idea on how to solve this one...
  • Anonymous
    November 09, 2011
    Hello,There's no [assembly: SecurityTransparent()] attribute in my AssemblyInfo.cs.Please help me..Are there other ways??
  • Anonymous
    May 13, 2013
    Inheritance security rules violated by type: 'MyService.Service'. Derived types must either match the security accessibility of the base type or be less accessibleFor this GO to Project Properties ->Security->uncheck Enable Click One Security Settings..Then the problem got solved.....