Search code examples
c#versionone

Invalid OID Token


I am using the VersionOne SDK and keep getting an error about the OID being invalid. However, when I use that OID to look up the test in VersionOne it is the correct OID for the test.

A first chance exception of type 'VersionOne.SDK.APIClient.OidException' occurred in VersionOne.SDK.APIClient.dll

Invalid OID token: Test:32423 

I am passing in a string that has "Test:32423" into the method.

public void UpdateTestResults(string strTestId, string strActualResult) 
    {
        var testId = Oid.FromToken(strTestId, _metaModel); 
        var query = new Query(testId);
        var assetType = _metaModel.GetAssetType("Test");
        var addResults = assetType.GetAttributeDefinition("ActualResults");

        query.Selection.Add(addResults);
        var result = _services.Retrieve(query);
        var test = result.Assets[0];
        var oldResult = GetValue(test.GetAttribute(addResults).Value);

        var time = DateTime.Now;
        const string format = "MMM ddd d HH:mm yyyy";
        test.SetAttributeValue(addResults, "<p>" + "\n" + oldResult + time.ToString(format) + "-->" + strActualResult + "</p>");
        _services.Save(test);

        _logger.Log(Loglevel.Debug, test.Oid.Token, oldResult, GetValue(test.GetAttribute(addResults).Value));

    }

I notice that the error only occurs when running a series of tests back to back. The error never occurs when I only run one test.

This is the code I put at the top of the class to make the connector and constructor.

const string ApplicationUrl = "https://www12.v1host.com/VersionOneAccount/";
    readonly NetworkCredential _credentials = new NetworkCredential("userName", "passWord");
    readonly IMetaModel _metaModel = new MetaModel(new VersionOneAPIConnector(ApplicationUrl + "meta.v1/"));
    readonly IServices _services;


    public V1Tools(ref DataObject masterData)
    {
        _services = new Services(_metaModel, new VersionOneAPIConnector(ApplicationUrl + "rest-1.v1/", _credentials));
        _logger = masterData.Logger;

    }

Solution

  • When I looked at the Inner Exception I saw that the request was timing out which was causing the Invalid OID exception to be thrown. So if the OID is correct and you see this error thrown check if there is another web request interfering with the communication between your application and the VersionOne server.