Tech in the 603, The Granite State Hacker

C# and WebAssembly

I’m honored to be able to post in Matt GrovesAnnual C# Advent again this year, and today… December 22nd, 2018, is my second year contributing to it.

Last year I talked about ways to unload the main UI thread in WPF/.NET apps.

This year, I want to call attention to the Uno Platform tools I’ve been evangelizing for the past six months or so. 

Silverlight is dead – Long Live Uno Platform!

To understand this perspective, we’ll need to walk through some key terms….

What is Silverlight?silverlight

For those who don’t know, about ten years ago, Silverlight was the way to write C# and XAML to run in the web browser. It required a plug-in to run, much like Adobe Flash Player. Unfortunately, Microsoft announced the…. untimely demise of Silverlight in 2012. Silverlight, to some extent, seemed a more catchy term than other related technology names, so Microsoft used Silverlight as the name for mobile platforms that are also now depricated. As a result, it became almost synonymous with XAML.

What is XAML?

XAML, “eXtensible Application Markup Language” is the markup language behind a few great UI / UX layers in various Microsoft .NET-oid languages.  For those who’ve used it, it’s an addictively cool language family.  Using Visual Studio, Blend, and Adobe DX, you can create first-class UI.  With features like Storyboard animation, basic animation becomes child’s play. Composition makes fast, dynamic animations easy. Once you’ve gotten the basic idea of it, one finds themselves wanting to use it anywhere they can…  or at least that’s been my experience through WPF, Silverlight, Silverlight for Windows Phone, Silverlight for Windows Phone 8 / 8.1, Universal Windows Platform (UWP) and probably others.

The “code behind” XAML is typically C#, and historically .NET based.

What is Universal Windows Platform (UWP)?

UWP is the native platform of Windows 10.  It’s similar to classic .NET in a few ways.  First, UWP feels a lot like Windows Presentation Foundation (WPF) and .NET, being XAML and C# based, respectively.  It differs from classic .NET because it has a lot of fixes, both in terms of security and performance, that .NET can’t afford to apply for various reasons.  More simply put, .NET had some serious technical debt built up, so the easiest way to forgive that debt was to build a new platform based on the old languages.  Your XAML and C# skills are the same, but the namespaces and supporting framework libraries are different.

Don’t fret, though…  UWP runs natively on over 800 million devices (as of today, December 22nd, 2018), and that number continues to grow.  UWP is the native platform for all Windows 10 devices.  This means desktops, laptops, tablets, phones, HoloLenses, Xbox consoles, IoT embedded devices, and more. 

What is WebAssembly?webassembly

WebAssembly is a relatively new bytecode language specification… a virtual machine specification, similar to the Java Virtual Machine (JVM), that is fully supported by most modern major web browsers.  It allows near native performance in the same sandbox that javascript apps run in.  When you run javascript in a web page, the jit compiler in the browser converts the code into tokenized bytecode in order to execute it quicker.  WebAssembly improves on this significantly by pre-compiling the code.  Because the code is pre-complied, it doesn’t have to be sourced from javascript.  It can be compiled from just about any programming language.  Wasm, as it’s called, went from a specification just a few short years ago to being well supported in all major modern web browsers.

What is Uno Platform?uno platform

Uno Platform, for our purposes, is not really a new platform, but an extension to UWP. 

You write your UWP application for your Windows 10 devices the same way you always have.  Uno provides a mechanism to re-compile that UWP app to Web Assembly (and… by the way… using Xamarin tools, also to iOS… and also to Android!)

In a sense, Uno Platform is to UWP as Xamarin is (roughly) to classic .NET.

See the connection? 

Let’s do some math…

UWP = C# & XAML for Windows 10.  (800,000,000 devices)

Uno Platform += UWP for iOS (Millions more devices), Android (over a Billion devices), and WebAssembly (every modern major PC in the world)

Now factor in this…

.NET Core 3 += UWP for services

What does all that add up to? 

One skill set… 

