Fix “Could Not Load File or Assembly” in nopCommerce Plugins

Plugin development 9 min read Updated

Fix “Could Not Load File or Assembly” in nopCommerce Plugins

What the error means when a nopCommerce 5.0 plugin loads, how to find the plugin and DLL behind it, and the three causes we reproduced on a local 5.00.1 store, with the fix for each.

A terminal where nopCommerce 5.00.1 fails at startup with Could not load file or assembly Google.Authenticator, Version=3.0.0.0, thrown from InitializePlugins, under the title Fix Could not load file or assembly

Key takeaways

  • The message names the missing assembly and its version. Look for that file in the plugin's folder first.
  • A plugin that uses a NuGet package needs CopyLocalLockFileAssemblies set to true, or the package DLL is never copied.
  • A plugin whose plugin.json does not list 5.00 is skipped, and System > Warnings says so.
  • Two plugins that ship different versions of one library get a collision warning naming both.

"Could not load file or assembly" means .NET went looking for a DLL and could not use the one it found, or found none. In nopCommerce this nearly always happens while plugins load, and in 5.0 an installed plugin with a missing dependency can stop the whole store from starting.

We reproduced each cause on a local nopCommerce 5.00.1 store built from the release-5.00.1 tag, then put everything back. The errors, warnings and folder listings below are what that store printed. If you are moving a plugin from 4.x, our guide to porting a plugin to nopCommerce 5.0 covers the code changes; this post is about the loading errors.

What the Error Means in a nopCommerce Plugin

The startup crash of a 5.00.1 store, a ReflectionTypeLoadException and FileNotFoundException for Google.Authenticator 3.0.0.0 thrown from InitializePlugins, beside three notes: startup stops, the missing file, InitializePlugins
The real startup crash of a 5.00.1 store whose plugin lost a dependency.

When nopCommerce starts, it reads every plugin folder under Plugins, loads the main DLL of each installed plugin and asks it for its types. If one of those types depends on an assembly that is not there, .NET throws, and nopCommerce rethrows with every inner message joined together.

The store never starts.

This is what our test store printed after the Google Authenticator plugin lost its dependency:

Unhandled exception. System.Exception: Unable to load one or more of the requested types.
Could not load file or assembly 'Google.Authenticator, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
 ---> System.Reflection.ReflectionTypeLoadException
   at ...ApplicationPartManagerExtensions.InitializePlugins(...) line 288

Read three things from it. The assembly name, here Google.Authenticator. The version it wanted, 3.0.0.0, which is the assembly version and can differ from the NuGet package version (the plugin references package 3.2.0). And the method, InitializePlugins, which tells you it failed while plugins were loading, not later in a page.

The ending matters too. "The system cannot find the file specified" means the file is missing. "The located assembly's manifest definition does not match the assembly reference" means a file was found but it is a different version from the one the plugin was built against.

Find Which Plugin and Assembly Failed

The Local plugins page of a 5.00.1 admin with a yellow banner naming two plugins that cannot be loaded, and in front of it the System warnings page with the same two warnings
When the store starts, Local plugins and System warnings name each plugin it skipped.

If the store does not start, the console or the hosting log has the full message: the stdout log under IIS, the container log under Docker, or the terminal when you run dotnet run. Search it for "Could not load file or assembly" and note the name and version.

If the store starts, nopCommerce 5.0 skips a plugin it cannot load and tells you where:

  • A yellow banner at the top of Configuration > Local plugins lists each plugin that cannot be loaded.
  • System > Warnings shows the same lines, with the reason: not compatible with the current version, main assembly not found, or an assembly collision.

Then open the plugin's folder, Plugins/<Group.Name>, next to the store's DLLs. Compare it with what the plugin needs: its main DLL (named in plugin.json under FileName) and every third-party DLL it uses.

From the BSS team

A common surprise on the upgrades we run is a plugin that compiled last week and no longer loads. We open System > Warnings before we read any code, because it names the plugin and the reason. Our nopCommerce upgrade service starts with that check.

A plugin that will not load after an upgrade? BSS ports and rebuilds nopCommerce plugins for 5.0.

See nopCommerce services

Cause 1: The Plugin's NuGet Dependency Was Not Copied

Two terminals building the Google Authenticator plugin with 0 errors: with CopyLocalLockFileAssemblies false its folder has no Google.Authenticator.dll or QRCoder.dll, with the default true both are copied
Both builds report 0 errors; only the folder shows the missing DLLs.

This is the most common cause, and the build will not warn you. A plugin builds straight into Nop.Web/Plugins/<name>, and by default .NET does not copy NuGet package DLLs into a class library's output. The bundled plugins' project files explain the switch in a comment:

<!--Set this parameter to true to get the dlls copied from the NuGet cache
to the output of your project. You need to set this parameter to true if your
plugin has a nuget package ...-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

The Google Authenticator plugin references the GoogleAuthenticator 3.2.0 package and sets this to true. When we rebuilt it with -p:CopyLocalLockFileAssemblies=false, the build still reported 0 warnings and 0 errors, but Google.Authenticator.dll and QRCoder.dll were gone from its folder. The next start of the store failed with the error above.

