Thursday 1 December 2016

Error when installing Docker on Windows Server 2016

When following the install guide here, ensure that you are running PowerShell as x64 (not x86!) otherwise you'll get the following error when trying to run the command:

PS C:\Windows\system32> Install-Package -Name docker -ProviderName DockerMsftProvider

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'DockerDefault'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
Install-Package : The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Install-Package -Name docker -ProviderName DockerMsftProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],
   Exception
    + FullyQualifiedErrorId : FailedToDownload,Install-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallP
   ackage

Friday 17 June 2016

Owin Startup Not Executed

I've been bashing my head over this problem today. My Owin Startup class wasn't being executed. I'd followed the usual instructions of ensuring the "Microsoft.Owin.Host.SystemWeb" package was installed. I had the correct attribute on the assembly ([assembly: OwinStartup(typeof(StartupDemo.TestStartup))]), clearing the ASP.NET cache, etc etc.

Eventually I found that if you have set a friendly name for your startup class (in the instance where you may have multiple Startup.cs files) - then you need to also make sure you add the friendly name to your appSettings in the web.config too!

<add key="owin:appStartup" value="StartupDemo.ProductionStartup"/>

Doh!

Monday 14 December 2015

Feature Folders in ASP.NET 5 (RC1) with MVC 6

Feature folders are a great way of structuring an MVC project in order to quickly and easily find the files for areas of your website.

You can turn a typical structure like this:

- Website
  + Content
  + Controllers
  + Models
  + Views

in to this:
- Website
  - Features
    - Portfolio
        Index.cshtml
        Index.js
        IndexViewModel.cs

This has been possible for a while now, however the API has changed a bit with ASP.NET 5 (as well as all the beta versions). Currently in ASP.NET 5 RC1 this is how you do it:

Create a new view engine, something like:

FeatureViewLocationRazorViewEngine.cs

public class FeatureViewLocationRazorViewEngine : RazorViewEngine
{
 private readonly string[] _featureFolderViewLocationFormats;

  public FeatureViewLocationRazorViewEngine(IRazorPageFactory pageFactory, IRazorViewFactory viewFactory, IOptions<RazorViewEngineOptions> options, IViewLocationCache viewLocationCache)
  :base(pageFactory, viewFactory, options, viewLocationCache)
 {
  _featureFolderViewLocationFormats = new[]
   {
   "~/Features/{1}/{0}.cshtml",
   "~/Features/{1}/{0}.vbhtml",
   "~/Features/Shared/{0}.cshtml",
   "~/Features/Shared/{0}.vbhtml"
   };
 }

  public override IEnumerable<string> ViewLocationFormats => _featureFolderViewLocationFormats;
}
Then modify the startup file:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
 services.AddSingleton<IRazorViewEngine, FeatureViewLocationRazorViewEngine>();
 services.AddMvc();
}
That's it!

Thursday 11 December 2014

Navigating away from a page in Windows Phone 8.1 with Prism throws a System.ArgumentNullException

I just had a little headache with something that should be fairly trivial, but unfortunately the exception & stack trace weren't particularly descriptive. I was navigating from one page to another in my universal app. The navigation worked for Windows, but not for Phone, and I got the following:

{System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
   at Microsoft.Practices.Prism.StoreApps.VisualStateAwarePage.OnNavigatedFrom(NavigationEventArgs e)}


Well it turns out when you create a new Windows Phone XAML page in Visual Studio, it kindly overrides the OnNavigatedTo method in the code behind (of course I didn't look here, I'm using MVVM!), which seems to throw Prism out of whack. Remove the overriden method (or just call it's base) and navigation succeeds, yippee.

Sunday 5 October 2014

Visual Studio 2014 CTP Crashes on Get Latest when using a touch screen

So, just a quick one. I downloaded Visual Studio 2014 CTP and tried to get some code from source control. Unfortunately, Visual Studio crashes without warning. A quick look in the event viewer shows that it's a touch related issue (null reference exception). I installed VS on my Surface Pro, and when using the touch pad it seems to work fine.


Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.

Exception Info: System.NullReferenceException
Stack:
   at System.Windows.Input.StylusLogic.IsTouchStylusDevice(System.Windows.Input.StylusDevice)
(Complete stacktrace omitted) Looks like I'll be sticking with the trackpad for now :-)

Sunday 28 September 2014

Introduction to ASP.NET MVC

I did a talk for Black Marble's Friday training last month. I recently passed a Microsoft certification on MVC and it seemed appropriate to talk about what I had learnt. There are also some tips on Microsoft exams.



The slides are available here

Friday 14 March 2014

Diagnosing a lean condition using VCDS-Lite

I recently went on a rolling road day to get an idea of my current cars performance (Seat Leon Cupra R, 1.8T), and was happy to find it wasn't too down on power for a 9 year old car.



Unfortunately I was (ill-) advised that the engine was running lean (the air to fuel ratio was too high). There are several areas to look at when diagnosing this, but the common one tends to be an air leak in the crankcase ventilation system.



I sprayed all the pipes in the system with (flammable) electrical contact cleaner. If there is a leak, then the engine will ingest some of the fluid into the engine via the leak and it will combust, creating an audible RPM change. Unfortunately this didn't help in diagnosing, but did lead me on to purchasing a VCDS-Lite Registration ($99 / £60) that enabled me to use my KKL VAG-COM cable I got from Amazon for around £6. The free version does some basic stuff such as reading error codes, but the registered version provides extended logging capabilities.



By measuring blocks 001 (RPM) and 031 (Lambda Control Actual & Specification) it provided enough data to calculate the air/fuel ratio requested by the ECU and the actual fuelling measured by the lambda control sensor. Just to note, a faulty lambda sensor is usually easy to spot, as the figures provided by it are either flat-lining or erratic. The figure must be multiplied by 14.7 (stoichiometric) to calculate the AFR.

Anyway, after consulting with one of the tuners on SeatCupra.net, the 1.8T BAM engines typically run more lean on the standard ECU map than other cars do, which is the only reason I can think of why I was ill-advised to the running of the engine. To confirm this, I used VCDS to to log the above measuring blocks (in 3rd gear, from 2500rpm to 6800rpm) to log the data required. As you can see in the graph below, the fuelling is almost exactly as the ECU requests (as the manufacturer intended) - and where it differs is where the engine is running richer (lower air fuel ratio, therefore more fuel is being combusted). Running rich is much less deteritmental to the engine, and whilst it is an increase in fuel consumption, it also means that the fuel keeps the cylinder walls cooler. Running lean can mean detonation, which is very bad.