Catalog Search APIs are for editing only!

If you are using Catalog Search APIs for any customer-facing features, you are doing it wrong!

I have seen this problem a couple of times – the search feature on the site is “dead” – it is very slow, and the log file is usually filled with dead lock or timeout error. As it turns out, the search feature was implemented by Catalog Search APIs, which is a big no-no.

To be clear, there are two builtin APIs related to searching in Episerver Commerce: the “fast” one, which can be done via SearchManager, ISearchCriteria and ISearchResults, is the SearchProvider APIs. It’s the indexed search (strictly speaking, you can make it not “indexed”, but that’s beside the point), and the actual search functions will be provided by providers, like LuceneSearchProvider, Solr35SearchProvider, or FindSearchProvider.

Continue reading “Catalog Search APIs are for editing only!”

I was with the EMVPs, and that was a fantastic experience

If there is anything I regret being an Episerver employee, is that I can’t be an EMVP – the gang of awesome Episerver developers which their contributions are widely recognized by the community (I don’t consider myself to be “awesome”, but I try (to be)). The EMVPs can be seen as the evangelists of Episerver frameworks and technologies, they spread their wisdom, experience and best practices to help developers build better solutions, and they give valuable feedback to us to build better frameworks.

EMVP Summit is one of special treat Episerver gives to EMVPs, as a recognition for their contributions, and also a chance – directly than ever – for Episerver to listen to the feedback from their distinguish developers. As a software engineer in Commerce development team, I was sent to team up, to talk, to discuss and to socialize with the EMVP (after winning a small competition with my two teammates, and getting a grant from my wife 🙂 ).

Continue reading “I was with the EMVPs, and that was a fantastic experience”

Debug .NET memory dump with WinDBG – crash course. Part 1

If you ask me what had I been doing the last two weeks – then the answer is I was pulling my hairs.  A customer had a problem with their site as the memory hiked up after catalog imports and stayed there “forever” – and in the end it slowed the site down. I jumped in and almost regretted that decision – had to spent days  messing around with WinDBG and memory dumps. In the end – I found the problem and it was fixed. A lot of hairs were loss in progress, but I learned something about WinDBG – and that’s what I’m sharing today.

WinDBG is probably the most famous tool for debugging stuffs on Windows. Out of the box, it only works with native applications, aka assembly and such – but lucky for us, there are plenty of extensions to allow it to work with .NET application. The “standard” SOS and more advanced extension SOSEX. SOS is included in WinDBG, while you can download SOSEX from here (for 64 bit) or here (for 32 bit) . Download the zip file and extract the dll somewhere.

WinDBG comes with the Windows SDK, not the standard .NET framework, so you’ll probably need to install it separately from here

Continue reading “Debug .NET memory dump with WinDBG – crash course. Part 1”

Why (and when) should you contact Episerver developer support service.

Today I filed a bug, which I should have filed almost one year ago. I saw it several times, I even had solution for it, but I didn’t think/know it was a bug. It was reported here: http://world.episerver.com/forum/developer-forum/Problems-and-bugs/Thread-Container/2016/9/commerce-catalog-randomly-goes-empty-until-website-restart/  and here http://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2016/6/addstaticattributepropertyvalues-object-reference-exception/

I’ve always wanted to say Episerver products are perfect frameworks and have no bugs at all. But that’s not true. Despite of having very talented developers and dedicated QAs, and a very high requirement for quality (“Quality is non-negotiable”), we still miss to catch some (very few) bugs.

Continue reading “Why (and when) should you contact Episerver developer support service.”

Episerver Commerce CustomerContact Events

This post was inspired by this question: http://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2016/9/commerce-manager-contacts-events/

and is an excerpt from my book: https://leanpub.com/proepiservercommerce

You might notice the lacking of events in some parts of the system. We have events for catalog system, for order system, for prices and inventories changes, but that’s not enough. You might want to have events – or at least – the ability to know when something happens. For example, when a customer contact is changed, or edited, or deleted, it would be very nice to do some extra actions.
Sending emails, updating external systems, etc.

Such events are not available out-of-box, so we have to implement our own. How? We don’t have ICustomerContactService (or something similiar) interface where we can write our implementation to replace the default service (and even if there is, it would be a big task to do so). So there’s no “ordinary”, framework-way to do that. However, CustomerContact is built on Business Foundation system, and BF, at its core, is all above extensible and pluggable. We don’t have ICustomerContactService interface, but we have IPlugin
who can do the same, and even more. As we learned in previous chapter, CustomerContact is just another EntityObject and all operations are still done via BusinessManager.Execute(Request) – even we have some nice wrapper methods to make working with it easier. And when Execute(Request) is called, it also runs all registered IPlugin modules.
Continue reading “Episerver Commerce CustomerContact Events”

The hidden danger of dot (Or why should your metafield not contain . in the name)

A dot (.) – it is harmless. What harm can it do, it looks pretty innocent.

