right now I am facing a weird problem as the code worked already and I don't know what I changed. I'm using the .NET API for vector CANoe to create test cases in c#. This just as a side fact.
In my testcase I'm performing a simple reset:
    [TestCase()]
    public void hardReset() {
        Response _response = UDS.resetDevice(ResetTypes.HARD);
        if (_response.IsPositive) {
            //Do something really great
        }
    }
So the the _response of the Type Response is created by the class 'UDS' with the reset function. This looks like this:
    public static Response resetDevice(byte resetType) {
        using (Ecu _ECU = Application.GetEcu(Qualifier.Name)) {
            byte[] _raw = new byte[] { 0x11, resetType };
            return sendRequestMessage(_raw, _ECU);
        }
    }
It opens the connection to the device, builds the request and sends the message, which returns the Response. Afterwards the connection is shut down by using(){}. The send function looks like this.
    private static Response sendRequestMessage(byte[] rawData, Ecu ECU) {
        Request _request = ECU.CreateRequest(rawData);
        SendResult _result = _request.Send();
        if (_result.Status == SendStatus.Ok) {
            return _result.Response;
        }
        return null;
    }
This is taken from the Vector GmbH manual and works as expected. If the request was send it returns _result.Response as it should. It's never null.
If I simply send the request, everything is fine, but as I take the '_response' (not null) and want to do something, it seems to be already disposed. Can someone show me the blind spot?
I already tried to declare the _response outside like this:
    public static Response resetDevice(byte resetType) {
        Response response = null;
        using (Ecu _ECU = Application.GetEcu(Qualifier.Name)) {
            byte[] _raw = new byte[] { 0x11, resetType };
            response =  sendRequestMessage(_raw, _ECU);
        }
        return response;
    }
The behavior is the same. The response is never null but gets disposed right away.
I found this hint in the meantime, but I'm not getting any better with this:
