Error Using IConsumer<ModelPrepared<BaseNopModel>> Event with Admin's ProductDetailsModel in nop 4.00

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 Jahre weitere
Hi,

I am migrating a plugin that I made from version 3.90 to 4.00, where I used a Filter to change the value of some properties of Model, and now with the introduction of events in version 4.00, I am trying to use them instead of Filter.
But I have not been successful so far. Here is my class that implements IConsumer:

    public class NewProductsConsumer: IConsumer<ModelPrepared<BaseNopModel>>
    {
        public void HandleEvent (ModelPrepared <BaseNopModel> eventMessage)
        {
            if (eventMessage.Model is Nop.Web.Areas.Admin.Models.Catalog.ProductDetailsModel)
            {
                Console.WriteLine ("Passed in event");
            }
        }
    }

When I run the nop through debug, after leaving my class, the code continues to run without problems until it drops in a validation in the ApplicationBuilderExtensions class, in the method UseNopExceptionHandler, more precisely in lines 62 and 63, where it has the code:

var exception = context.Features.Get <IExceptionHandlerFeature> ().
   if (exception == null)

The exception variable is not null, and returns the following exception:
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: 'One or more compilation failures occurred:
wf1ycseb.phc (219,102): error CS0246: The type or namespace name 'ProductModel' could not be found (are you missing a directive or an assembly reference?)
wf1ycseb.phc (402,71): error CS0246: The type or namespace name 'ProductModel' could not be found (are you missing a directive or an assembly reference?) '

StackTrace: at Nop.Web.Framework.Infrastructure.Extensions.ApplicationBuilderExtensions. <> C. <UseNopExceptionHandler> b__1_1 (HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware. <Invoke> d__6.MoveNext ()

I could not find the reason for the problem so I did some testing to see if there was anything to help me. First test I did was to change the ProductDetailsModel model from Admin to the ProductDetailsModel of the namespace Nop.Web.Models.Catalog, and when I do this the code works without errors, and I can change the values I want from the Model.

Another test I did was switch to Model Nop.Web.Areas.Admin.Models.Customers.CustomerModel, which is also part of Admin, and also worked perfectly.

Just when I refer in my Consumer the Nop.Web.Areas.Admin.Models.Catalog.ProductDetailsModel does the problem occur, did anyone go through something like that or do you have any idea what I might be doing wrong?

One thing I noticed in the error message appears that ProductModel was not found, not ProductDetailsModel, ProductModel being the name of the file that the ProductDetailsModel class is in.

Sorry for my english.

Thanks
5 Jahre weitere
I found the problem, it was my mistake.

I do not know how or what time it occurred, but the ProductModel class was with the incorrect ProductDetailsModel name, which is the correct model name for the public product page.

When I got to analyze the change history in GitHub I found the wrong name, I reversed this code and the problem was solved.

Sorry for the mistake.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.