4.20 Plugin Error

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
I am building a plugin from scratch for version 4.20, I can install it no problem however I get an
Error that breaks the entire website after installing the new plugin..

An error occurred while starting the application.
.NET Core 4.6.27617.05 X64 v4.0.0.0    |   Microsoft.AspNetCore.Hosting version 2.2.0-rtm-35687    |    Microsoft Windows 10.0.17134    |   Need help?

and the only clue I have is below. It started out as an error, I googled it, cleaned the solution, restarted and it changed to a warning!


1>Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '' and ('$(RunPostBuildEvent)' != 'OnOutputUpdated' or '$(_AssemblyTimestampBeforeCompile)' != '$(_AssemblyTimestampAfterCompile)')) was evaluated as ('' != '' and ('' != 'OnOutputUpdated' or '' != '')).
1>Target "GenerateBuildDependencyFile" skipped. Previously built successfully.
1>Target "GenerateBuildRuntimeConfigurationFiles" skipped, due to false condition; ( '$(GenerateRuntimeConfigurationFiles)' == 'true') was evaluated as ( '' == 'true').
1>Target CoreBuild:
1>Target AfterBuild:
1>Target Build:
1>Target NopTarget:
1>  Task "MSBuild"
1>    Global Properties:
1>      PluginPath=C:\Users\Jonathon.JON-HOPLEY-NET\Documents\UPGRADE\4201\Plugins\Nop.Plugin.Misc.MegaMenu\C:\Users\Jonathon.JON-HOPLEY-NET\Documents\UPGRADE\42001\Plugins\Misc.MegaMenu\
1>    Building with tools version "15.0".
1>    Target NopClear:
1>      Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>      Task "Exec"
1>        dotnet "ClearPluginAssemblies.dll" "OutputPath=C:\Users\Jonathon.JON-HOPLEY-NET\Documents\UPGRADE\4201\Build\..\Presentation\Nop.Web\bin\Debug\netcoreapp2.2\|PluginPath=C:\Users\Jonathon.JON-HOPLEY-NET\Documents\UPGRADE\4201\Plugins\Nop.Plugin.Misc.MegaMenu\C:\Users\Jonathon.JON-HOPLEY-NET\Documents\UPGRADE\42001\Plugins\Misc.MegaMenu\|SaveLocalesFolders="
1>      Done executing task "Exec".
1>
1>    Done building project "ClearPluginAssemblies.proj".
1>  Done executing task "MSBuild".
1>Target "_PackAsBuildAfterTarget" skipped, due to false condition; ('$(GeneratePackageOnBuild)' == 'true' AND '$(IsInnerBuild)' != 'true') was evaluated as ('false' == 'true' AND '' != 'true').
1>Target AfterRebuild:
1>Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
1>Target Rebuild:
1>
1>Done building project "Nop.Plugin.Misc.MegaMenu.csproj".
1>
1>Build succeeded.
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3277: Found conflicts between different versions of "System.Diagnostics.DiagnosticSource" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>    1 Warning(s)
1>    0 Error(s)
1>
1>Time Elapsed 00:00:03.12
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
4 years ago
Ok Now I'm trying this approach..
I have moved my controller and factories to the source and removed the plugin. So now I clean and build the solution with no errors except when I try to render my new view component. I have followed the pattern of the source code and can not see why

InvalidOperationException: A view component named 'MegaMenu' could not be found. A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated with 'ViewComponentAttribute' or have a class name ending with the 'ViewComponent' suffix. A view component must not be decorated with 'NonViewComponentAttribute'.
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeAsync(string name, object arguments)

as my view component is decorated with 'ViewComponent'; same as the TopMenu
using System;
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Web.Framework.Components;
using Nop.Web.Factories;    

namespace Nop.Web.Components
{
    /// <summary>
    /// Represents view component to embed tracking script on pages
    /// </summary>
  
    public class MegaMenuViewComponent : NopViewComponent  
    {
      
            private readonly IMegaMenuCatalogModelFactory _megaMenuCatalogModelFactory;

            public MegaMenuViewComponent(IMegaMenuCatalogModelFactory megaMenuCatalogModelFactory)
            {
                _megaMenuCatalogModelFactory = megaMenuCatalogModelFactory;
            }

            public IViewComponentResult Invoke(int? productThumbPictureSize)
            {
                var model = _megaMenuCatalogModelFactory.PrepareMegaMenuModel();
                return View(model);
            }
        }
    }
4 years ago
Ok progress is progress now the ViewComponent will load - I have now registered the new factories with the Dependency Registrar which fixes the above issue, however still having temperamental build errors and warnings about System.Diagnostics.DiagnosticSource
Jon.Hopley.Net wrote:

Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3277: Found conflicts between different versions of "System.Diagnostics.DiagnosticSource" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>    0 Warning(s)
1>    8 Error(s)
4 years ago
Nearly there now instead of category pictures I get

Computers Nop.Web.Media.PictureModels
Desktops Nop.Web.Media.PictureModels
..etc

anyone any ideas why the pictures don't appear?

The modified factory for preparing the catgory simple method has this added
//prepare picture model
                var pictureSize = _mediaSettings.CategoryThumbPictureSize;
                var categoryPictureCacheKey = string.Format(NopModelCacheDefaults.CategoryPictureModelKey, category.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id);
                categoryModel.Picture = _cacheManager.Get(categoryPictureCacheKey, () =>
                {
                    var picture = _pictureService.GetPictureById(category.PictureId);
                    var pictureModel = new PictureModel
                    {
                        FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
                        ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize),
                        Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), categoryModel.Name),
                        AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), categoryModel.Name)
                    };
                    return pictureModel;
                });
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.