Search code examples
sharepointsharepoint-2010sharepoint-2013microsoft-fakes

Unable to create a fakes assembly for a SharePoint project


I've found that when trying to create a fakes assembly for a SharePoint project that references certain SharePoint libraries that I get errors similar to:

Failed to load properly Derived method 'RequiresWebPartClientScript' in type 'Microsoft.Office.Server.Search.WebControls.ScriptWebPart' from assembly 'Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' cannot reduce access.    

This commonly occurs where the SharePoint project references libraries that are not in the GAC such as: Microsoft.SharePoint.ApplicationPages and Microsoft.ApplicationPages.Administration


Solution

  • It seems that this problem is caused by the fakes generator being unable to resolve the reference when attempting to create fakes. The issue can be worked around by adding a reference to the offending library to the project that will contain the fakes assembly.

    For example, if I have a project 'My.SharePoint.Stuff' and I want to run tests in a project 'My.SharePoint.Stuff.Tests' then I would generate a fakes assembly for My.SharePoint.Stuff in My.SharePoint.Stuff.Tests.

    Where this fails as described above, the solution is to add a reference to the assembly that is described in the error message to the My.SharePoint.Project.Tests project and then recreate the fake.