Visual Studio Extensions: SlowCheetah to transform XML and JSON Configuration Files

I have been using this Extension at some occasions, and it’s good to see, that it’s still around.

You might have noticed, that you can add transformations for your Web.config file based on the Build Configurations you are using. By default, transformations for Release and Debug are added automatically. If you have added your own Configuration, you can add transformations for these too.

This will create a transformation file, to modify the original Web.Config. You can replace Connections Strings, Servernames, Pathsettings – Basically everything, based on the Original Web.Config you have created.

However, if you try to do this for example for App.config in a Console Application, you will notice that there is no such option. Not even transformations are added for the default Build Configurations.

This is, where SlowCheetah comes in handy. You can install it via Extension Manager, and after restarting Visual Studio, it will be available.

After Installation is complete, we can have a look at out previous Console Application again and Right-Click on the App.Config file. Et voila, now we have an Option called “Add Transform”.

When executing this command, it will ask you to install the SlowCheetah Nuget package. This is required to run transformations, even if the Extension itself is not installed. So, not every member of your team needs to install the extension, only the people modifying the Configuration need it. But it will work for all team-members by using the installed Nuget package.

After we have done this, SlowCheetah creates the transformations for the default Configurations. If we add special configurations later, we just have to run the “Add Transform” again, to have new transformations added.

You can also find SlowCheetah in the Visual Studio Market Place

The Sourcecode can be found on GitHub: https://github.com/Microsoft/slow-cheetah

Champions of C# 9 : “Simplified parameter null validation code”

In this blog post I wan’t to have a closer look at a current proposals for the upcoming C# Version 9.

Proposal #2145 – Simplified parameter null validation code.

Usually, if handing over parameters to a method, some checking for NULL is required to prevent unexpected behavior. Have a look at the following sample of a method with some checking.

private string ParseText(string text)
{
    if (text is null)
    {
      throw new ArgumentException(nameof(text));
    }
    return text;
}

In C# 9, this code could be simplified by adding ! as an indicator for “Will not be NULL” to the parametername. The code would then look like this.

private string ParseText(string text!)
{
    return text;
}

Based on This discussion from summer 2019, the new syntax is supposed to throw an Exception too, if the constraint is violated. Most likely also an ArgumentException, but this doesn’t seem to have specified yet.


New Resources Section and first Page “Resources to learn C# and ASP.NET”

Today I published a new section in my Blog, to collect resources to various topics. The goal for these pages is, to stick around and for me to update them regularly, to keep them relevant. The first page of this format is about Learning C# and ASP.NET. As someone who is working with these technologies for almost two decades, I hope I can deliver some useful information for beginners. Also, I am open for suggestions. What resources did I forget ? Let me know.
Sascha

Sundays IT: Ever wondered, why chrome runs so many processes ?

Hi everyone,

did you ever ask yourself, why the hack is chrome running so many processes ?

Image of Windows Taskmanager

This image shows only 5 processes, but this can go up to an nearly insane amount.
According to some articles I read, chrome encapsulates every single page into its own process, to prevent crashing the browser when one page goes down.

Chrome provides a way, to get an overview of the processes it runs. To see it, go to you menu => more tools => Taskmanager

Image of Chrome Taskmanager Menu

Image of Chrome Taskmanager

And here you see the different processes Chrome is using. There is one for the browser itself, some additionals for certain features (In this case GPU) and one process for every page you have open at the moment.

Have a nice sunday
Sascha

Sundays IT: Windows Update on my Win7 machine is stuck at 0% again – 4 Steps solution

Hi everyone,

its annoying when Windows Updates just is not working and its download percentage is Stuck at 0%. I like to share my process to solve this issue – So I do the following:

  1. Opening a command prompt with elevated permissions by typing cmd in my searchbox, right-click and select “run as aministrator” or just type cmd into the box and hit CTRL+Shift+Enter.
  2. Stopping the update service by typing net stop wuauserv into the command prompt and hit enter.
  3. Deleting the contents of C:\Windows\SoftwareDistribution using the windows explorer.
  4. Starting the update service by typing net start wuauserv into the command prompt and hit enter.

After that, I need to scan for new updates again (May take a while, since the cached information is gone). Downloading them should now work as expected.

DISCLAIMER: Reproduce at your own risk and without warranties.

Have a nice sunday
Sascha

Sundays IT: Harddisc was going crazy

Hello everyone,

I have no idea how it happend, but suddenly the system harddisc on my good old Windows 7 machine went crazy. After some exploration with Resource Manager (PID: 4 – System was the bad guy) and browsing the internet I stumbled across an article about Prefetch and Superfetch.

