The Granite State Hacker

Getting Started with .NET Aspire

At .NET Conf 2023, Microsoft announced a new stack set on top of the (also new) .NET 8 (LTS). During this presentation, I dig into what .NET Aspire is made of, and how to build cloud ready apps on it. It may still be in preview for now, something tells me it will become a .NET staple eventually.

During my presentation at Granite State .NET (NH) Developer’s Meetup on April 18th, I recorded the presentation. During the presentation, I unintentionally updated my toolset in the middle of the demo, and pried out the demo demons.

Catch the presentation on YouTube here:

The error that came up during the publish operation was this:

Error generating project artifacts: configuring ingress for resource cache: binding for does not specify a container port, ensure WithServiceBinding for this resource specifies a hostPort value ErrorPublish profile creation failed. Unable to store profile

Here’s the related GitHub issue:
[WebToolsE2E][Aspire] For Aspire Starter App projects with redis checked, an error occurs when running ‘azd init’. · Issue #3624 · Azure/azure-dev (github.com)

The solution was to also update AZ and AZD cli tools.

C:\Program Files\Microsoft Visual Studio\2022\Enterprise>winget upgrade Microsoft.Azd
Found Azure Developer CLI [Microsoft.Azd] Version 1.8.100
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/Azure/azure-dev/releases/download/azure-dev-cli_1.8.0/azd-windows-amd64.msi
██████████████████████████████ 9.66 MB / 9.66 MB
Successfully verified installer hash
Starting package install…
Successfully installed

After updating the tools, publishing proceeded as expected.

Welcome to the Virtual Assistant Template
Tech in the 603, The Granite State Hacker

Welcome to the Virtual Assistant Template

I can’t believe I haven’t blogged this out, yet. I’ve been building chatbots for clients for years now, and presenting to the tech community on the topic at least as long.

Welcome to the Virtual Assistant Template

For a while, I was doing “Bot in a Day” workshops, all over the country. Held at Microsoft Technology Centers in places like Boston, Reston, Philly… I just realized the last one I did was over a year ago, now, in Irvine, California.

The reason we don’t need to do the day long workshops anymore is because everything we did (and more!) in “Bot in a Day” can now be done reliably and repeatably in minutes… We do this using the latest iteration of the “Enterprise Template”, now known as the “Virtual Assistant Template”.

Ok, so the one-time setup can be a bit longer than an hour… but that’s (mostly) one time. If you are a C# dev, especially in the ASP.NET Core space, you probably have most of the tools installed already, anyway.

Anyway, I’ve been doing variations on this “Bot in an Hour” theme, using Virtual Assistant Template, all over New England, and will soon be taking it on the road to Washington DC, where I’ll be doing the shtick for Ignite the Tour in February 2020.

So the Virtual Assistant Template is a very quick way to build out some meaty bones of an enterprise-grade chat bot, especially in C# (though a TypeScript version is also available).

I won’t try to do what its own documentation does well, at this point. Rather, I’ll point you to that documentation.

What is the Virtual Assistant Template (Microsoft)

OSS GitHub Repo

Here’s my presentation slides from Boston Code Camp, which was on November 23rd, 2019. It’s more complete than the stripped down version I presented as a workshop at Global AI Bootcamp 2019 today (December 14th) at MIT.

In addition to the “Welcome to the Virtual Assistant Template” presentation for Ignite the Tour, I’ll be doing a similar presentation for Granite State NH .NET Devs on December 19th at the Microsoft Store in Salem, NH.

Tech in the 603, The Granite State Hacker

Locking Resources in C# for Read/Write Concurrency

In a previous project, I became a big fan of System.Threading.ReaderWriterLockSlim.  It was an excellent way to guard a resource against concurrency in a relatively flexible manner.  

C# has a lock(object) {} syntax for simple concurrency locks, but what if you have a resource that can sometimes be used concurrently, and other times, exclusively?

Enter System.Threading.ReaderWriterLockSlim.  This has a few handy methods on it for guarding code on a non-exclusive (Read) and exclusive (Write) mode, with an upgradeable lock, as well, so you don’t have to release a read lock in order to upgrade it.

This source works just as well in .NET as UWP.

I commented the code enough to try to make it so that someone familiar with ReaderWriterLockSlim and using(IDisposable){} would understand the rest, so without further ado…

https://gist.github.com/GraniteStateHacker/e608eecce2cb3dba0dbf4363b00e941f.js