Why do I get a TypeLoadException when moving my project to .NET 4?

There have been some security changes in the .NET 4.0 Framework, so when moving a project to .NET 4.0 you may get the following exception:

TypeLoadException – Derived Types must either match the security accessibility of the base type or be less accessible.

There are two approaches to fixing this problem:

1. If you are you using the SecurityTransparentAttribute in your project’s AssemblyInfo.cs/vb file you need to remove this attribute since it’s now obsolete in the .NET 4 Framework.

2. If this isn’t the case, try adding the following attribute to your project’s AssemblyInfo.cs/vb file to get past the exception:

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

For more information, check out this MSDN topic: http://msdn.microsoft.com/en-us/library/dd233102(VS.100).aspx

Best Regards,
Kevin McNeish
INETA Speaker
President, Oak Leaf Enterprises, Inc.
Home of the MM .NET Framework

One thought on “Why do I get a TypeLoadException when moving my project to .NET 4?

Leave a Reply

Your email address will not be published. Required fields are marked *