Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

ISSUE/BUG Report X509CertificateCollection.Remove/Contains

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vecozo@online.nospam - 04 Aug 2005 19:32 GMT
LS,

The  X509CertificateCollection.Remove and X509CertificateCollection.Contains
are not consistent with each other. Although a X509CertificateCollection
reports that it contains a certificate, it might not be able to remove this
certificate with exception "Cannot remove the specified item because it was
not found in the specified Collection". I believe this is not consistent with
ICollection interface / pattern. Please correct me if I am wrong.

See code snippet below:
_____________________________________
public void Reproduce( X509Certificate certificate )
        {
System.Security.Cryptography.X509Certificates.X509CertificateCollection coll
= new X509CertificateCollection ();

System.Security.Cryptography.X509Certificates.X509Certificate
otherCeritificate = new X509Certificate (certificate);

coll.Add ( certificate );
               
System.Diagnostics.Debug.WriteLineIf ( coll.Contains ( otherCeritificate ),
"*Collection contains otherCertificate" );
               
try
{
    coll.Remove ( otherCeritificate );
}
catch ( Exception e )
{
    System.Diagnostics.Debug.WriteLine ( string.Format ( "*An  exception
occured while removing otherCertificate from the collection. Message: {0}.",
e.Message ) );
}

}

_____________________________________

This prints:

*Collection contains otherCertificate
*An  exception occured while removing otherCertificate from the collection.
Message: Cannot remove the specified item because it was not found in the
specified Collection..
_____________________________________

Our Fix:

// Workaround.
for ( int i = 0; i < certificateCollection.Count; i++ )
{
    if ( certificateCollection[i].Equals ( certificate ))
    {
        certificateCollection.RemoveAt ( i );
        break;
    }
}

Not too pretty, but it works.

Regards,
Martijn Kaag
______________________________
www.VECOZO.nl
"Peter Huang" [MSFT] - 05 Aug 2005 07:34 GMT
Hi Martijn,

I can reproduce with your code, and I have reported the issue to our
product team.
Thanks for your feedback.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.