Compile error when you try to create an instance of System.Drawing.Imaging.PropertyItem (814358)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# 2005, Express Edition
- Microsoft Visual Basic 2005
- Microsoft .NET Framework 2.0
SYMPTOMSWhen you try to create an instance of a PropertyItem object in a project that you try to compile, you receive one of
the following error messages: Visual Basic .NET Error'System.Drawing.Imaging.PropertyItem.Private
Overloads Sub New()' is not accessible in this context because it is
'Private'. Visual Basic 2005 Errorerror BC30251: Type 'System.Drawing.Imaging.PropertyItem' has no constructors. Visual C# .NET Error'System.Drawing.Imaging.PropertyItem.PropertyItem()' is
inaccessible due to its protection level. Visual C# 2005 Errorerror CS0143: The type 'System.Drawing.Imaging.PropertyItem' has no constructors defined CAUSEA PropertyItem object encapsulates a metadata property to be included in an
image file. A PropertyItem object is not intended to be used a stand-alone object. A PropertyItem object is intended to be used by classes that are derived from System.Drawing.Image. A PropertyItem object is used to retrieve and change the metadata of existing
image files, not to create the metadata. Therefore, the PropertyItem class does not have a defined Public constructor, and you cannot
create an instance of a PropertyItem object.WORKAROUNDTo work around this problem, use an existing PropertyItem object instead of creating a new instance of the PropertyItem class. To do this, use the following code sample: Visual Basic .NET or Visual Basic 2005 Sample Code ' Create a Bitmap Image to access a PropertyItem object.
Dim MyImage As System.Drawing.Bitmap
MyImage = New System.Drawing.Bitmap("C:\Sample.jpg") ' Refer to some existing .JPEG image.
' Define a PropertyItem variable.
Dim pItem As System.Drawing.Imaging.PropertyItem
' Instead of creating a new instance of PropertyItem, use an existing PropertyItem object.
For Each pItem In MyImage.PropertyItems
' You can modify the pItem object now.
Exit For
Next Visual C# .NET or Visual C# 2005 Sample Code // Create a Bitmap Image to access a PropertyItem object.
System.Drawing.Bitmap MyImage;
MyImage = new System.Drawing.Bitmap("C:\\Sample.jpg"); // Refer to some existing .JPEG image.
// Define a PropertyItem variable.
// Instead of creating a new instance of PropertyItem, use an existing PropertyItem object.
foreach (System.Drawing.Imaging.PropertyItem pItem in MyImage.PropertyItems)
{
// You can modify the pItem object now.
break;
} Note For this code to work correctly, you should have a reference to
the System.Drawing.dll assembly. STATUS This
behavior is by design.REFERENCESFor additional information, visit the following MSDN Web
sites:
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005applies kbvs2005swept kbProgramming kbgdipimaging kbdraw kbprb KB814358 kbAudDeveloper |
---|
|