I'm creating a new plugin in NopCommerce 2.1. However I keep getting this error when I add the DependencyRegistrar class
Server Error in '/' Application.
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Source Error:
Line 132:
Line 133: //init plugin type (only one plugin per assembly is allowed)
Line 134: foreach (var t in description.ReferencedAssembly.GetTypes())
Line 135: if (typeof(IPlugin).IsAssignableFrom(t))
Line 136: if (!t.IsInterface)
Source File: C:\Users\Tri\Documents\Koneka\Koneka\NopCommerce\Main\Libraries\Nop.Core\Plugins\PluginManager.cs Line: 134
Stack Trace:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.RuntimeModule.GetTypes() +4
System.Reflection.Assembly.GetTypes() +78
Nop.Core.Plugins.PluginManager.Initialize() in C:\Users\Tri\Documents\Koneka\Koneka\NopCommerce\Main\Libraries\Nop.Core\Plugins\PluginManager.cs:134
[Exception: Could not initialise plugin folder]
Nop.Core.Plugins.PluginManager.Initialize() in C:\Users\Tri\Documents\Koneka\Koneka\NopCommerce\Main\Libraries\Nop.Core\Plugins\PluginManager.cs:149
[Exception: Could not initialise plugin folder]
Nop.Core.Plugins.PluginManager.Initialize() in C:\Users\Tri\Documents\Koneka\Koneka\NopCommerce\Main\Libraries\Nop.Core\Plugins\PluginManager.cs:157
[InvalidOperationException: The pre-application start initialization method Initialize on type Nop.Core.Plugins.PluginManager threw an exception with the following error message: Could not initialise plugin folder.]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +423
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +306
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677
[HttpException (0x80004005): The pre-application start initialization method Initialize on type Nop.Core.Plugins.PluginManager threw an exception with the following error message: Could not initialise plugin folder.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
Here is the code of the class
using Autofac;
using Autofac.Core;
using Autofac.Integration.Mvc;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Koneka.Banners.Data;
using Nop.Plugin.Koneka.Banners.Models;
namespace Nop.Plugin.Koneka.Banners
{
public class DependencyRegistrar:IDependencyRegistrar
{
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
{
//data layer
var dataSettingsManager = new DataSettingsManager();
var dataProviderSettings = dataSettingsManager.LoadSettings();
if (dataProviderSettings != null && dataProviderSettings.IsValid())
{
//register named context
builder.Register<IDbContext>(c => new BannerRecordContext(dataProviderSettings.DataConnectionString))
.Named<IDbContext>("nop_object_context_koneka_banners")
.InstancePerHttpRequest();
builder.Register<BannerRecordContext>(c => new BannerRecordContext(dataProviderSettings.DataConnectionString))
.InstancePerHttpRequest();
}
else
{
//register named context
builder.Register<IDbContext>(c => new BannerRecordContext(c.Resolve<DataSettings>().DataConnectionString))
.Named<IDbContext>("nop_object_context_koneka_banners")
.InstancePerHttpRequest();
builder.Register<BannerRecordContext>(c => new BannerRecordContext(c.Resolve<DataSettings>().DataConnectionString))
.InstancePerHttpRequest();
}
/// override required repository with our custom context
builder.RegisterType<EfRepository<Banner>>()
.As<IRepository<Banner>>()
.WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_koneka_banners"))
.InstancePerHttpRequest();
}
public int Order
{
get { return 1; }
}
}
}
Please help.
Thanks in advance :)