UWP (C# & XAML) = FULL STACK, on all major platforms

From data access layer to REST API to UI canvas.

Wait a minute…  What about Xamarin?

Xamarin is the older way to do C# for cross platform / mobile.  

Coincidentally, just this past Thursday, Carl Barton, a Microsoft MVP for Xamarin presented the Xamarin Forms Challenge at the Windows Platform App Devs users group. The goal of the meetup was to demonstrate creating a simple app in C# and running it on as many platforms as we could in the hour.  He easily pushed ran the app on over a dozen platforms in the hour.

Uno Platform actually depends on Xamarin libraries to support iOS and Android. 

The main differences between Xamarin and Uno Platform are these:

  • Xamarin encourages you to use a Xamarin-specific dialect of XAML, including Xamarin Forms to express your cross platform UI.
  • If you already know & understand Microsoft’s UWP dialect of XAML, Uno Platform uses that dialect.
  • Xamarin enables you to produce binaries for dozens of different target platforms, reaching a billion or more devices.  These include .NET, UWP, iOS, Android, Tizen, Unity, ASP.NET, and many others.
  • Uno Platform only enables you to reach three additional binary output targets…  iOS, Android, and WebAssembly…. but WebAssembly can or likely will soon cover most of what Xamarin Forms covers.

I’ll leave it up to you which to choose, but for me, given the choice between Xamarin with several years of technical debt built up in a distinct dialect of XAML, and Uno Platform, using the fresher, native UWP dialect of XAML…  

Finally… 

Here’s the slides I presented most recently at the New England Microsoft Developers meetup in Burlington, Mass on December 6th (thanks again to Mathieu Filion of nventive for much of the content):

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%211297452&authkey=AM6QZrb_6-9ltdE&em=2″ width=”402″ height=”327″]

Tech in the 603, The Granite State Hacker

Google’s Challenge, by the Numbers

Google may have inadvertently worked itself into some awkward dependencies that could be troublesome for it in the next few years.

It’s hard to imagine Web 2.0, now a decade gone by, as the peak of the web, but I think the numbers speak volumes about it.  Below, I’ve grabbed some stats from Wikipedia, as of today (4/26/2015) ( http://en.wikipedia.org/wiki/Usage_share_of_operating_systems ), that puts together some puzzle pieces together in my head, but introduces a few new ones. 

Originally, I was thinking about Windows market share this past weekend, and how absurd it is that folks think of Windows 8/8.1 a “failure”… (It came up at the Global Azure Cloud Camp Jim O’Neil hosted at BlueMetal’s office in Watertown this past Saturday.)  There’s more Windows 8+ machine (alone) than all versions of Mac OS X combined…  Microsoft’s “failure” is only a failure when compared to Windows XP and Windows 7.

Desktop operating system browsing statistics
Windows 7
  
58.04%
Windows XP
  
16.94%
Windows 8.1
  
10.55%
Mac OS X 10.10
  
3.96%
Windows 8
  
3.52%
Windows Vista
  
1.97%
Mac OS X (other)
  
1.71%
Mac OS X 10.9
  
1.61%
Linux
  
1.5%
Windows (other)
  
0.2%

Windows 8 / 8.1 comes sums at roughly 13%, while OS X (all versions) is (estimating generously) 8%.  So 13% may be a failure compared to Windows 7’s 58%….  but no one thinks of OS X’s 8% market share as anything less than a smash hit.  

I get that the terms of failure for 8.x come from it’s largest customer, the enterprise market, which has largely ignored it. It’s why Windows 10 is a significant comeuppance for Microsoft.

All told, though, among desktop OS’s, Windows is king.  No surprise there, really.  That’s only the beginning of the story. 

Some of the other stats started to catch my attention with respect to all devices, and what folks are using them for.

From the same Wikipedia page:

According to Gartner, the following is the worldwide device shipments (referring to wholesale) by operating system, which includes smartphones, tablets, laptops and PCs together.

Worldwide Device Shipments by Operating System
Source Year Android iOS/OS X Windows Others
Gartner[1] 2014 48.61% 11.04% 14.0% 26.34%
Gartner[2] 2013 38.51% 10.12% 13.98% 37.41%
Gartner[3] 2012 22.8% 9.6% 15.62% 51.98%

The above table establishes that “device” shipments of Windows devices is relatively small compared to Android devices, with Apple devices coming in 3rd overall.  If we set form factor aside and look at all consumer “computing devices”, Android is undeniably tops, and has been for a few years already.

Now look at this…  (a breakdown of what OS folks are using web browsers on.)

Web clients’ OS family statistics
Windows
  
55.74%
Linux based
  
22.02%
iOS, OS X
  
17.17%
Symbian, S40
  
2.02%
Other
  
3.05%
Linux based is actually composed of both desktop and Android based devices… digging a bit, the stat that shows Android usage specifically shows it at less than half of “Linux” based stats.

See the rub?

The web is unequivocally consumed by desktops, which are owned by Windows.

Android… the most popular consumer “device” (by an allegedly monopolistic margin in some markets), represents less than half the web traffic.

Either the margin of error is so far off these stats, rendering them all useless, or there’s an interesting story there.

This means the good old browser is being left behind by mobile devices.   This has been observed before, but it’s interesting to note that Google’s hanging on it.  I mean, what’s your home page?  If you’re like a lot of folks, it may well be www.google.com.

Here’s a question.  Is the browser propping up Windows, or is Windows propping up the WWW?

Here’s an answer…  Microsoft’s go-forward strategy is Mobile First / Cloud First.  Windows 10 is a mobile OS that supports desktops, not a desktop OS that supports mobile.  Clearly, Microsoft is taking risks, but their goal is to push Windows into the mobile app world, taking only the parts of the world wide web that are important to mobile and cloud.

One might argue that Windows 10 includes both IE 12 and the Spartan browser.  Further, Microsoft is just releasing a new ASP.NET and MVC web development tools.

No matter what, the web app is not going to vanish overnight.  Still, Microsoft adding yet another browser and more tools is 1) further fragmenting the already terribly fragmented web app platform, 2) a bone thrown to the many enterprises who have built their infrastructure on web technology and can’t afford to fully shift their enterprise app platform (and developer skill set) to mobile apps in the next few years, and 3) continued support for the still critical http protocol that is a core network transport for everything in the Internet of Things.

