---
title: Classic .NET SDK
summary: The classic, hand-written .NET SDK (the BIM.works_SDK NuGet package) — requirements, the client factory and its login methods, the sub-APIs of a client, IDS validation and IDS checks, exceptions and error codes, and the DocFX reference.
order: 93
languages: [csharp]
terms: [sdk, qid, api-token, auth-token, scope, ids]
see-also: [reference/sdk/dotnet, reference/sdk, how-to/install/dotnet, how-to/auth/log-in-with-an-api-token, how-to/query/run-a-bql-query, how-to/checks/run-an-ids-check-via-the-api]
---

# Classic .NET SDK

```note title="Classic SDK"
This is the classic, hand-written .NET [[term:sdk|SDK]]. For a new integration use the [[page:reference/sdk/dotnet|.NET SDK]] generated from the OpenAPI document (`BIMworks.Sdk`); [[page:reference/sdk]] compares the two. The classic SDK stays supported.
```

The classic .NET SDK is the task-API client for C# and the other .NET languages: nodes, uploads, queries, IDS checks, scoped tokens and the Actions tree, with async tasks for the long-running calls.

## Package {#package}

| | |
|---|---|
| Package | `BIM.works_SDK` on nuget.org, version equal to your BIM.works server (beta releases carry a `-b.n` suffix) |
| Install | `dotnet add package BIM.works_SDK --version <version>` or `<PackageReference Include="BIM.works_SDK" Version="<version>" />` |
| Namespace | `BIM.works_SDK` |
| Target | .NET Standard 2.0, so .NET Core 2.0 and later, .NET 5 and later, and .NET Framework 4.6.1 and later |
| JSON | Results are `System.Text.Json` `JsonElement`s where the shape follows the query |

## Client factory {#factory}

`BimWorksClientFactory(Uri address)` is created once; the factory and every `BimWorksClient` are `IDisposable`, so wrap them in `using`.

| Method | Logs in with |
|---|---|
| `CreateClientWithApiToken(string)` | An [[term:api-token|API token]] — the normal way. |
| `CreateClientWithUsernamePassword(string, string)` | A user's credentials; for testing. |
| `CreateClientWithAuth(AuthToken)` | An [[term:auth-token|auth token]] obtained elsewhere. |
| `CreateAnonymousClient()` | No credentials; a very small set of calls. |

```csharp {#factory-example}
using System;
using System.Text.Json;
using BIM.works_SDK;

using (BimWorksClientFactory factory = new BimWorksClientFactory(new Uri("BIM_WORKS_ADDRESS")))
{
    using (BimWorksClient client = factory.CreateClientWithApiToken("BIM_WORKS_API_TOKEN"))
    {
        TreeNode root = client.Fs.GetRootNode();
        Guid version = Guid.Parse("BIM_WORKS_FIRST_MODEL");
        JsonElement results = client.Bim.Query(version, "GET qid, attribute.Name WHERE type = IFCWALL");
        Console.WriteLine(results.GetArrayLength());
    }
}
```

## Sub-APIs {#apis}

The client exposes its APIs as public read-only fields:

