How to fix the Failed to load expression host assembly error in a SharePoint custom solution

I was writing a custom Reporting Services local report , placed in a SharePoint Web Part, and got this error:

Failed to load expression host assembly. Details: Could not load file or assembly ‘expression_host_31f4d73d84764f4b9a7332f3673bdf0b, Version=10.8.30729.1, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)

This was fixed by setting the ExecuteReportInCurrentAppDomain property like so:

reportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);