serverfault.com – system-process-pid-4-constantly-accessing-the-hard-disk

Some time later, after checking out the configuration of these two values in my registry, I decided to limit the fetching to the startup time. Different settings for this entries can be found here:

https://en.wikipedia.org/wiki/Prefetcher
https://de.wikipedia.org/wiki/SuperFetch

And finally after rebooting, my harddisc goes quiet again. Still have no idea what the cause of that problem was still the values in the registry been the default values. Maybe some Windows Update lately, that expected me to suddenly have an SSD in my old machine 😉

Maybe someone finds this useful.

DISCLAIMER: Reproduce at your own risk and without warranties.

Cheers
Sascha

DotNetFiddle mit Unterstützung für F#, ASP.NET MVC und NuGet Packages.

Guten Abend,

leider konnte ich auf der Webseite DotNetFiddle.net keine Release-Notes finden.
Allerdings wurde irgendwann zwischen Januar und jetzt der Funktionsumfang dieses Tools für “.NET im Browser” nochmal deutlich aufgebohrt.
Man kann nun als Sprache F# zusätzlich zu den bisherigen C# und VB.NET nutzen, NuGet Packages,wie man aus Visual Studio Projekten kennt, einbinden und auch Fiddles für ASP.NET MVC erstellen.

dotnetfiddle_newfeatures_20140317

Bild: Screenshots von DotNetFiddle.net

C#: Lookup vs. Dictionary

Lookup (Namespace: System.Linq)

Lookup<Tkey, Tvalue> 
: ILookup<Tkey, Tvalue> 
: IEnumerable<IGroupin<<Tkey, Tvalue>>

A Lookup is a collection which implements the ILookup Interface. It was introduces with LINQ and can be used instead of Dictionary.

A key don’t has to be unique, so you can have multiple entries with the same key. Also the Lookup is immutable, that means you can not add values on the fly, like you could with a List or Dictionary. You can however determine its count (.Count) and you can access the items with [value].

When you look up a key that does not exist in the Lookup, you don’t get a KeyNotFound-Exception but an empty sequence instead.

You cannot directly instantiate a Lookup, it is a result of a LINQ-Selection, which needs a Func for Key-Selection and a Func for Value selection.

Here is an example:

var myList = new List<KeyValuePair<int, string>>
            {
                new KeyValuePair<int, string>(30, "Sam"),
                new KeyValuePair<int, string>(10, "Hans"),
                new KeyValuePair<int, string>(10, "Fred"),
                new KeyValuePair<int, string>(20, "Sepp"),
                new KeyValuePair<int, string>(10, "Ron")
            };

var myLookup = (Lookup<int,string>) myList.ToLookup(
                                             (item)=>item.Key, 
                                             (item)=>item.Value
                                             );

var len = myLookup.Count;
var entry = myLookup[10];

Dictionary (Namespace: System.Collections.Generic)

Dictionary<Tkey, Tvalue> 
: IDictionary<Tkey, Tvalue>
: ICollection<KeyValuePair<Tkey, Tvalue>>, 
: IEnumerable<KeyValuePair<Tkey, Tvalue>>

A key has to be unique, so you can have only one multiple entry with the same key. The Dictionary is mutable, that means you can add values on the fly. Also you can use normal collection methods to determine its count (.Count) and to access the items with [value].

When you look up a key that does not exist you get a KeyNotFound-Exception.
You can directly instantiate a Dictionary.

Here is an example:

var myDictionary = new Dictionary<int, string>();
myDictionary.Add(10,"Hans");
myDictionary.Add(20, "Fred");

var len = myDictionary.Count;
var entry = myDictionary[10];

Blogpost Original Date: 16.02.2010, Updated: 13.12.2013

Pinnwand KW 47 / 2013 – Glimpse Developer Dashboard, Nicht unterstützte Features in Windows Phone, XAML Performance Video

  • Scott Hanselman stellt in seinem Artikel das “Developer Dashboard” Glimpse vor. Persönlich habe ich es noch nicht eingesetzt, ist aber auf jeden Fall eine Option für zukünftige ASP.NET oder MVC Projekte.

Pinnwand KW 46 / 2013 – Vorlagen für Felder in ASP.NET MVC, KnockoutJS, Neu in XAML in Windows 8.1

  • Eine gute Zusammenfassung zum Thema “Vorlagen für Felder” in ASP.NET MVC von Holger Schwichtenberg und Manfred Steyer findet sich bei Windows Developer.
  • Eine dreiteilige Artikelserie “Beginners Guide Knockout.JS” findet man bei Sitepoint