I tried to install the plugin "paypal commerce" (the official integration)
but upon clicking "install" and restarting the shop, it throws an error
System.NullReferenceException: Object reference not set to an instance of an object.
at Nop.Plugin.Payments.PayPalCommerce.Services.EventConsumer.GetAdminMenuItemAsync(IPlugin plugin) in C:\Repositories\nopCommerce_work\src\Plugins\Nop.Plugin.Payments.PayPalCommerce\Services\EventConsumer.cs:line 98
at Nop.Web.Framework.Events.BaseAdminMenuCreatedEventConsumer.HandleEventAsync(AdminMenuCreatedEvent eventMessage)
at Nop.Services.Events.EventPublisher.PublishAsync[TEvent](TEvent event)
I found the problem in the following:
in the class "EventPublisher.cs" there is a method "PublishAsync" that resolves all occurences of the event consumer for the event "GetAdminMenuItemAsync"
var consumers = EngineContext.Current.ResolveAll<IConsumer<TEvent>>().ToList();
foreach (var consumer in consumers)
{
try
{
//try to handle published event
await consumer.HandleEventAsync(@event);
...
and upon handling it in the class "BaseAdminMenuCreatedEventConsumer", method "HandleEventAsync"
does the following:
var plugin = await _pluginManager.LoadPluginBySystemNameAsync(PluginSystemName);
var newItem = await GetAdminMenuItemAsync(plugin);
what happened? The plugin is not installed yet so "var plugin" is null.
the class "EventConsumer", method "GetAdminMenuItemAsync" of the paypal commerce plugin is called nevertheless
and throws the "object reference not set" error at the methods first line "var descriptor = plugin.PluginDescriptor;"
I honestly don't understand why event consumers of not-installed plugins are loaded.
in my plugins.json there still is
"PluginNamesToInstall": [
{
"Item1": "Payments.PayPalCommerce",
"Item2": "a29ff26f-de6a-45a5-b0de-b8894dd104d5"
}
]
also: what is the item2? i did not find this guid anywhere else.
it's also not the project guid in the visual studio solution file.
this guid of item2 appears in the plugins.json in the development environment but also in the live environment (nopcommerce noSource 4.80.2)