Hello,

Sur le projet qui m'occupe actuellement, j'ai besoin de faire ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    Public Sub CheckForDuplicateSeason(ByRef detailsOwn As List(Of PROMO_DTO.PromoDetailOwn), Optional ByRef detailsDept As List(Of PROMO_DTO.PromoDetailDepartment) = Nothing)
        If detailsDept Is Nothing Then
            Dim data = (From d1 As PROMO_DTO.PromoDetailOwn In detailsOwn
                        From d2 As PROMO_DTO.PromoDetailOwn In detailsOwn
                        Where d1 IsNot d2 And d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select d1)
 
            For Each d As PROMO_DTO.PromoDetailOwn In data.ToList
                d.ErrorText = "saison"
            Next
        Else
            Dim data = (From d1 As PROMO_DTO.PromoDetailOwn In detailsOwn
                        From d2 As PROMO_DTO.PromoDetailDepartment In detailsDept
                        Where d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select d1)
 
            For Each d As PROMO_DTO.PromoDetailOwn In data.ToList
                d.ErrorText = "saison"
            Next
        End If
    End Sub
En l'état, VS me fait la gueule et souligne, dans les deux branches du If, la source de la 2e liste de ma query sous prétexte que c'est un paramètre ByRef. Or la source de la première ligne l'est tout autant (surtout qu'il s'agit de la même liste dans le premier cas).

En soit, ce n'est pas bien grave, je peux faire comme indiquer dans la MSDN et modifier mon code comme suit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    Public Sub CheckForDuplicateSeason(ByRef detailsOwn As List(Of PROMO_DTO.PromoDetailOwn), Optional ByRef detailsDept As List(Of PROMO_DTO.PromoDetailDepartment) = Nothing)
        Dim dto As List(Of PROMO_DTO.PromoDetailOwn) = detailsOwn
        If detailsDept Is Nothing Then
            Dim data = (From d1 As PROMO_DTO.PromoDetailOwn In detailsOwn
                        From d2 As PROMO_DTO.PromoDetailOwn In detailsOwn
                        Where d1 IsNot d2 And d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select d1)
 
            For Each d As PROMO_DTO.PromoDetailOwn In data.ToList
                d.ErrorText = "saison"
            Next
        Else
            Dim ddp As List(Of PROMO_DTO.PromoDetailDepartment) = detailsDept
            Dim data = (From d1 As PROMO_DTO.PromoDetailOwn In detailsOwn
                        From d2 As PROMO_DTO.PromoDetailDepartment In detailsDept
                        Where d1.Seasons.Intersect(d2.Seasons).Count > 0
                        Select d1)
 
            For Each d As PROMO_DTO.PromoDetailOwn In data.ToList
                d.ErrorText = "saison"
            Next
        End If
    End Sub
Mais j'aimerais bien comprendre le pourquoi malgré tout. Il doit sûrement y avoir une très bonne raison derrière tout ça mais avec le peu d'info que j'ai, cette erreur n'a aucune raison d'être...