AttachmentCollection attachmentCollection in C#
c#, visual-studio, visual-studio-2008
Solution
Some types aren't designed to be instantiated.
They might be Abstract, meaning that you are expected to extend the class and fill in some of its functionality.
They might also require some extensive work to get them created correctly. Those types often expose public static methods or have factories which you can use to instantiate them.
The docs state that "Instances of the AttachmentCollection class are returned by the MailMessage.AlternateViews and MailMessage.Attachments properties." Seems like the designers didn't want you to create this collection; its purpose is to be used only with the MailMessage class.
Let the MailMessage class handle its AttachmentCollections for you. Create an instance of MailMessage and then fill in AlternateViews and Attachments, rather than create the collection, fill it in and then assign it to the properties.
One last thing, most public properties that are collections don't have setters. Its considered a bad design to allow users of your types to be able to set or even null out your public collection properties.
Problem
I am trying to utilize the AttachmentCollection Class in C# and when I try to create a new instance of it it gives me an error saying "Error 32 The type 'System.Net.Mail.AttachmentCollection' has no constructors defined".... Here is what I was trying, how to a create a new instance of this if there are no constructors defined ? ``` AttachmentCollection attachmentCollection = new AttachmentCollection(); ``` Thanks for your help!