Forum  Commercial Foru...  Commercial Foru...  failed to create component
Previous Previous
 
Next Next
New Post 1/27/2012 4:47 AM
  sramirez@dynacal.com
381 posts
3rd Level Poster


failed to create component 

I have a usercontrol that I am trying to add to a form.

When I try to drag the control from the toolbar to the form I get: 

Failed to create component 'ucRCRTab2'. The error message follows: 'System.NullReferenceException: Object reference not set to an instance of an object at AdminSide.dcSession.get_OrgID ......

The place it points to is:

    Public Property OrgID As Integer
        Get
            Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")    <---- this line
        End Get
        Set(ByVal value As Integer)
            Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID") = value
        End Set
    End Property

 

If I change

       Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")

to

     Return 0

and recompile then i can drag the control to my form.

Why is this happening?

I am running Pro Studio 6.4.0 Release JQT Beta2b for .net 4.0

Thanks

Shawn

 
New Post 1/27/2012 12:18 PM
  palli
11824 posts
1st Level Poster




Re: failed to create component 

Hi Shawn,

This is quite normal, as the designtime will invoke the Getter of your property, but at designtime the VWGContext is not instanciated, so you will get this error.

You will need to handle the design case in such a way that it doesn't rely on VWGContext. You can use a "if DesignMode" test in most cases. Please note that wihin the constructor of controls, the DesignMode has not been set correctly, so it will not be of any value to you. In such cases, and I belive it will apply to yours, you will have to use something like "if Gizmox.WebGUI.Forms.VWGContext isnot nothing" etc.

Hope this helps,

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 1/28/2012 2:52 PM
  sramirez@dynacal.com
381 posts
3rd Level Poster


Re: failed to create component 
Modified By sramirez@dynacal.com  on 1/28/2012 8:34:54 PM)

I tried 2 different things and neither of them worked.

I tried

If DesignMode = True Then

   return 0

else
                    Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")

end if

this method didn't work

 

I also tried

    Public Property OrgID As Integer
        Get
            If System.ComponentModel.LicenseManager.UsageMode = ComponentModel.LicenseUsageMode.Designtime Then
                Return 0
            Else

                Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")
            End If
        End Get
        Set(ByVal value As Integer)
            Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID") = value
        End Set
    End Property

This method did not work either

 

The error message is the same as before.

I might add that the user control I am trying to add to the form is

ucRCRTab2

it calls dcSession, (a class that inherits from usercontrol), and dcSession is what is throwing the error with the line

 Public Property OrgID As Integer
        Get
            If System.ComponentModel.LicenseManager.UsageMode = ComponentModel.LicenseUsageMode.Designtime Then
                Return 0  <-- this is the line throwing the error
            Else
                Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")
            End If
        End Get
        Set(ByVal value As Integer)
            Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID") = value
        End Set
    End Property

Here is the error http://www.mediafire.com/?6x4ak5nm55gycng

Thanks for any help.

 
New Post 1/29/2012 11:13 AM
  palli
11824 posts
1st Level Poster




Re: failed to create component 

Hi Shawn,

Like I said in my earlier reply, if your code is used as a part of the contstructor's code execution, then you do not have a reliable DesignMode setting, it's value is set after the constructor has been invoked. Your public property's getter will be accessed as a part of the serialization process when the designer is writing it's designer generated code, and you may also have to protect the setter, as when you load a form that has a value assigned to this property within the designer generated code, the designer will access the setter.

This means, you best option is to use:

            If VWGContext.Current Is Nothing Then
                Return 0
            Else
                Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")
            End If
 

As you want this property to get it's initial value from the current context at runtime, I think it's a good idea to set an attribute for the property to prevent the designer from writing it's value to the designer generated code, which means you don't urgently have to protect the setter from the designer. To accomplish this, you place a DesignerSerializationVisibility attribute on the property, like this:

    <System.ComponentModel.DesignerSerializationVisibility(ComponentModel.DesignerSerializationVisibility.Hidden)> _
    Public Property OrgID() As Integer
 

You can see more on this attribute on MSDN here.

Regarding your use of System.ComponentModel.LicenseManager.UsageMode, then I don't think it will be of any value for you in this context, as you can see in this MSDN article here.

Hope this helps,

Palli

 

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 1/29/2012 1:03 PM
  sramirez@dynacal.com
381 posts
3rd Level Poster


Re: failed to create component 

Thanks for all the help!

I have changed my code to the following and it works now. 

<ComponentModel.DesignerSerializationVisibilityAttribute(ComponentModel.DesignerSerializationVisibility.Hidden)> _
    Public Property OrgID As Integer
        Get
            If VWGContext.Current Is Nothing Then
                Return 0
            Else
                Return Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID")
            End If
        End Get
        Set(ByVal value As Integer)
            Gizmox.WebGUI.Forms.VWGContext.Current.Item("OrgID") = value
        End Set
    End Property

 
Previous Previous
 
Next Next
  Forum  Commercial Foru...  Commercial Foru...  failed to create component
CompanionKit Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS