none
object reference not set to an instance of a object

    Question

  • Hi what can I do for resolve my error : object reference not set to an instance of a object

    Hi, I try to add to my customs control this class:

     

    Imports System.Security.Cryptography

    Imports System.ComponentModel

    <TypeConverter(GetType(SecuritySetting))> _

    Public Class SecurityAlgorithm

    Inherits SymmetricAlgorithm

    Public Overloads Overrides Function CreateDecryptor(ByVal rgbKey() As Byte, ByVal rgbIV() As Byte) As System.Security.Cryptography.ICryptoTransform

    End Function

    Public Overloads Overrides Function CreateEncryptor(ByVal rgbKey() As Byte, ByVal rgbIV() As Byte) As System.Security.Cryptography.ICryptoTransform

    End Function

    Public Overrides Sub GenerateIV()

     

    End Sub

    Public Overrides Sub GenerateKey()

     

    End Sub

    Public Sub New()

    End Sub

    End Class

     

    In my Objectcode I have:

     

    Private _SecurityAlgorithm As New SecurityAlgorithm

     

    #Region "SecurityAlgorithm"

    <TypeConverter(GetType(ObjectConverter))> _

    Public Property SecurityAlgorithm() As SecurityAlgorithm

    Get

    Return _SecurityAlgorithm

    End Get

    Set(ByVal value As SecurityAlgorithm)

    _SecurityAlgorithm = value

    End Set

    End Property

    #End Region

     

    Public Sub New()

    AddHandler (Me.SecuritySetting.AlgorithmeChange), AddressOf catchtype

    End Sub

    Private Sub catchtype(ByVal Encryption As SecuritySetting.PDSAEncryptionType)

    Select Case Encryption

    Case ControlValidator.SecuritySetting.PDSAEncryptionType.DES

    Dim CryptiongMode As New Cryptography.DESCryptoServiceProvider

    _SecurityAlgorithm.Key = CryptiongMode.Key

    Case ControlValidator.SecuritySetting.PDSAEncryptionType.RC2

    Dim CryptiongMode As New Cryptography.RC2CryptoServiceProvider()

    _SecurityAlgorithm.Key = CryptiongMode.Key

    Case ControlValidator.SecuritySetting.PDSAEncryptionType.Rijndael

    Dim CryptiongMode As New Cryptography.RijndaelManaged

    _SecurityAlgorithm.Key = CryptiongMode.Key

    Case ControlValidator.SecuritySetting.PDSAEncryptionType.TripleDES

    Dim CryptiongMode As New Cryptography.TripleDESCryptoServiceProvider

    _SecurityAlgorithm.Key = CryptiongMode.Key

    End Select

    End Sub

     

     

    But when I build my project, and I look property of my class I have these property:

    blocksize

    feedbacksize

    IV (object reference not set to an instance of a object)

    key(object reference not set to an instance of a object)

    keysize

    legalblocksizes(object reference not set to an instance of a object)

    legalkeysizes(object reference not set to an instance of a object)

    mode

    padding

     

    legalblocksizez and legalkeysizes appear in grey

     

    IV and Key dont appear in grey but if I click on the (...)

    that saidSurprisebject reference not set to an instance of a object

     

     

    and for some reason I get this message 6 time per minutes.....

    Code generation for property Key failed. Error was: property accessor KEy on objet controlvalidator.securityalgorihme threw the following exception: object reference not set to an instance of a object

     

     

    I hate this error....

    Somebody can explain me what I can do?

     

    Tuesday, April 24, 2007 6:15 AM

Answers

  • I got this error because I tried to set the data source for a report without first creating a new report object:

    rptPickTicketPgPerSKU1. SetDataSource(Myobj)

     

    This is the solution:

     

    Dim MyRpt As rptPickTicketPgPerSKU = New rptPickTicketPgPerSKU
    MyRpt.SetDataSource(Myobj)
    CrystalReportViewer1.ReportSource = MyRpt

    Friday, April 27, 2007 8:59 PM

All replies

  • This error normal occurs when you have not correctly instantiated a instance of an object.

    an example may be

     

    dim x as form1
      x.showdialog

     

    This will generate the error you talk about because x is simply a variable which can hold a reference to an instance of form1 but it has not been set to anything.   Using the watch window will reveal it contains nothing.

     

    Doing something like

     

    dim x as new form1

    x.showdialog

     

    or

     

    dim x as form1 = new form1

    x.showdialog

     

    will both work as apart from declaring a variable to hold the reference to an instance of form1, you are also instantiating a new instance because you used the NEW keyword.

     

    So my course of action with this problem your having would be to work backwards until you see where the variables are being declared and then where they are being instantiated.   This could be on the same line or could be on different lines.  The most common cause for this is that you have missed out a new keyword somewhere.

     

     

    Wednesday, April 25, 2007 12:57 AM
  • I know thatbut it's exacly the problem.... Inherits from  existing componant and it's the sub property that have problem not the one I create. The problem is on autogenerated subproperty( I think)
    Wednesday, April 25, 2007 1:44 AM
  • That's a difficult one to answer from the contents of your post .. but my best guess would be that you have not called MyBase.New in your constructor which means the _SecurityAlgorithm variable will not be initialised ... which (judging from its declaration) does not appear to be your intent.

     

    Change your constructor to

     

    Public Sub New()

    MyBase.New()

    AddHandler (Me.SecuritySetting.AlgorithmeChange), AddressOf catchtype

    End Sub

     

    Hope it helps.

     

    Richard

    Wednesday, April 25, 2007 11:51 AM
  • I try it but continue to make the same eror.
    Thursday, April 26, 2007 5:30 AM
  • Which line of code errors?
    Thursday, April 26, 2007 10:03 AM
  • It's the problem, none of line make error! That just said randomize error without compilation. Exemple... I play starcraft and I let open visual studio with the project... and starcraft stop and error appear, or i chat on msn, and sudently make error. Each time error appear, that repeat error 2 time. But dont have any line marked as error... If you want to see the project my email is alexqwert55@hotmail.com
    Thursday, April 26, 2007 7:07 PM
  • I'm afraid there is not much information for me to offer any really useful advice.

     

    One of your posts mentioned that it is a problem with the base class.  In the methods that you override .. are you calling the base class method?  I can't tell from your post, but guess you are not because your constructor didn't.

     

    If you override a method and do not call mybase.XXX, you run the risk of the base class state been corrupt.  Might be worth checking which overridden methods have a base implementation that cannot be replaced fully and ensuring you call the base method from your overridden version.

     

    Good luck

     

    Richard

    Friday, April 27, 2007 9:41 AM
  • If you want, I can send you the project, I cant on him now anyway because of this error lol
    Friday, April 27, 2007 6:30 PM
  • I got this error because I tried to set the data source for a report without first creating a new report object:

    rptPickTicketPgPerSKU1. SetDataSource(Myobj)

     

    This is the solution:

     

    Dim MyRpt As rptPickTicketPgPerSKU = New rptPickTicketPgPerSKU
    MyRpt.SetDataSource(Myobj)
    CrystalReportViewer1.ReportSource = MyRpt

    Friday, April 27, 2007 8:59 PM