0

I am getting an error as:

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

While accessing Sitecore FakeDB in my MSTEST unit testing project.

  • Sitecore Version : 8.2 update 2
  • Sitecore FakeDB: 1.7.4
  • .Net Framework: 4.5.2

What can be the issue here?

7
  • can you check the version of Microsoft.Extensions.DependencyInjection dll in your website? Mar 31 at 12:43
  • In my Sitecore application it is 1.0.0.20622. Mar 31 at 12:49
  • Not sure how you are referencing the dll (nuget package or dll reference) in your Test project, but you can take a look at what version it is set in the Project/References. Mar 31 at 12:50
  • I have DLL reference of Sitecore.Kernel.dll v8.2 update 2 same dll i have referred in Unit testing project whereas I have referred nuget package of Sitecore Fake DB v 1.7.4. With higher version of fakedb dll is not getting resolved as i have dot net framework 4.5.2 Mar 31 at 12:54
  • Can you try to add a reference in your Test project to the Microsoft.Extensions.DependencyInjection dll or use the nuget package? Mar 31 at 13:15
1

I remember having some issues with error messages not corresponding to the actual issue. If you can make sure of all of these (assuming you are following Helix principles here):

Declare databases configuration on each projects (ex : Feature/YourFeautre/App_Config/Include/Feature/Sitecore.license.config)

<?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>

Declare the license configuration on each projects.(ex : Feature/YourFeautre/App_Config/Include/Feature/Sitecore.license.config)

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <setting name="LicenseFile" value="C:\inetpub\wwwroot\yourInstance\App_Data\license.xml" />
    </settings>
  </sitecore>
</configuration>

Then in your tests, you should be using these :

using Sitecore.Data;
using Sitecore.FakeDb;
using Sitecore.Mvc.Presentation;
using Xunit;

In your projects references, you should have those : enter image description here

Official doc said you need those :

Lucene.Net.dll
Sitecore.Analytics.dll
Sitecore.Kernel.dll
Sitecore.Logging.dll
Sitecore.Nexus.dll

But I make it work without Sitecore.Analytics.dll and Sitecore.Logging.dll

After it is all said and done, make sure you are using compatible versions within your projects. I think your Microsoft.Extensions.DependencyInjection is good, would also make sure to have Microsoft.Extensions.DependencyInjection.Abstractions in your references. So within your packages.config it should look like this :

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <!-- [...your other packages...] -->
  <package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net452" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net452" />
</packages>

I would also recommend to take a look at this answer : https://stackoverflow.com/questions/39802162/what-is-the-minimum-nugets-footprint-for-sitecore-fakedb-tests/39802163 because it feels like, in your similar case, you would end up using this fakedb version :

 <package id="Sitecore.FakeDb" version="1.2.2" targetFramework="net452" />

and also include sitecore.logging

<package id="Sitecore.Logging.NoReferences" version="8.2.160729" targetFramework="net452" developmentDependency="true" />
1

You should make sure that your Test project has at least the following references:

<packages>
  <package id="Lucene.Net" version="3.0.3" targetFramework="net452" />
  <package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net452" />
  <package id="Sitecore.FakeDb" version="1.7.4" targetFramework="net452" />
  <package id="Sitecore.Kernel.NoReferences" version="8.2.161221" targetFramework="net452" developmentDependency="true" />
  <package id="Sitecore.Logging.NoReferences" version="8.2.161221" targetFramework="net452" developmentDependency="true" />
  <package id="Sitecore.Nexus.NoReferences" version="8.2.161221" targetFramework="net452" developmentDependency="true" />
</packages>

You only need to add two nuget packages in your solution with the dependencies: Sitecore.Nexus and Microsoft.Extensions.DependencyInjection.

0
0

Thanks for the Response.

I have reinstalled Sitecore using nuget package. I have verified steps provided Jean-Nicolas G. response.

It did worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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