Stange and complicated

H

Henrry Pires

Hello to all.

I have and strange and complicated problem.



My asp.net application raise errors when the data that the user input is
invalid. For example: The user didn't fill all some data (customer name or
SSN and so on). I have a class that try to validate the data and is
something is wrong it raises an error. That error is a class that I made,
this class inherits from System.Exceptio. So far so good.

It works fine, but only in 2 classes it doesn't work. I fire my error when
the data isn't correct but in the webpage the error is an
System.Reflection.TargetInvocationException that has as a inner exception
the error that I fire.





I will put some code to make it clear



WEB FORM



Private sub SaveData()



Declare BRL as NEW Customer



'Fill the brl object

With BRL

.Name = txtName.Text

.SSN = txtSSN.Text

...

End With



Try



BRL.CheckSaveRules

BRL.Save



Catch ex As ValidationRowException

'Display an alert message to the user

ShowMessage(ex.Message, Page_MessageBox.MsgType.CriticalInformation)

Catch ex As System.Reflection.TargetInvocationException

'this catch it wasn't suppose to exist.

'This is the error that the web form catch and I don't know why.

Catch ex As Exception

ShowUnKnowError

Finally

BRL.Dispose()

End Try



End sub



BRL



Public sub CheckSaveRules



'Creates an instance of the validator object and get the not null fields of
this dataTable

Dim validation As New RecordCommonValidation(GetRequiredFields)

'Gets a row with all the data to be validated

Dim row As DataRow = FillTableOP()



'Calls the validate method of the Validation Class

validation.Validate(row)¨



'Some other validations

....



End sub



FramekWork Validation Class



Public Sub Validate(ByVal RowToValidate As DataRow)



'Check each cell of the row and if any of the are null (and it wasn't
suppose to be null) raises the error



Throw New ValidationRowException(Enums.RowFailType.NotField,
Consts.NotFillMessage)

...

End sub



It is a long post I know but I don't know what else I can try to resolve
this strange thing.
 
K

Karl Seguin [MVP]

It's a tricky one, but I have a number of guesses

I doubt this is it, but make sure Dispose() isn't the problem
Also, it's possibly an issue with exception serialization. Your custom
exceptions should implement ALL exception constructors as they are used
internally by the .net framework only god (brad adams) knows how. HEre's a
pretty good post which covers it:
http://software.gurock.com/articles/creating-custom-exceptions-in-dotnet/

Also, remember that BRL was disposed of after the finally, so you can't be
using it later on.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top