<violates the constraint of type parameter 'TSettings'> error in paymentSettings (Payment Plugin)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 anos atrás
Hi,

I encounter a problem when creating a new Payment Plugin.
I tried to "decouple" my dependencies and decided to create an interface for all my concrete classes. I then use autofac in Nop in order to resolve the correct service/implementation to use.

A problem occurs in the paymentsettings model.
I created following Interface for my paymentsettings model:

using Nop.Core.Configuration;

namespace Nop.Plugin.Payments.Mollie.BankContact
{
    public interface IMollieBankContactPaymentSettings : ISettings
    {
        decimal AdditionalHandlingFeeFixed { get; set; }
        decimal AdditionalHandlingFeePercentage { get; set; }
        string ApiProduction { get; set; }
        string ApiTest { get; set; }
......


My concrete class is as followed:


namespace Nop.Plugin.Payments.Mollie.BankContact
{
    public class MollieBankContactPaymentSettings : IMollieBankContactPaymentSettings
    {
        public bool UseSandbox { get; set; }
        public string ApiTest { get; set; }
        public string ApiProduction { get; set; }
        //
        // RedirectURL : URL which is used access the mollie API        
        //

    
Because my interface IMollieBankContactPaymentSettings extends ISettings, I expected all to go fine, but I get following error:


Method Nop.Web.Framework.SettingsSource.BuildRegistration: type argument 'Nop.Plugin.Payments.Mollie.BankContact.IMollieBankContactPaymentSettings' violates the constraint of type parameter 'TSettings'.
Exception Details: System.Security.VerificationException: Method Nop.Web.Framework.SettingsSource.BuildRegistration: type argument 'Nop.Plugin.Payments.Mollie.BankContact.IMollieBankContactPaymentSettings' violates the constraint of type parameter 'TSettings'.
Source Error:
Line 385:            if (ts != null && typeof(ISettings).IsAssignableFrom(ts.ServiceType))
Line 386:            {
Line 387:                var buildMethod = BuildMethod.MakeGenericMethod(ts.ServiceType);
Line 388:                yield return (IComponentRegistration)buildMethod.Invoke(null, null);
Line 389:            }
Source File: C:\Data\Ecommerce\nop390\Presentation\Nop.Web.Framework\DependencyRegistrar.cs    Line: 387


Any thought on this ?
Thanks in advance.
7 anos atrás
The reason for that exception could be this line of code

static IComponentRegistration BuildRegistration<TSettings>() where TSettings : ISettings, new()

If i understand your code right you are using IMobileBankContactPaymentSettings for resolving your settings.
So it fits the constraint ISettings, but not the new() constraint.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.