Hi moondaddy,
Thanks very much for your feedback!
I have received your project, after go through it, I reproduced out your
issue. After doing some research, I found that this problem occurs in
baseFormDE.vb TestBase_Load event. It is caused by the statement below:
Me.BackColor = MyBaseColors.FormBackColor
This "MyBaseColors" class is defined in "Libraries/basGen.vb" file. Then I
looked into this file.
I found that this problem is caused by GetRGBFromString method which is
called in LoadColors method(which is also called in FormBackColor property
in above statement)
Finally, I found that the root cause is that there is an
"NullRerenceException" thrown in GetRGBFromString() method. This is because
the following statement return an empty string:
Dim str As String =
System.Configuration.ConfigurationSettings.AppSettings("AppColors_FormBackCo
lor")
then the empty string is splited and cause the NullRerenceException:
colors = str.Split(",")
Actually, I found that you use ErrLog method to log the exception message
in the ErrorHandler.xml file, if you open this file, you will see a lot of
exception logs. You may place MessageBox.Show(ex.Message) in the exception
handler, then when you open the inherited form, you will see a dialog with
error message:
Private Shared Function GetRGBFromString(ByVal sColor As String) As Color
Try
Dim colors() As String
Dim str As String =
System.Configuration.ConfigurationSettings.AppSettings("AppColors_FormBackCo
lor")
colors = str.Split(",")
'
Dim R As Int32 = colors(0)
Dim G As Int32 = colors(1)
Dim B As Int32 = colors(2)
Dim newColor As Color = Color.FromArgb(R, G, B)
Return newColor
Catch ex As Exception
MessageBox.Show(ex.Message)
ErrLog(ex)
End Try
End Function
==========================================
Cause:
If we run the project, we will find that
System.Configuration.ConfigurationSettings.AppSettings("AppColors_FormBackCo
lor") return the correct string in the app.config, not an empty string. So
the problem only occurs at design-time.
Actually, this is because at design-time, when you inherit from the base
form, the application is at design-time but it is the IDE's runtime, the
code will try to find the config setting in the VS.net IDE process¡¯
(devenv) exe.config not the application's config file, this will fail and
return an empty string.
Solution:
To get rid of the problem, we should disable this code snippet from running
at design-time. We can use Control.DesignMode property to determine if it
is design-time. Just like below:
Private Sub TestBase_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
TT.ShowAlways = True
TT.SetToolTip(Me.btnSave, "Alt-S Save")
TT.SetToolTip(Me.btnDelete, "Alt-D Delete")
TT.SetToolTip(Me.btnUnDo, "Alt-U UnDo")
TT.SetToolTip(Me.btnNew, "Alt-N New")
TT.SetToolTip(Me.btnClose, "Alt-C Close")
TT.SetToolTip(Me.btnGoTo, "Alt-G Go To Selected Record")
If Me.DesignMode = False Then
Me.BackColor = MyBaseColors.FormBackColor
End If
Catch ex As Exception
ErrLog(ex)
End Try
End Sub
===========================================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.