FIX - Dumping Dynamic Types In LinqPad
[Tools, LinqPad, Fix]
If you are a .NET developer, you must have come across and used Joe Albahari’s LinqPad.
This is a brilliant tool for quick prototyping and experimentation.
It is basically free, but for a small fee, you get autocompletion, refactoring, Nuget package management, and a bunch of other useful aids.
One of its most powerful features is its ability to render an object to its console using the Dump extension method.
Take this type:
public class Animal
{
public string Name { get; set; }
public byte Legs { get; set; }
}
We use it like this:
var animal = new Animal()
{
Name = "Dog",
Legs = 4
};
Normally, if you want to visualize your Animal, you either use your favourite debugger (which LinqPad also has) or override ToString.
In LinqPad, you simply call the Dump method.
animal.Dump();
This will do the following:

This can save a lot of time.
You can also set breakpoints and examine your objects the usual way:

An interesting thing happens when your type is dynamic.
As it the case here:
using (var cn = new SqlConnection("data source=localhost;uid=sa;pwd=YourStrongPassword123;TrustServerCertificate=true"))
{
var data = cn.QuerySingle("SELECT getdate()");
data.Dump();
}
This should print the date to the console.
However, it does nothing!

The solution to this is to make your dynamic type an object.
using (var cn = new SqlConnection("data source=localhost;uid=sa;pwd=YourStrongPassword123;TrustServerCertificate=true"))
{
var data = cn.QuerySingle<object>("SELECT getdate()");
data.Dump();
}
This now behaves.

TLDR
If you want to display a dynamic, cast it to an object.
Happy hacking!