Type used in a using statement must be implicitly convertible to System.Idisposible

1

I want to create an object of type HistoryDA to then send a method call of that object, but I mark the following error when trying to do it:

Type used in a using statement must be implicity convertible to System.Idisposible

Class Code HistoryBI:

 public static BaseErrorResult InsertHistory(int idVehiculo, DateTime FechaC, DateTime FechaV, int QR, string FotografiaE, string status, string dueño)
    {
        try
        {
            using (var da = new HistoryDA())
            {
                 da.InsertHistoryDA(idVehiculo,FechaC,FechaV,QR,FotografiaE,status,dueño);
            }
            return new BaseErrorResult();
        }
        catch (Exception ex)
        {
            return new BaseErrorResult(ex);
        }
    }

Class Code HistoryDA:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ned4Models;
using Ned4Models.PruebasQR;

namespace Ned4DataAccess.PruebaQR
{
    class HistoryDa
    {
        public HistoryDa()
        {

        }

        public void InsertHistory(int idV, DateTime fechaC, DateTime fechaV, int QR, string FotoE, string status, string dueno)
        {

           Historico history = new Historico();

            idV = history.VehiculoId;
            fechaC = history.FechaCreacion;
            fechaV = history.FechaVigencia;
            QR = history.CodigoQR;
            FotoE = history.FotografiaEvidencia;
            status = history.Estatus;
            dueno = history.Dueño;
        }

    }
}
    
asked by David 09.05.2018 в 19:37
source

1 answer

1

When using the using clause, the object is expected to implement the IDisposable interface and therefore implement a Dispose method.

using (var da = new HistoryDA())
{
   ...
}

This means that when you finish executing the code inside the keys of using the dispose method will be automatically called on the object inside the parentheses, in your case, about da .

Since the HistoryDA class does not implement IDisposable , it can not be used in a using clause.

Then you have 2 options, remove the using :

var da = new HistoryDA()
da.InsertHistoryDA(idVehiculo,FechaC,FechaV,QR,FotografiaE,status,dueño);

or implement the interface:

class HistoryDA : System.IDisposable
{
    ...

    void Dispose()
    {
        ...
    }
}
    
answered by 09.05.2018 / 20:02
source