| Field | Class | What it does |
|---|---|---|
| `client.Auth` | `Auth` | Login and the current token (`SetAuthToken`, `GetAuthToken` are on the client itself). |
| `client.Fs` | `Fs` | Nodes and versions: `GetRootNode`, `GetRootNodeUuid`, `GetNodeByPath`, `GetNodeByUuid`, `GetNodeByVersionUuid`, `ListNodes`, `ListNodesRecursive`, `CreateNode`, `CreateNodeIfNotExists`, `RenameNode`, `DeleteNode`, `DeleteNodeIfExists`, `UndeleteNode`, `NodeExists`, `ListNodeVersions`, `GetNodeVersion`, `DeleteNodeVersion`, `ListNodeErrors`. |
| `client.Upload` | `Upload` | `UploadModel(UploadBuilder)`: an `AsyncUploadTask` whose `GetUploadResponse()` waits for the new version. |
| `client.Bim` | `Bim` | BQL: `Query(Guid version, string bql)` for one model, `Query2(ISet<Guid> versions, string bql)` for several, and `Query2(..., Guid queryUuid)` for a stored query. |
| `client.Tokens` | `Tokens` | `CreateVersionsToken`, `CreateNodesToken`, `CreateRecursiveNodeToken`, each with a request object and a response holding the `AuthToken`. The requests take an `ISet<Scope>` ([[page:reference/dotnet#scopes|Scopes]]); the constructors with a task-name list are obsolete. |
| `client.Gis` | `Gis` | Geo-references. |
| `client.Actions` | `Actions` | The Actions tree: `GetRootAction`, `ListActions`, `AddFolder`, `AddQuery` (a saved BQL query, run with `client.Bim.Query2(versions, queryUuid)`), `DeleteAction`. |
| `client.Checks` | `Checks` | IDS: `ValidateIds`, `RunIdsCheck` (the result tree with every checked object), `RunIdsCheckSummary` (the status and counts per specification) ([[page:reference/dotnet#checks|IDS checks]]). |
| `client.Admin` | `Admin` | `CreateApiToken(nodeUuid, name, scopes, expiresOn)` returns the new API token; the variant with `ApiTokenCredential.READ`/`WRITE` is the legacy one. |
| `client.Info` | `Info` | Server information. |

`client.QueryDelegated` and `client.QueryWithToken` are left over from the retired [[term:delegated-query|delegated query]] and no longer return results: the signed table export they set up carries the deprecated JSON query object (`BimQueryV1`) and asks for JSON output, while the server's table export takes BQL and writes XLSX, XLS or CSV. To let another client query, give it a versions token with the `query:run` scope ([[page:how-to/auth/create-a-versions-token]]); `client.CreateAsyncTask(request)`, `client.Execute(...)` and `client.GetTask(uuid)` reach any task the SDK has no method for. An `AsyncTask` is returned by every long-running call; `Get()` waits for the `Response`, whose `getOutput()` is the JSON result. One client can run many uploads at the same time, started from one thread: the synchronous calls only share the thread-safe `HttpClient`, but the list of running tasks the client keeps is not synchronised ([[page:how-to/models/upload-models-concurrently]]).

## Scopes {#scopes}

A token or API token is restricted to [[term:scope|scopes]], the `Scope` enum (`Scope.FS_READ`, `Scope.GEOMETRY_READ`, `Scope.QUERY_RUN`, …); `scope.ToWire()` gives the server's name (`"fs:read"`) and `Scopes.FromWire` the reverse. A token never gets a scope the credential that issues it lacks ([[page:how-to/auth/create-a-versions-token]]).

```csharp {#scopes-example}
ISet<Scope> scopes = new HashSet<Scope> { Scope.FS_READ, Scope.GEOMETRY_READ, Scope.QUERY_RUN };
AuthToken auth = client.Tokens.CreateVersionsToken(
    new CreateVersionsTokenRequest(Collections.CreateHashSet(versionUuid), scopes, TimeSpan.FromMinutes(30))).GetAuth();
```

## IDS checks {#checks}

[[dotnet:BIM.works_SDK.Checks|`client.Checks`]] validates an [[term:ids|IDS]] and runs it on model versions. The IDS is the XML text of an IDS 1.0 document; it travels with every call and nothing is stored on the server.

| Method | Returns |
|---|---|
| [[dotnet:BIM.works_SDK.Checks#ValidateIds|`ValidateIds(ids)`]] | An [[dotnet:BIM.works_SDK.IdsValidationResult|`IdsValidationResult`]]: `IsValid`, or the server's reason in `Message`. Checks that the IDS is well-formed XML and valid against the IDS schema; an invalid IDS is an answer, not an exception. |
| [[dotnet:BIM.works_SDK.Checks#RunIdsCheck|`RunIdsCheck(version or versions, ids)`]] | An [[dotnet:BIM.works_SDK.IdsCheckResult|`IdsCheckResult`]]: `OverallResult`, the result tree (`Root`, `Specifications`), and `ObjectResults` and `FailingObjectResults`, each with the checked objects (Qid, name, GlobalId, IFC type). Needs `checks:run`. |
| [[dotnet:BIM.works_SDK.Checks#RunIdsCheckSummary|`RunIdsCheckSummary(version or versions, ids, specifications = true)`]] | An [[dotnet:BIM.works_SDK.IdsCheckSummary|`IdsCheckSummary`]]: the counts, and per specification its status (`PASSED`, `FAILED`, `NOT_APPLICABLE`, `EVALUATION_ERROR`) with its counts and its requirements' counts. Not limited in size. Needs `checks:run`. |
| [[dotnet:BIM.works_SDK.Checks#ReadTooLargeSummary|`Checks.ReadTooLargeSummary(e)`]] | The summary a `RESULT_TOO_LARGE` refusal of `RunIdsCheck` carries, or `null`. |

An IDS that cannot run is refused with `INVALID_CHECK_DEFINITION`.

```csharp {#checks-example}
string ids = File.ReadAllText("specification.ids");
Guid version = Guid.Parse("BIM_WORKS_FIRST_MODEL");

IdsValidationResult validation = client.Checks.ValidateIds(ids);
if (!validation.IsValid)
{
    Console.WriteLine(validation.Message);
    return;
}
IdsCheckResult result = client.Checks.RunIdsCheck(version, ids);
foreach (CheckResultNode failed in result.FailingObjectResults)
{
    foreach (CheckedObject o in failed.Objects)
    {
        Console.WriteLine($"{o.Type} {o.Name} {o.GlobalId}");
    }
}
```

[[page:how-to/checks/run-an-ids-check-via-the-api]] has the same calls in JavaScript and Java.

## Errors {#errors}

Every call throws `BimWorksException`; `GetEnum()` returns the error constant (`BimWorksErrorCode.NODE_NOT_FOUND`, `BimWorksQueryError.SYNTAX_ERROR`, `AuthorizationError.NON_AUTHORIZED_SCOPE`, …), `GetCode()` its number and `Message` the server's message. `GetDomain()` and `GetErrorType()` give the server's names (`"BimWorksErrorCode"`, `"NODE_NOT_FOUND"`); for an error newer than your SDK version `GetEnum()` is null and those two still tell you what happened. `GetUserSafeMessage()` is the server's message for an end user, and `GetPayload()` the data some errors carry (a `RESULT_TOO_LARGE` refusal its summary). Codes are listed on the [[page:reference/errors|error codes]] page.

```csharp {#error-example}
try
{
    client.Fs.GetNodeByPath("/does/not/exist");
}
catch (BimWorksException e)
{
    if (BimWorksErrorCode.NODE_NOT_FOUND.Equals(e.GetEnum())) { /* create it */ } else { throw; }
}
```

An answer the server could not send as a result, an HTTP error status, also arrives as a `BimWorksException`, with the status as `GetCode()`. A value the server adds to an enum later (a new discipline, node type or status) reads as a fallback instead of failing the call: `UNKNOWN` where the SDK's enum has one, `FOLDER` or `MODEL` for a node type.

## Generated reference {#generated}

The [[page:reference/dotnet/api|.NET API catalogue]] documents the types and members of `BIM.works_SDK`, generated from DocFX metadata and XML documentation comments. It shares this site's navigation, styling and search, including signatures, overloads, parameters and inheritance.

## Used in {#used-in}

- [[page:how-to/install/dotnet]] — NuGet and prereleases.
- [[page:how-to/auth/log-in-with-an-api-token]] — the factory and the token.
- [[page:how-to/query/run-a-bql-query]] — `client.Bim.Query`.
- [[page:how-to/models/upload-models-concurrently]] — a batch of uploads checked in at the same time.
- [[page:how-to/checks/run-an-ids-check-via-the-api]] — `client.Checks`.
