1

In my code, I have a reference variable LogValidacionPagosDTO

public void InsertarArchivoXmlOk(ArchivoXmlDRO archivo, ref LogValidacionPagosDTO archivoRespuesta)
{
   //Some code
}

When executing "code analysis" generates this warning

Warning CA1062  
In externally visible method 'ArchivoXMLOperacion.ValidacionDuplicadosArchivoXmlFosyga(List<RegistroXmlFosygaDRO>, ref LogValidacionPagosDTO)', 
validate local variable ''(*archivoRespuesta)'', which was reassigned from parameter 'archivoRespuesta', before using it.

Then try to validate the object as null

public void InsertarArchivoXmlOk(ArchivoXmlDRO archivo, ref LogValidacionPagosDTO archivoRespuesta)
        {
            if (archivoRespuesta == null || archivoRespuesta.DetalleRegistros == null)
                        throw new ExcepcionOperacion(HelperMensaje.Obtener(HelperCodigoMensaje.GEN_0003),
                                                   (int)CodigosHTTP.Error, archivoRespuesta, null);
            //Some code
        }

But this didn't solve the warning. I found this possible solution in Microsoft forum https://social.msdn.microsoft.com/Forums/en-US/fdb00899-c7ea-4e8e-b5f6-9768c2ac0001/ca1062-false-positive-in-externally-visible-method-xxx-validate-local-variable-x-which-was?forum=vstscode

But, I really need to know if this is a false positive, thks!

makitocode
  • 938
  • 1
  • 16
  • 40
  • 1
    There's also a similar issue cited on SO that appears to be a bug with MSVS: https://stackoverflow.com/questions/2860979/why-do-i-get-code-analysis-ca1062-on-an-out-parameter-in-this-code – paulsm4 Aug 17 '17 at 00:32

0 Answers0