.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.


Breaking changes from v0.5

  1. Package renamed from Microsoft.AdaptiveCards to AdaptiveCards
  2. Due to frequent name collisions with framework types, all model classes have been prefixed with "Adaptive". E.g., TextBlock is now AdaptiveTextBlock
  3. All "uri" properties were changed from type string to Uri
  4. There have also been some schema changes from the v0.5 preview, which are outlined here

NuGet Install

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

Nuget install

Install-Package AdaptiveCards -IncludePrerelease

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();

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("http://adaptivecards.io/payloads/ActivityUpdate.json");
    var response = await client.GetAsync(cardUrl);
    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