"Inheritance security rules violated while overriding member: 'PublicDomain.ReadOnlyDictionary`2<TKey


Problem when moving to the .Net Framework 4.5. Full error is:

{"Inheritance security rules violated while overriding member: 'PublicDomain.ReadOnlyDictionary2<TKey,TValue>.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'.
Security accessibility of the overriding method must match the security accessibility of the method being overriden.":


andyrivera255 wrote Oct 1, 2013 at 12:54 AM

Here is the solution:
  1. Open ReadOnlyDictionary.cs and scroll to 400 (it says public void GetObjectData) it needs the following added right above: [System.Security.SecuritySafeCritical]
Here are more details about the fix from Microsoft: http://msdn.microsoft.com/en-us/library/system.security.securitysafecriticalattribute.aspx

andyrivera255 wrote Oct 15, 2013 at 1:20 AM

Well this broke again when I moved to framework 4.5 and it seems that marking the whole assembly to use the old security rules will be better. So you can go to readonlydictionary.cs and add the line right before the namespace line (after the using, before the "namespace PublicDomain"
[assembly: SecurityRules(SecurityRuleSet.Level1)]

More info here: http://blogs.msdn.com/b/shawnfa/archive/2009/11/12/differences-between-the-security-rule-sets.aspx