Tuesday, March 20, 2018

System.Collections.Concurrent.ConcurrentBag Has a hissy fit.


It's well acknowledged that installing Sitecore Commerce 8.2.1 can be beastly to install and more so in a scaled environment. I have done many times now, I was beginning to find it straightforward... let your guard down for a moment and BOOM! Microsoft come a'callin. 

All credit to Tan Vu from Sitecore support, he's great ! - I'm just the documenter. 

Unable to cast object of type 'System.Collections.Concurrent.ConcurrentBag`1[Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration]' to type 'System.Collections.Generic.IReadOnlyCollection`1[Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration]'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Collections.Concurrent.ConcurrentBag`1[Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration]' to type 'System.Collections.Generic.IReadOnlyCollection`1[Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration]'.

 


This is what might have happened to you:
  • .NET framework 4.5.2 contains System.Collections.Concurrent.ConcurrentBag<T> class from System.dll which implement IReadOnlyCollection<T> interface, but due to the some security updates from Microsoft side, ConcurrentBag<T> was changed, and as a result, it does not implement IReadOnlyCollection<T>. In order to check whether one of the aforementioned security updates was installed on your server, you can review the version of C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll 
    For the regular .NET framework 4.5.2 this version looks like 4.5.2... , but if security update was installed it will look like 4.0.30319.36388 (It seems to me that these security updates were built based on .NET framework 4.0 which did not have IReadOnlyCollection<T> interface at all.
  • In this way, if the server has .NET framework 4.5.2 without aforementioned security updates, provided by Microsoft, then System.dll will have System.Collections.Concurrent.ConcurrentBag<T> which implement IReadOnlyCollection<T> interface, in contrast to .NET framework 4.5.2 with security update. This error may happen because of these security updates.
Thus, to fix this problem, please update the .NET framework version on your server to at least 4.6.1
Then, please update the following configuration on your Web.config file:

  • <compilation defaultLanguage="c#" debug="false" targetFramework="4.6.1">
  • <httpRuntime targetFramework="4.6.1" ..

Thanks again Vu Tan!

Hope this helps someone out there who doesn't have a Vu Tan to lean on :-) 










No comments:

Post a Comment