Microsoft Knowledge Base Email Alertz

KBAlertz.com: (814358) - When you try to create an instance of a PropertyItem object in a project that you try to compile, you receive one of the following errors: Visual Basic .NET Error 'System.Drawing.Imaging.PropertyItem.Private Overloads Sub New()' is not accessible in...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 814358 - Last Review: December 3, 2007 - Revision: 2.11

Compile error when you try to create an instance of System.Drawing.Imaging.PropertyItem

On This Page

SYMPTOMS

When 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 Error
error 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 Error
error CS0143: The type 'System.Drawing.Imaging.PropertyItem' has no constructors defined

CAUSE

A 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.

WORKAROUND

To 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. Create a Windows application named PropertyItemDemo by using Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET.

    By default, Form1 is created.
  2. Append the following code to the Form1_Load() event handler:

    Visual Basic .NET or Visual Basic 2005 Sample Code
    Dim pItem As New System.Drawing.Imaging.PropertyItem
    Visual C# .NET or Visual C# 2005 Sample Code
    System.Drawing.Imaging.PropertyItem pItem = new System.Drawing.Imaging.PropertyItem();
  3. On the Build menu, click Build Solution.

    You receive the error mentioned in the "Symptoms" section of this article.

REFERENCES

For additional information, visit the following MSDN Web sites:
PropertyItem Class
http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.propertyitem(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.propertyitem(vs.71).aspx)
4.6 Access Types
http://msdn2.microsoft.com/en-us/library/aa711877(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa711877(VS.71).aspx)
Access Modifiers
http://msdn2.microsoft.com/en-us/library/wxh6fsc7(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/wxh6fsc7(vs.71).aspx)

APPLIES TO
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual Basic 2005
  • Microsoft .NET Framework 2.0
Keywords: 
kbvs2005applies kbvs2005swept kbprogramming kbgdipimaging kbdraw kbprb KB814358
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please