.NET SDK for Authoring Cards

As we described in the Getting Started page, an Adaptive Card is a JSON object model. The .NET library makes working with that JSON much easier.

NuGet Install

The AdaptiveCards NuGet package provides types for working with adaptive cards in .NET

Nuget install

Install-Package AdaptiveCards

Example: Create an AdaptiveCard and serialize to JSON

This example demonstrates how to build an Adaptive Card using standard C# objects and then serialize it to JSON for transport over the wire.

using AdaptiveCards;
// ...

AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

card.Body.Add(new AdaptiveTextBlock() 
    Text = "Hello",
    Size = AdaptiveTextSize.ExtraLarge

card.Body.Add(new AdaptiveImage() 
    Url = new Uri("http://adaptivecards.io/content/cats/1.png")

// serialize the card to JSON
string json = card.ToJson();

Example: Parse an AdaptiveCard from JSON

This example demonstrates how to parse a JSON payload into an Adaptive Card. This makes it easy to manipulate the object model or even render Adaptive Cards inside your app by using our renderer SDKs.

    // Get a JSON-serialized payload
    // Your app will probably get cards from somewhere else :)
    var client = new HttpClient();
    var response = await client.GetAsync("http://adaptivecards.io/payloads/ActivityUpdate.json");
    var json = await response.Content.ReadAsStringAsync();

    // Parse the JSON 
    AdaptiveCardParseResult result = AdaptiveCard.FromJson(json);

    // Get card from result
    AdaptiveCard card = result.Card;

    // Optional: check for any parse warnings
    // This includes things like unknown element "type"
    // or unknown properties on element
    IList<AdaptiveWarning> warnings = result.Warnings;
catch(AdaptiveSerializationException ex)
    // Failed to deserialize card 
    // This occurs from malformed JSON
    // or schema violations like required properties missing