And yet it can break your Catalog UI.

Psyduck, from Pokemon Go
A dot can look pretty harmless and innocent, just like a Psyduck. Frankly, its eyes are also two dots.

Catalog UI relies on the Shell UI from CMS to render properties and such. Shell UI, in its hands, needs to know about the metadata of the properties. When you have dot in the metafield names, the MetaDataPropertyMapper will create an Property with that name on site start up. And then when you open All properties mode, Shell UI will request your content type models, and CMS Core will happily return those properties.

Continue reading “The hidden danger of dot (Or why should your metafield not contain . in the name)”

How to check if a coupon was successfully applied

When a customer add a coupon to his/her cart, it’s nice and best practice to show to him/her if the coupon has been applied successfully, or if it was an invalid/not applicable code.

Coupon has been applied successfully
Coupon has been applied successfully

How can you do that?

In old promotion system

When old promotion system run, each successfully applied promotion will be presented by an instance of Discount, which has a property named DiscountCode – this is the coupon used for the promotion (it can of course be null if the promotion requires no coupon).

Continue reading “How to check if a coupon was successfully applied”

Why did I leave HBO (Nordics). Spoiler: it sucks!

As most of us, I spend a fair chunk amount of my free time to watch movies and TV series, and as most of us, on Netflix. While Netflix has some very good content, and they have been adding great original TV series (House of Cards, Daredevil, Stranger Things, Narcos, just to name a few), those have not been enough for me. I want to watch Games of Throne, The Wire, The Sopranos, Silicon Valley etc, but sadly, they are pretty HBO-exclusive, so to watch them, I have two options: either buy the discs (Very expensive), or subscribe to HBO (much cheaper).

Fine, I decided to suspend my Netflix for a month a resume my HBO Nordics subscription. At least for one month to watch the good content there. Last year I did try HBO one month, for free, but I cancelled it – which I have no clear memory why I did. May be it will work this time.

Unfortunately it does not.

Right after I tried HBO again, it’s clear to me why I left HBO at the first place – and sadly, there are several reasons for that.

Continue reading “Why did I leave HBO (Nordics). Spoiler: it sucks!”

Fixing Visual Studio 2015 after update 3

In case you did not notice, Microsoft released Visual Studio 2015 Update 3 a couple of days ago. I immediately jumped in because I have high hope for better stability – VS2015 update 2 has been crashing more open than I would like.

When I updated my VS on my work computer, all went well and it worked right after that without any problem. However when I finally updated my VS on my home computer, problem appears. Everytime I try to open a solution, it crashes! Rendering my VS2015 totally useless. It’s not a problem I can ignore, and I would avoid reinstall it, unless it’s the last resort.