One might argue Office 365.  The backfire there:  pretty much everyone who has Office 365 also has desktop and even mobile apps.  This leaves Office 365 to be primarily a services back end for those apps, with a web-based UI as a fallback if you for some reason can’t run the native apps.

Apple’s iOS success and Google’s Chromebook failure led Google to cannibalize itself into the (unexpectedly?) wildly successful Android.

Android’s success, in turn, is eating away at Google’s classic model…  Google will likely always be a media platform first, but more and more, that media platform is being confined to (and defined by) Android.  (Like a genie enslaved to its bottle…  “Phenomenal cosmic power, itty-bitty living space.)

All in all, I’ll go out on a limb and say that Microsoft is about done propping up the consumer web as an application platform.

Still, forgetting what Microsoft is doing, Google is SaaS heavy, and has no PaaS or IaaS offering to fall back on.  They have no desktop OS to elevate them.  All the cards in their foreseeable future appear to rest on Android (and therefore Samsung).

With the anti-trust suits already starting against Google because of Android, it’s hard to really see Google’s future over the next decade.

Being at the top, it’s pretty easy to say Android is peaking.   The question is where does that leave Google.  YouTube?  Self-driving cars?

I find myself thinking it makes a bit more sense that Apple and Yahoo have aligned their search with Bing.

What am I missing?

Tech in the 603, The Granite State Hacker

Is Your Solution Delivery Strategy About to get Avalanched by Windows 10?

HoloLens took the spotlight when //build/ 2015 announced it had sold out in under an hour, but I can’t help but think at least as big a chunk of the excitement is around Windows 10 (or as we developers like to think of it, Windows Unified). As cool as HoloLens is, Windows 10 will most likely be landing in your lap long before HoloLens has images dancing in your living room. 

If you’re not already preparing for Windows 10, your solution delivery stack could be in for a shock from the client up. Microsoft is in the process of launching a re-boot of itself, and Windows 10 is the fulcrum of that effort. As usual, many of its changes are aimed at pulling developers in. If solution development has a place in your organization, this will likely impact you as well. 

“Mobile First / Cloud First” is, as always, the key phrase, and for a client OS… if it’s not for cloud devices…. give it a moment…  let that sink in…   Yes.  Windows 10 is an OS for mobile devices. Even if your device is a big heavy block of a workstation sitting near your monitor.  It will have the same mobile app store as phones and tablets, and it can be managed by the same Enterprise Mobile Device Manager (MDM).

Windows 8 was an introductory / transitional OS. With Windows 10, the transition matures.  Windows 10’s maturity is likely to make it far more palatable than Windows 8 was. (Keep in mind that Windows 8 is only a “failure” in terms of Microsoft’s other OS releases… Windows 8/8.1 has a bigger install base than some of the most “successful” of its non-Microsoft competitors. If Windows 10 becomes the hit many foresee it to be, it has potential to become the de facto standard platform to truly de-throne XP and even Windows 7.)

