ERROR - Key '' does not exist in this pattern space

Not able to see the "Best pattern matches" in Experience Profile and has an error that similar to "Key '' does not exist in this pattern space" in the log.

TL;DR

Check the Pattern field value of Pattern Card (In Raw mode), may be empty.

I got this error when i try to add a matched pattern to the contact programmatically, and i found out some other people also have this error.

I follow the advice they suggested:

1. Check the Profile key name (the Name field value, not item name)

2. Deploy marketing definitions

3. Rebuild the search index (The indexes related to marketing)

4. Rebuild the reporting database

All of above doesn't help me to resolve the issue.

For me the issue is a little bit different. The key name in the error message is random. I'm 100% sure they are exists, but they belong to other profile. So the question is why Sitecore try to find the value for other profile??

After spent some time to looking through the code, I found the Sitecore will load all the Profiles and the profile for your pattern will be the first. If the pattern field doesn't have a value then it will be ignored. 

This is explain why Sitecore try to load other profile.