Help Library Agent exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary

HelpLibAgent.exe crashes while accessing the help feature in Visual Studio 2010 on a Windows 7system.

Based on the app evt log I found the following stack trace:

.NET Runtime version 2.0.50727.4927 - Profiling flag set, but required environment (COR_PROFILER) was not set.

Faulting application name: HelpLibAgent.exe, version: 1.0.30319.1, time stamp: 0x4ba21585

Faulting module name: KERNELBASE.dll, version: 6.1.7600.16385, time stamp: 0x4a5bdaae

Exception code: 0xe0434352

Fault offset: 0x00009617

Faulting process id: 0xcfc

Faulting application start time: 0x01caebbf97f03542

Faulting application path: C:\Program Files\Microsoft Help Viewer\v1.0\HelpLibAgent.exe

Faulting module path: C:\Windows\system32\KERNELBASE.dll

Report Id: d81a6ae2-57b2-11df-8888-001676c5f454

Application: HelpLibAgent.exe

Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.Collections.Generic.KeyNotFoundException

Stack:

Server stack trace:

at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

at Microsoft.Help.ProtocolHandlerPool.ReturnProtocolHandler(Guid protocolId, Boolean destroy)

at Microsoft.Help.InvisibleWindow.HandleHttpRequest(Object sender, HttpRequestEventArgs e)

at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)

at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

at Microsoft.Help.HelpHttpServer.IncomingRequestCallback(System.IAsyncResult)

at System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage)

at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessageSink)

at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()

at System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(System.Object)

at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)

at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()

at System.Threading.ThreadPoolWorkQueue.Dispatch()

at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

.NET Runtime version 4.0.30319.1 - Loading profiler failed. COR_ENABLE_PROFILING was set properly, but COR_PROFILER was not. COR_PROFILER must be set to the CLSID of the profiler to load. Process ID (decimal): 3324. Message ID: [0x2500].

Help Library Agent exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary

After analyzing the issue, I found that the local store (C:\ProgramData\Microsoft\HelpLibrary) was corrupted because:

1. No books are mapped in Scopes.xml
2. No packages are present
3. No catalog partitions are present

To fix the problem please follow these steps:

1. Go to helplibmanager.exe.config C:\Program Files\Microsoft Help Viewer\v1.0\
2. open helplibmanager.exe.config (in notepad.exe)
3. change key="FirstTimeRun" value="False" to key="FirstTimeRun" value="True
4. Run Help Library manager again from shortcut or IDE => help menu and it should give you a dialog to setup new content local store and you can install content from media or online.

You may also find the following error message in the app evt log:

Description:
An error occurred while updating local content: Microsoft.Help.CacheLib.CacheLibDownloadException: An error occurred while the BITS service was transferring 'https://packages.mtps.microsoft.com/visual_studio_22759845_vs_100_en-us_1(9444da16-9b8f-d8cd-4f30-2fe26ccd6e03).cab' to 'C:\ProgramData\Microsoft\HelpLibrary\content\Microsoft\incoming\0b2898b2-71b6-4fe1-b6f6-58e1df779364\Visual_Studio_22759845_VS_100_en-us_1.cab'. The error context was 'RemoteFile', and the error code was '0x80200013'.
at Microsoft.Help.CacheLib.DocumentationCache.<>c__DisplayClass6c.<DownloadWebContent>b__69(IGrouping`2 chunk)
at Microsoft.Help.CacheLib.Extensions.Each[T](IEnumerable`1 that, Action`1 lambda)
at Microsoft.Help.CacheLib.DocumentationCache.DownloadWebContent(IEnumerable`1 webDownloads, Int32 totalDownloads, Int32 completedDownloads, String workingDirectory, StatusCallback`1 statusCallback)
at Microsoft.Help.CacheLib.DocumentationCache.Download(ChangeDescription change, StatusCallback`1 statusCallback)
at Microsoft.Help.CacheLib.DocumentationCache.Update(VendorName vendorName, Boolean checkForOnlineUpdates, StatusCallback`1 statusCallback, CertificateCheckCallback certCheckCallback)
at Microsoft.Help.CacheLib.CacheManager.<>c__DisplayClass24.<UpdateAsync>b__23()
at Microsoft.Help.CacheLib.AsyncOperationRunner.Run(Object state)

This issue can occur if the proxy server does not support HTTP 1.1 range request. There is a Windows update support article https://support.microsoft.com/kb/910337 with details on this error and here the quote that describes the bits error: Error 0x80200013 BITS can request ranges of updates. If the network proxy or firewall device does not support range requests, BITS cannot download updates. Therefore, BITS returns the 0x80200013 error code. When this problem occurs, the %windir%\Windowsupdate.log displays the following entry: Download job failed due to insufficient range support. To resolve this problem, contact the vendor of the network proxy or firewall device.

And here is the quote from BITS documentation explaining this:

When you copy a file by using BITS in background mode, the file is copied in multiple small parts. To perform this kind of copy operation, BITS uses the HTTP 1.1 Content-Range header. If you are behind a proxy server or behind a firewall that removes this header, the file copy operation is unsuccessful.

In order to fix the issue, we need some other proxy or get the proxy settings updated.