XC 10 - Tip #8: When assembly hell breaks loose - hunt & fix

XC 10 - Tip #8: When assembly hell breaks loose - hunt & fix

Just a few days before a big milestone, we need to deliver our Sitecore Commerce solution to a customer, Sitecore decides to bring out version 10.1. In my daily development flow, I restart my Sitecore Commerce Engine project again from Visual studio to do some debugging... and everything stops working.

When the Sitecore Commerce Engine stops working, the first thing I do is opening the local URL https://localhost:5000/api/$metadata to see if everything is ok. But this time it was NOT ok:

[
  "Could not load file or assembly 'Sitecore.Commerce.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)"
]

Ehhh.... 7.0.0.0? We are still on Sitecore Commerce version 10.0, and most assemblies have version 6.0.92.0... It was almost the end of the day. So after some investigations we assumed something went wrong with the NuGet feed of Sitecore (we had a similar issue before), a colleague created a support ticket with Sitecore, and we called it a day.

This morning the deployments to our test server were broken as well, and none of my team members could continue working on their local machines anymore. You don't do much Sitecore Commerce development with a broken Sitecore Commerce Engine. I decided to do some more digging...

NuGet package management

The first thing is why are NuGet packages automatically updated... Because the Sitecore.Commerce.Engine application is always rebuilt, we have a NuGet configuration file that updates assemblies automatically:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!--
  Used to specify the default Sources for list, install and update.
  -->
    <packageSources>
        <add key="Official Sitecore" value="https://sitecore.myget.org/F/sc-packages/api/v3/index.json" />
        <add key="Stylelabs_PartnerPublic" value="https://slpartners.myget.org/F/m-public/api/v3/index.json" />
        <add key="Official Sitecore Commerce" value="https://sitecore.myget.org/F/sc-commerce-packages/api/v3/index.json" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    </packageSources>


    <activePackageSource>
        <!-- this tells that all of them are active https://sitecore.myget.org/F/sc-commerce-packages/api/v3/index.json -->
        <add key="All" value="(Aggregate source)" />
    </activePackageSource>
    <packageRestore>
        <add key="enabled" value="True" />
        <add key="automatic" value="True" />
    </packageRestore>
    <solution>
        <add key="disableSourceControlIntegration" value="true" />
    </solution>
    <config>
        <add key="globalPackagesFolder" value="./packages" />
    </config>
</configuration>

The important part in this file:

    <packageRestore>
        <add key="enabled" value="True" />
        <add key="automatic" value="True" />
    </packageRestore>

This would normally never lead to issues, but now it did!

On the Sitecore XP side, Sitecore provides all required assemblies already in the bin folder of the site, and we exclude these assemblies from project deployment using the approach developed by Anders Laub. So these issues will not occur that fast on Sitecore XP.

Assembly binding issues

In the old .NET days when I had assembly loading issues, the first thing I did was open up Fuslogvw.exe (Assembly Binding Log Viewer). For .NET Core this tool does not work anymore. After some searching, I stumbled across a GitHub issue that describes that it is replaced by an environment variable setting called COREHOST_TRACE.

I headed over to my project Debug output folder ...\CommerceEngine\src\Project\Sitecore.Commerce.Engine\bin\Debug\netcoreapp3.1 and executed the following commands:

set COREHOST_TRACE=1
dotnet Sitecore.Commerce.Engine.dll

I now got a huge amount of output in my console window. Luckily enough I use ConEmu with the largest buffer size enabled and using the built-in search feature I found that multiple assemblies were now on version 7.0.34. Something was clearly wrong...

When I checked the file Sitecore.Commerce.Engine.deps.json which generated next to Sitecore.Commerce.Engine.dll I saw multiple wrong dependencies, for example:

      "Sitecore.Commerce.Plugin.BusinessUsers/6.0.92": {
        "dependencies": {
          "Sitecore.Commerce.Plugin.Shops": "6.0.92",
          "Sitecore.Commerce.Plugin.Views": "7.0.34"
        },

How can a 10.0 assembly with version 6.0.92 be dependent on a 7.0.34 assembly of Sitecore 10.1?!

Determining assembly versions quickly

I opened up the file explorer and did the following steps to get a better overview of what assemblies were affected:

  1. While in the netcoreapp3.1 folder, right-click on the column row and select “More…”
  2. Search for and mark the item called “File version” and click OK
  3. You should now see a column with the version number!

After string on the version column I found three assemblies with version 7.0.34.0:

No alt text provided for this image

Although most colleagues working on the project already had "updated" their assemblies and ruined their system, there was one colleague that had its day off. I called him up, asked for a zip file with his "old" assemblies, and after a quick patch of copying over the three "old" assemblies everything started working again.

A simple workaround

While still waiting for Sitecore to fix this issue, I created a simple workaround so we can finally continue working and deploying:

No alt text provided for this image

I added the "old" versions of the assemblies that were affected to the root of the project, and on the properties set Copy to Output Directory to Copy always.

This solves the issue for now, let's hope Sitecore comes with a solution fast.



G?ran Halvarsson

Experienced Fullstack & Sitecore MVP | AI Enthusiast | .NET, Azure, Kubernetes, Sitecore Specialist

4 å¹´

You are a true life savior. Thank's a lot! I was going crazy. Thanks again for this!!!

赞
回复

要查看或添加评论,请登录

Serge van den Oever的更多文章

  • SUGCON 2024 - my three cents...

    SUGCON 2024 - my three cents...

    Jason St-Cyr from Sitecore, although unable to attend the SUGCON conference in Dublin in person, provided insightful…

    2 条评论
  • Sitecore User Group Netherlands meeting @ Macaw

    Sitecore User Group Netherlands meeting @ Macaw

    Tuesday, September 27 the Dutch Sitecore User Group (SUGNL) came together at the Dutch headquarters of Macaw in the…

    1 条评论
  • What do we know about XM Cloud?

    What do we know about XM Cloud?

    As Sitecore MVPs, we had different sessions with Sitecore the last few months to keep us up to date on what is…

  • Sitecore demo portal ain't no XM Cloud

    Sitecore demo portal ain't no XM Cloud

    After my stupid blunder of mixing up Sitecore demo portal and XM Cloud I had to rewrite some blog posts[1][2], and do…

  • Azure Fluid Relay and Fluid Framework

    Azure Fluid Relay and Fluid Framework

    Microsoft made a great managed cloud service available on Azure called Azure Fluid Relay that enables Fluid Framework…

  • DynaMail - send data-driven, multi-language emails - replace Sitecore EXM

    DynaMail - send data-driven, multi-language emails - replace Sitecore EXM

    For a Sitecore Experience Commerce project we needed to send out emails on placed orders, but could not use EXM due to…

  • Boxever - my first baby steps

    Boxever - my first baby steps

    After doing the Boxever Advanced Certification I was lucky enough to get access to a Boxever sandbox. I will post my…

    1 条评论
  • XC 10 - Tip #7: When the docs fails - Google

    XC 10 - Tip #7: When the docs fails - Google

    Ok, a bit of an obvious one: if you need an answer, you Google. But if you hit a Sitecore documentation page in most…

  • XC 10 - Tip #6: When the docs fails -ILSpy

    XC 10 - Tip #6: When the docs fails -ILSpy

    The best documentation is the code. And the code you need, especially when replacing for example a pipeline block where…

  • XC 10 - Tip #5: When the docs fails -NDepend

    XC 10 - Tip #5: When the docs fails -NDepend

    With a large software product like Sitecore with a huge code-base, it is difficult to get a good overview of how…

社区洞察

其他会员也浏览了