Digging in the event viewers shed a light on what is wrong:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Microsoft.VisualStudio.Composition.CompositionFailedException: An exception was thrown while initializing part "Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerService". ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.InitializeDisplayAndId()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.get_Id()
   at Microsoft.CodeAnalysis.Diagnostics.HostAnalyzerManager.CreateAnalyzerReferencesMap(IEnumerable`1 analyzerReferences)
   at Microsoft.CodeAnalysis.Diagnostics.HostAnalyzerManager..ctor(ImmutableArray`1 hostAnalyzerReferences, ImmutableArray`1 hostAnalyzerPackages, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
   at Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzerService..ctor(IDiagnosticUpdateSourceRegistrationService registrationService, IEnumerable`1 asyncListeners, IWorkspaceDiagnosticAnalyzerProviderService diagnosticAnalyzerProviderService, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue()
   at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create()
   at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState)
   at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState)
   at Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose()
   at Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0()
   at Microsoft.VisualStudio.Composition.DelegateServices.<>c__DisplayClass2_0`1.<As>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.WorkCoordinator.IncrementalAnalyzerProcessor.<>c__DisplayClass15_0.<GetOrderedAnalyzers>b__0(Lazy`2 p)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at System.Collections.Immutable.ImmutableArray.ToImmutableArray[TSource](IEnumerable`1 items)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.WorkCoordinator.IncrementalAnalyzerProcessor.GetOrderedAnalyzers(Registration registration, IEnumerable`1 providers)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.WorkCoordinator.IncrementalAnalyzerProcessor.GetActiveFileIncrementalAnalyzers(Registration registration, IEnumerable`1 providers)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.WorkCoordinator.IncrementalAnalyzerProcessor..ctor(IAsynchronousOperationListener listener, IEnumerable`1 analyzerProviders, Registration registration, Int32 highBackOffTimeSpanInMs, Int32 normalBackOffTimeSpanInMs, Int32 lowBackOffTimeSpanInMs, CancellationToken shutdownToken)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.WorkCoordinator..ctor(IAsynchronousOperationListener listener, IEnumerable`1 analyzerProviders, Registration registration)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.Register(Workspace workspace)
   at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.StartSolutionCrawler()
   at Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractPackage`2.Initialize()
   at Microsoft.VisualStudio.LanguageServices.CSharp.LanguageService.CSharpPackage.Initialize()
Stack:
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
   at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, System.Action`1<System.Exception>)
   at Microsoft.VisualStudio.LanguageServices.CSharp.LanguageService.CSharpPackage.Initialize()
   at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CreateValue()
   at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].LazyInitValue()
   at System.Lazy`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_Value()
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService+WorkCoordinator+IncrementalAnalyzerProcessor+<>c__DisplayClass15_0.<GetOrderedAnalyzers>b__0(System.Lazy`2<Microsoft.CodeAnalysis.SolutionCrawler.IIncrementalAnalyzerProvider,Microsoft.CodeAnalysis.SolutionCrawler.IncrementalAnalyzerProviderMetadata>)
   at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.OrderedEnumerable`1+<GetEnumerator>d__1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Linq.Buffer`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Collections.Immutable.ImmutableArray.CreateRange[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Collections.Immutable.ImmutableArray.ToImmutableArray[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService+WorkCoordinator+IncrementalAnalyzerProcessor.GetOrderedAnalyzers(Registration, System.Collections.Generic.IEnumerable`1<System.Lazy`2<Microsoft.CodeAnalysis.SolutionCrawler.IIncrementalAnalyzerProvider,Microsoft.CodeAnalysis.SolutionCrawler.IncrementalAnalyzerProviderMetadata>>)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService+WorkCoordinator+IncrementalAnalyzerProcessor.GetActiveFileIncrementalAnalyzers(Registration, System.Collections.Generic.IEnumerable`1<System.Lazy`2<Microsoft.CodeAnalysis.SolutionCrawler.IIncrementalAnalyzerProvider,Microsoft.CodeAnalysis.SolutionCrawler.IncrementalAnalyzerProviderMetadata>>)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService+WorkCoordinator+IncrementalAnalyzerProcessor..ctor(Microsoft.CodeAnalysis.Shared.TestHooks.IAsynchronousOperationListener, System.Collections.Generic.IEnumerable`1<System.Lazy`2<Microsoft.CodeAnalysis.SolutionCrawler.IIncrementalAnalyzerProvider,Microsoft.CodeAnalysis.SolutionCrawler.IncrementalAnalyzerProviderMetadata>>, Registration, Int32, Int32, Int32, System.Threading.CancellationToken)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService+WorkCoordinator..ctor(Microsoft.CodeAnalysis.Shared.TestHooks.IAsynchronousOperationListener, System.Collections.Generic.IEnumerable`1<System.Lazy`2<Microsoft.CodeAnalysis.SolutionCrawler.IIncrementalAnalyzerProvider,Microsoft.CodeAnalysis.SolutionCrawler.IncrementalAnalyzerProviderMetadata>>, Registration)
   at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.Register(Microsoft.CodeAnalysis.Workspace)
   at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.StartSolutionCrawler()
   at Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractPackage`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Initialize()
   at Microsoft.VisualStudio.LanguageServices.CSharp.LanguageService.CSharpPackage.Initialize()
   at Microsoft.VisualStudio.Shell.Package.Microsoft.VisualStudio.Shell.Interop.IVsPackage.SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider)
   at Microsoft.VisualStudio.Shell.Interop.IVsUIDataSource.Invoke(System.String, System.Object, System.Object ByRef)
   at Microsoft.Internal.VisualStudio.PlatformUI.DataSource.Invoke(System.String, System.Object, System.Object ByRef)
   at Microsoft.VisualStudio.PlatformUI.VsCommand.Execute(System.Object)
   at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource, Boolean)
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

So System.Reflection.Metadata, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ was missing.

But why? and missing from where? A quick search shows that it was used for Roslyn, and dnx uses version 1.1. Visual Studio 2015 also crashes if I try to open Tools => Text Editor => C# => Advanced, where the Roslyn options are. So the problem was Roslyn unable to load an assembly it needs, then the entire VS crashes. Lame!

It seems unable to just reinstall Roslyn alone, so my best bet is to put the correct System.Reflection.Metadata version … somewhere. It’s not clear that where should it be – so I should put it in the most common place – the GAC – Global Assemblies Cache.

This is an attempt to fix:

First, I need to have the assembly. This will require nuget 3.x to run, so you can download the latest version (3.4.4 at this time of writing) from here.

nuget install system.reflection.metadata -version 1.2.0

And then open your Developer command prompt for VS2015, and cd to the lib folder of downloaded package, for me it’s D:\Downloads\System.Reflection.Metadata.1.2.0\lib\netstandard1.1, and run the famous gacutil to install the assembly to GAC:

D:\Downloads\System.Reflection.Metadata.1.2.0\lib\netstandard1.1>gacutil -i System.Reflection.Metadata.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

Open my solution again and it works! It might be not the best solution, but it works and I don’t have to reinstall VS2015, so I won’t complain.