1

I've recently imported a couple of the Test projects from a site running Sitecore 8.2 into a site running 7.2. When I run the tests, they all error with the message

Could not resolve type name: Sitecore.Data.DefaultDatabase, Sitecore.Kernel.

In app.config, I found this:

<!-- DATABASE TYPE
     For Sitecore versions prior to 8.2 should be 'Sitecore.Data.Database, Sitecore.Kernel'.
     For Sitecore 8.2 and later should be 'Sitecore.Data.DefaultDatabase, Sitecore.Kernel'. -->
<sc.variable name="databaseType" value="Sitecore.Data.Database, Sitecore.Kernel" />

So I replaced all instances in the solution of Sitecore.Data.DefaultDatabase with Sitecore.Data.Database, but I still get the same error.

The test projects are using FakeDb.

2
  • Matt - did you copy the whole test project into your 7.2 implementation, or setup a new one and copy in the test code? Make sure that you don't have a patch file like the one that @Mark mentioned that is overriding that class name.
    – Richard Seal
    Commented Sep 6, 2017 at 13:03
  • I copied the whole project and then changed the configuration and Nuget references to work for 7.2. I have the mentioned patch file, but I've changed the values to Sitecore.Data.Database. Perhaps I should just remove the patch altogether.
    – Matt Eno
    Commented Sep 6, 2017 at 22:09

2 Answers 2

2

Sitecore 8.2 introduced changes to the way Database is handled internally. To make FakeDB work on 8.2, you need to add a configuration snippet to App_Config\Include containing the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <databases>
      <database id="core">
        <patch:attribute name="type">Sitecore.Data.DefaultDatabase, Sitecore.Kernel</patch:attribute>
      </database>
      <database id="master">
        <patch:attribute name="type">Sitecore.Data.DefaultDatabase, Sitecore.Kernel</patch:attribute>
      </database>
      <database id="web">
        <patch:attribute name="type">Sitecore.Data.DefaultDatabase, Sitecore.Kernel</patch:attribute>
      </database>
    </databases>
    <!-- EVENTING -->
    <eventing defaultProvider="sitecore">
      <providers>
        <clear />
        <add name="sitecore" type="Sitecore.Eventing.EventProvider, Sitecore.Kernel" systemDatabaseName="core" />
      </providers>
    </eventing>
  </sitecore>
</configuration>

More information to be found here: Sitecore 8.2 - Could not create instance of type: Sitecore.Data.Database. No matching constructor was found.

3
  • Thanks, but I need it to work the other way around, ie; my solution is for a Sitecore 7.2 site.
    – Matt Eno
    Commented Sep 6, 2017 at 22:07
  • 1
    In which case the solution would be the opposite. You can assume it's patched like I describe here; find that patch and remove it.
    – Mark Cassidy
    Commented Sep 6, 2017 at 22:09
  • Yeah, I just tried removing that patch, and still the same thing. There's literally no reference to the string "Sitecore.Data.DefaultDatabase" anywhere in the solution. I'm wondering if some of the other assemblies like Autofixture might be using too new a version which specifically expects Sitecore.Data.DefaultDatabase. Perhaps downgrading them may work.
    – Matt Eno
    Commented Sep 6, 2017 at 23:22
0

It turns out that I had a couple of the patch files hanging around on the file system. They weren't in the solution, so I didn't spot them at first until I did a search through the file system for "Sitecore.Data.DefaultDatabase".

Now I have a whole new unrelated error to work through.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.