Skip to main content
Home  ›  Blog

2sxc 16.07 Typed LTS

2sxc 16.07 is LTS with the new Typed mode. This is one of the most important updates ever. Time to use Razor for precision shaving...


2sxc 16.07 is LTS - meaning Long-Term-Stable / Long-Term-Support. We are already using it in production, and so can you. The big features that are finally stable are the Typed coding mode, which will revolutionize how you work and probably increase productivity by a factor of 2!

  1. Read more about our LTS policy
  2. Get your 2sxc from the github releases

Typed Mode - The Big Deal

If you've gone from JavaScript to TypeScript, you know what I'm talking about. For all others, bear with me, as I'll explain why this is so important. Let's look at the following code:

This code will result in an error, which looks like this:

As you can see, the compiler is unhappy about line 14. But the developer can now waste countless hours trying to figure out what to do about this - when in reality, the problem started on line 9. Here's why:

  1. The object Content is dynamic - so Razor can't determine at runtime, what it will be.
  2. Because of this, the code AsAdam(...) will also be treated as dynamic - meaning that the variable folder will be dynamic - even though AsAdam(...) will always return an IFolder.
  3. but the compiler cannot assume that, so it treats folder and folder.Files as dynamic
  4. As a result, the code compiles as if everything is ok, even though a compiler could have spotted the problem much earlier. It will break at runtime, and usually in a randomly different place than expected. 

The fix is be to help the compiler on line 9 - but this is really hard to figure out 😠:

And this is the equivalent, Typed version. If something is wrong, you'll know right away:

Recap: The Problems with Dynamic Razor

  1. The compiler can't help with bugs on dynamic variable, resulting in errors which are really hard to figure out
  2. When you do get an error, it's often reported far away from the original cause.
  3. dynamic variables are like a virus - any code that use them will be treated as dynamic 
  4. the more code you have, the harder it gets to figure out what's going on
  5. together with LINQ (which uses Extension Methods) this get's really, really messy
  6. 2sxc has a bunch of magic to compensate for this - but if that didn't suffice, the problem often got even harder to find

Solution: Going Typed and Cleaning up History

The new typed mode is active when inheriting the new base class RazorTyped (or ApiTyped / CodeTyped). With this change, we also renamed a bunch of variables which have also caused confusions. For example:

  • No more "Content". The item which belongs to the the current Razor is called MyItem. If we get a list, it's MyItems. The Header is now MyHeader.
  • No more "Settings". It's either AllSettings or App.Settings.
  • No more "Resources". It's AllResources or App.Resources.
  • No more "Data". It's either MyData or App.Data.
  • There a lot more My* - like MyContext, MyModel, MyPage, MyView and more.
  • No more "AsDynamic(...)". This super-magical method did so many things that the code looked nice, but was impossible to debug. It's now AsItem(...), AsItems(...) or Kit.Json.ToTyped(string).

There's a lot more to this - best check out the docs.

Typed Tutorial

We spent more than a 4 full weeks on the tutorial app, so that you'll be able to see the code in both old and new from now on.

â–ļī¸ Check out the latest tutorial app now 🚀 -

â–ļī¸ especially the new Quick Reference 💡 -

Get it now!


💝 from Switzerland and Croatia,
iJungleboy, Tonci, Duje

Daniel Mettler grew up in the jungles of Indonesia and is founder and CEO of 2sic internet solutions in Switzerland and Liechtenstein, an 20-head web specialist with over 800 DNN projects since 1999. He is also chief architect of 2sxc (see github), an open source module for creating attractive content and DNN Apps.

Read more posts by Daniel Mettler