The fix:

  1. Set CopyLocalLockFileAssemblies to true in every plugin project that has a PackageReference.
  2. Rebuild the plugin and list its output folder. Every package DLL should be there.
  3. When you deploy, copy the whole plugin folder, not only the plugin's own DLL.

Do not copy nopCommerce's own DLLs into a plugin folder. The bundled plugins run a ClearPluginAssemblies step after build that removes files the store already has, which keeps the folder to the plugin and its real dependencies.

BSS plugin for 5.00, 4.90 and 4.80
BSS Nop REST API Plugin

Pre-built storefront endpoints for mobile and headless apps, packaged for each nopCommerce version it supports.

Cause 2: The Plugin Was Built for Another Version

A plugin.json with SupportedVersions 4.90 highlighted and NopVersion.cs giving CURRENT_VERSION 5.00, above the System warnings line saying the plugin isn't compatible with the current version
SupportedVersions set to 4.90 on a 5.00 store, and the warning it produces.

Every plugin carries a plugin.json. nopCommerce compares its SupportedVersions list with its own version, which is "5.00" in NopVersion.cs for every 5.0 release. If 5.00 is not in the list, the plugin is not loaded.

We set the Google Authenticator plugin's list to 4.90 and restarted. The store started, and System > Warnings read: "MultiFactorAuth.GoogleAuthenticator: The plugin isn't compatible with the current version. Hence this plugin can't be loaded."

Do not fix this by typing 5.00 into the JSON of a 4.x plugin. The version check is there because the plugin was compiled against 4.x assemblies and an older .NET.

A 5.0 plugin targets net10.0, as every bundled plugin does, and is built against the 5.0 source. Rebuild it, test it, then update SupportedVersions. Our checklist for testing plugin compatibility before an upgrade lists what to check.

The same page reported our second test: "Widgets.GoogleAnalytics: The main assembly isn't found." We had renamed that plugin's main DLL. A FileName in plugin.json that does not match the DLL in the folder, often after a rename or a half-finished deploy, gives this warning.

Cause 3: Two Plugins Load Different Versions of One Library

The two collision warning texts from the 5.00.1 resources and the line in ApplicationPartManagerExtensions.cs that marks a plugin HasCollisions, above three notes: two versions, first load wins, align versions
The collision warnings in the 5.00.1 resources, and where the check lives.

A .NET process loads one copy of an assembly by name. When two plugins ship different versions of the same library, the first one loaded is the one every plugin gets.

nopCommerce 5.0 notices this while loading plugins and reports it on System > Warnings in this form: "The 'library' assembly has collision, application loaded the 'version' assembly, but the 'plugin' plugin required the 'version' assembly", with one "plugin required" part for each plugin involved.

A plugin that is not yet installed and would collide is marked HasCollisions and left out. One that is installed keeps running with the loaded version, which works until it calls something that version lacks. That is when "Could not load file or assembly" or a MissingMethodException appears, usually on one page rather than at startup.

The fix is to agree on one version. Update both plugins to the same package version and rebuild them together, or remove the plugin you do not need. If one plugin is not yours, ask its vendor for a build on the same version.

From the BSS team

Before we ship a plugin update, we install it next to the other plugins the store runs and read System > Warnings after the restart. A collision shows up there before a customer ever finds it. Our nopCommerce services include that check.

Do it yourself

  • Read the name and version in the error
  • Check the plugin folder and plugin.json
  • Rebuild with CopyLocalLockFileAssemblies true
  • Align shared package versions

Or BSS does it

Our engineers port plugins to 5.0, fix their packaging and test them together with the rest of your store's plugins.

Talk to an engineer

Frequently Asked Questions

What does "Could not load file or assembly" mean in nopCommerce?
.NET could not find or could not use a DLL that a plugin needs. The message names the assembly and version. In nopCommerce it usually appears while plugins load at startup.
Why does my plugin build fine but fail when the store starts?
A plugin with a NuGet package needs CopyLocalLockFileAssemblies set to true. Without it the build succeeds but the package DLL is never copied to the plugin folder.
Can I make a 4.90 plugin load in nopCommerce 5.0 by editing plugin.json?
Not safely. The plugin was compiled against 4.x assemblies and an older .NET. Rebuild it against the 5.0 source for net10.0, test it, then list 5.00 in SupportedVersions.
Where does nopCommerce show plugins that failed to load?
On System > Warnings and in a banner on Configuration > Local plugins. If the store cannot start at all, the message is in the console or hosting log.
What is an assembly collision in nopCommerce?
Two plugins ship different versions of the same library. Only one version can load, and nopCommerce lists the library, the loaded version and what each plugin asked for on System > Warnings.

Final Thoughts

"Could not load file or assembly" looks alarming because it can stop the whole store, but in nopCommerce it has a short list of causes. Read the assembly name and version, open the plugin's folder, and check System > Warnings when the store starts.

Most of the time the fix is in the plugin's packaging: copy its NuGet DLLs, build it for 5.0, and keep shared libraries on one version across plugins. Check the folder after every build, because the compiler will not.

MH

Written by Moumita Hossain

Software Engineer · Bangladesh Software Solution

Software Engineer at BSS in Dhaka, building backend systems in JavaScript and TypeScript.

Read nextPlugin development How to Port a nopCommerce Plugin from 4.90 to 5.0 9 min read