Bonjour à tous,

J'ai une nouvelle fois besoin de vos lumières.

J'ai un problème avec un fonction de sauvegarde en base de données que j'appelle avec un InvokeMember. Cette fonction s'appelle bien mais génère une exception qui apparemment est catché avant le retour dans mon code.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Try
    For Each obj As Object In listObjects
         If (obj.GetType().BaseType.Name = GetType(EntityCollectionBase(Of )).Name) Then
              transaction.Add(obj)
              obj.GetType().InvokeMember("SaveMulti", BindingFlags.InvokeMethod, Nothing, obj, Nothing)
         Else
              transaction.Add(obj)
              obj.GetType().InvokeMember("Save", BindingFlags.InvokeMethod, Nothing, obj, Nothing)
         End If
    Next
    transaction.Commit()
Catch ex As Exception
    transaction.Rollback()
End Try
Lorsque l'objet existe déjà en base (ce qui est normal), il sort une exception du type :
SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException was unhandled by user code
Message=An exception was caught during the execution of an action query: Violation of PRIMARY KEY constraint ''. Cannot insert duplicate key in object.
The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
Mais bon, moi j'aimerais bien quelle passe dans mon catch cette petite...ce qu'elle ne fait pas.

J'ai essayé de la lancer à partir d'un objet (sans reflexion), et je peux catcher l'exception...pourquoi pas là ?

(Si j'ai pas été clair, désolé, il fait chaud )