Windows 10 also adds a bit of a surprise, especially around browser technology.  Microsoft is tossing in to Windows 10 a whole new web browser (in addition to Internet Explorer) currently code-named Spartan. This new browser is intended to go after the consumer browser market, which IE has lost considerable ground in. I speculate that Spartan will be a breath of fresh air for consumers who feel IE’s bloat-related flaws collectively compels them to download Chrome or Firefox.

If you’re a web application developer who does more than a little HTML, on the other hand, you’re probably already groaning. You know what a pain browser compatibility is. (The browser was never intended to be a homogenous cross-everything platform, but that’s how a lot of web designers treat it, and they’ve shaped culture to expect it. Despite the best efforts of tools like jQuery and others to try homogenize, and trends like responsive to try to change the culture of presentation homogeny, web application developers get severely burned in the crossfire.  I’ve got more than a few scars to prove this, but you don’t have to look further than jQuery’s failed mechanisms for helping developers with these issues.    (First there was $.browser and $.browser.version, then $.support… then, “awe… heck… we give up, use Modernizr“.) /rant )

Spartan is a move that makes total sense, but it can’t help but add complexity to web application developers’ lives.  

In fact, in my mind, the long term net message is… there’s only one way to end browser pain… by getting out of web as a client platform. (Web services are the only part of the web worth salvaging.)

Microsoft has seen what platform diversification has done to its core OS business, and it’s not good. Developers need a consistent platform to deliver consistent solutions on, and that’s been a bigger part of Microsoft’s success over the years than even they seem to have realize.

So if web application development is becoming ever more complex in an already over complicated domain, how should one produce and deploy apps?

In a word:  native (aka mobile).

