.NET 3.5 (NetFx3) Installation Fails With Error 3017 And HRESULT 80070BC9 on Server 2012 R2

Recently, when rebuilding my System Center Configuration Manager 2012 lab, I ran into an issue.  I was preinstalling SQL Server 2012 and hit a snag.

Image: Error while enabling Windows Feature: NetFx3 Please enable Windows Feature NetFx3 from Windows management tools and then run setup again.

It seems that for whatever reason the SQL installer could not install the .NET 3.5 framework. Thinking this would be a simple fix I opened up PowerShell, fired off a quick Install-WindowsFeature and… it also failed.  Puzzled I headed to the Internet.  As it turns out this was a common problem and quite a few others suggested using DISM in online mode to install the feature either by pointing direct to the source media

Dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess

or by obtaining the feature from windows update

Dism /online /enable-feature /featurename:NetFx3 /All

Neither worked.  Both returned the error 3017, which basically means “something broke, you need to restart to roll back the installation”.  Examining C:\Windows\Logs\DISM\dism.log revealed the following:

DISM Package Manager: PID=2536 TID=352 Error in operation: (null) (CBS HRESULT=0x80070bc9) - CCbsConUIHandler::Error
DISM Package Manager: PID=2536 TID=2292 Failed finalizing changes. - CDISMPackageManager::Internal_Finalize(hr:0x80070bc9)
DISM Package Manager: PID=2536 TID=2292 Failed processing package changes with session options - CDISMPackageManager::ProcessChangesWithOptions(hr:0x80070bc9)
DISM Package Manager: PID=2536 TID=2292 Failed ProcessChanges. - CPackageManagerCLIHandler::Private_ProcessFeatureChange(hr:0x80070bc9)
DISM Package Manager: PID=2536 TID=2292 Failed while processing command enable-feature. - CPackageManagerCLIHandler::ExecuteCmdLine(hr:0x80070bc9)
DISM Package Manager: PID=2536 TID=2292 Further logs for online package and feature related operations can be found at %WINDIR%\logs\CBS\cbs.log - CPackageManagerCLIHandler::ExecuteCmdLine
DISM.EXE: DISM Package Manager processed the command line but failed. HRESULT=80070BC9

While not terribly helpful the DISM log tells us where we can get more information.  The cbs.log showed:

Info CSI 000000a7 Begin executing advanced installer phase 34 (0x00000022) index 246 (0x00000000000000f6) (sequence 278)
     Old component: [l:0]""
     New component: [ml:276{138},l:274{137}]"WWF-PerfCnt_ini, Culture=neutral, Version=6.3.9600.16384, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=x86, versionScope=NonSxS"
     Install mode: install
     Installer ID: {d82eedee-854e-4f9a-b458-ae1bc62a0e6b}
     Installer name: [16]"LodCtr Installer"
Info CSI 000000a8 Performing 1 operations; 1 are not lock/unlock and follow:
     (0) LockComponentPath (10): flags: 0 comp: {l:16 b:547843cbc942cf0124030000e4088408} pathid: {l:16 b:547843cbc942cf0125030000e4088408} path: [l:184{92}]"\SystemRoot\WinSxS\x86_wwf-perfcnt_ini_31bf3856ad364e35_6.3.9600.16384_none_086429b116eaedfd" pid: 8e4 starttime: 130396348381515426 (0x01cf42c9b949cea2)
Error CSI 00000002@2014/3/18:16:47:48.324 (F) Logged @2014/3/18:16:47:48.324 : [ml:242{121},l:240{120}]"RegQueryValue_ServiceFirstCounter("SYSTEM\CurrentControlSet\Services","Windows Workflow Foundation 3.0.0.0") fails (2,0)"
[gle=0x80004005]
Error CSI 00000003@2014/3/18:16:47:48.324 (F) Logged @2014/3/18:16:47:48.324 : [ml:354{177},l:352{176}]"Extract actual INI path "C:\Windows\inf\Windows Workflow Foundation 3.0.0.0\PerfCounters.ini" from "C:\Windows\inf\Windows Workflow Foundation 3.0.0.0000\PerfCounters_D.ini"."
[gle=0x80004005]
Error CSI 00000004@2014/3/18:16:47:48.324 (F) Logged @2014/3/18:16:47:48.324 : [ml:354{177},l:352{176}]"Extract actual INI path "C:\Windows\inf\Windows Workflow Foundation 3.0.0.0\PerfCounters.ini" from "C:\Windows\inf\Windows Workflow Foundation 3.0.0.0409\PerfCounters_D.ini"."
[gle=0x80004005]
Error CSI 00000005@2014/3/18:16:47:48.340 (F) CMIADAPTER: Inner Error Message from AI HRESULT = HRESULT_FROM_WIN32(1010)
[
[44]"The configuration registry key is invalid.
"
]
[gle=0x80004005]
Error CSI 00000006@2014/3/18:16:47:48.340 (F) CMIADAPTER: AI failed. HRESULT = HRESULT_FROM_WIN32(1010)
...

Checking the registry key mentioned in the error revealed that the key was related to performance counters. A little more research led me to the lodctr.exe tool, and running

lodctr.exe /R

performed a rebuild of the performance counters. After rebuilding the performance counters installing the .Net 3.5 framework feature with DISM succeeded.