Hi !
I have built an Add-in for VS.NET 2003 which adds or updates the
StrongNameIdentityPermissionAttribute in all the classes of the selected
project in a solution. When the classes don't have the attribute, is is
added fine, but in the code that updates the attribute, I am having a slight
problem, since when I try to cast the read attribute to a
StrongNameIdentityPermissionAttribute it throws an invalid cast exception.
Can someone help me ? The below code is where the error occurs:
If CurrentClass.Attributes.Count > 0 Then
'-- For the current class, see if the attribute
StrongNameIdentityPermissionAttribute exists and act accordingly
For Each CurrentAttribute As CodeAttribute In CurrentClass.Attributes
'-- If the attribute already exists, change it to the new public key
If CurrentAttribute.Name.IndexOf("StrongNameIdentityP ermission")
<> -1 Then
Dim NewAttribute As
System.Security.Permissions.StrongNameIdentityPerm issionAttribute
'-- *** ERROR occurs in line below ***
NewAttribute = CType(CurrentAttribute,
System.Security.Permissions.StrongNameIdentityPerm issionAttribute)
NewAttribute.Action =
Security.Permissions.SecurityAction.LinkDemand
NewAttribute.PublicKey = Key
CurrentAttribute = NewAttribute
Log.Write("Updated public key in class: " & CurrentClass.Name,
NewKey.DTE.Solution.FullName & ".log")
AttFound = True
End If
Next
End If
--
*****************************************
Mário Sobral
www.MarioSobral.com
www.CBRWorld.net
www.PerformanceTotal.com
*****************************************