Windows 10 is a unifying platform, a “pentecostal” event to counter the “tower of babel” event of Windows platforms that have fractured into existence since the end of the .NET Compact Framework era. Where before development was requiring more and more effort to support PC, tablet, smartphone, wearable and even Xbox, Windows 10 has a unified SDK across all those platforms. For the first time ever, a .NET developer can build a single solution that runs in all those devices. There may be runtime differences between platforms that have to be ironed out, still, but not compile-time  (if(system.capability.phone) {} rather than #ifdef WINDOWS_PHONE_APP)

And think about it… what are the big reasons for web deployment?   Centralized management and centralized deployment.  Think back to MDMs and mobile app stores.

(Xamarin plays a roll in all this as well. Between Windows 10 and Xamarin, developers will be able to leverage a good chunk of their code base across all hardware, even non Microsoft platforms such as IOS and Android. This, too, is a breath of fresh air, because the cost of maintaining multiple code bases (and talent pools) is ever climbing. Xamarin will likely never be the 110% development experience that the latest .NET framework is, but neither was Silverlight for Windows Phone 7, yet one could do some fairly heavy lifting with it.)

Because Windows 10 is one platform that runs across form factors, it essentially means that any app written for Windows 10 is a mobile app. In that light, it means that Windows 10 is most likely to vault Windows into the top spot for mobile platforms by its projected install base. 

This on top of Microsoft’s recent “trickle up” theory of mobile market share growth, where Microsoft has been grabbing market share by targeting the feature phone market.  (This tactic has little effect in the US, where carrier subsidies nullify the low end to “$0”)  At some point Windows Phone will hit critical mass outside the US. Once that happens, even US developers will no longer be able to afford to ignore it.

Even if Microsoft is not contributing directly to your solution stack, Windows 10 and its biases have potential to culturally influence your solutions and solution delivery over the next decade.

Tech in the 603, The Granite State Hacker

Publishing Content Separately from Presentation

Separating content from presentation is a very old “Best Practice”™. 

Publishing using web technology is not new anymore, either, but mobile puts a newish urgency in that best practice.  I’m seeing ignorance of the old best practice bite some in a potentially surprising way as the age of mobile apps become the preferred way to consume content.

Here’s what I mean by publishing separate content and presentation… 

Take for example a menu from a restaurant.  I’m finding in many cases, restaurants have web sites that publish their menu.  Their menu items are content, and the web site presents it in a pleasant manner.  In many cases, the presentation and the content are published just in that web page.  (The menu items are “hard coded” as HTML into the page.)

If the restaurant’s menu items are “hard coded” into the page presentation, it’s very hard for anyone to re-use that information in any other presentation.  It’s not impossible.  It can be “scraped”, and some tools do a decent job of it.  It’s just not easy enough. 

The more technically correct path is to publish the content as a web service, and then publish the web site.  The web presentation layer should consume content it gets from the service. 

Why does this matter?

There’s lots of functionality that can be provided by a content service.  Users can consume portions of the content by filtering it, sorting it, or classifying it.

To expand on that, I’ll pick on Microsoft’s Windows Phone AppStudio a bit, since they’re the star in my circles right now.  Microsoft’s AppStudio is one of many ways to create apps for mobile devices.  (In this case, for Windows Phones, but that’s beside the point.)  AppStudio’s niche is making it easy for people to pull in content from various sources and present it in their own Windows Phone app.  LOTS of people are building apps for just about everything you can imagine…  members of the Granite State Windows Phone Users Group are producing a ton of apps based on it.  

Here’s some statistics to try to paint a picture of this.  The NH Windows Phone UG community publishes a list of apps produced by its members.  In the past three months since App Studio was released, I estimate that the number of apps in that catalog has doubled, and 95% of the new apps are AppStudio apps, consuming and re-presenting, making use of content provided by 3rd parties. 

What makes it easy to build AppStudio apps is that it has a simple presentation of its own… all folks need to do is find content that’s been formatted in one of a few very standard ways.

We have, for example, a grade-school aged member of the #NHWPUG community building and publishing apps with AppStudio.  His publisher name is YoungMaster, and his first app is called “Kids Zone”.  The cool part about Kids Zone is that he was able to add video content from YouTube.  His app merely queries YouTube for certain kinds of videos, and YouTube responds with a list (in a standard format) of items.  Users of the app simply tap the list for more information about it, or to watch the video.

Now, back to that restaurant…  if a patron/fan developer wants to make an app for a specific restaurant, it would be very hard to add that restaurant’s menu items if the menu item information is not published separate from the web site presentation.  

Another application might be to allow a person searching for a meal to browse menu items from a number of nearby restaurants.  Will your restaurant’s menu items be available in the list?

Lots of folks already understand this concept of separately published content and presentation, and apps pop up around the content all the time.  Movie theaters, travel agencies, transit authorities, social media updates, news agencies… all publish their content separate from their web site presentations. 

What’s rougher, for folks using a CMS (Content Management System), chances are, you have the ability to publish a Syndicated Feed or RSS Feed that would do the job… but if you’re not enabling and exposing it, you’re missing a chance for folks to help spread the word about your company in these new ways.

Tech in the 603, The Granite State Hacker

WORKAROUND: Misconfigured Windows-Integrated Authentication for Web Services

In trying to drive a process from a SharePoint list, I ran across a problem…

I couldn’t create a web reference in my C# project due to some really weird problem… In the “Add web reference” wizard, I entered my URL, and was surprised by a pop-up titled “Discovery Credential”, asking me for credentials for the site.

Since I was on the local domain and had “owner” permissions to the site, I thought I would just waltz in and get the WSDL.

Ok, so it wants creds… I gave it my own.

Negative…!?!?

After a few attempts and access denied errors, I hit Cancel, and was rewarded by, of all things, the WSDL display… but I still couldn’t add the reference.

After quite a bit of wrestling, it turns out there was an authentication provider configuration problem. The site was configured to use Kerberos authentication, but the active directory configuration was not set up correctly. (I believe it needed someone to use SetSPN to update the Service Principal Name (SPN) for the service.)

One way to resolve the problem was to set the authentication provider to NTLM, but in my case, I didn’t have, (and wasn’t likely to get) that configuration changed in the site (a SharePoint Web Application) I really needed access to.

In order to make it work, I had to initially create my reference to a similar, accessible site.

(e.g. http://host/sites/myaccessiblesite/_vti_bin/lists.asmx )

Then, I had to initialize the service as such, in code:


private void InitWebService()
{
System.Net.AuthenticationManager.Unregister("Basic");

System.Net.AuthenticationManager.Unregister("Kerberos");

//System.Net.AuthenticationManager.Unregister("Ntlm");

System.Net.AuthenticationManager.Unregister("Negotiate");

System.Net.AuthenticationManager.Unregister("Digest");


SmokeTestSite.Lists workingLists = new SmokeTest.SmokeTestSite.Lists();

workingLists.Url = "http://host/sites/mybrokensite/_vti_bin/lists.asmx";

workingLists.UseDefaultCredentials = true;

workingLists.Proxy = null;

lists = workingLists;
}

What this accomplishes is it unregisters all authentication managers in your application domain. (This can only be done once in the same app domain. Attempts to unregister the same manager more than once while the program’s running will throw an exception.)

So by having all the other authentication managers disabled in the client, the server would negotiate and agree on Ntlm authentication, which succeeds.