Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load PayPal section from web.config #101

Closed
peternxyz opened this issue May 22, 2015 · 23 comments
Closed

Cannot load PayPal section from web.config #101

peternxyz opened this issue May 22, 2015 · 23 comments
Labels

Comments

@peternxyz
Copy link

Hello,

I am trying to set up PayPal in a new MVC5 web application.

Your documentation doesn't state that you need to add in the <accounts /> element from the <paypal /> section (only <settings />) so I had to dig through the code to add it in.

Sample code should look like this:

    <configSections>
        <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
    </configSections>
    <paypal>
        <settings>
            <add name="mode" value="sandbox" />
            <add name="clientId" value="" />
            <add name="clientSecret" value="" />
        </settings>
        <accounts>
            <account apiUsername="" apiPassword="" apiSignature="" />
        </accounts>
    </paypal>

When <accounts /> isn't there it throws this error:

Unable to load 'paypal' section from *.config: Required attribute 'accounts' not found.

I'm now getting this really strange error when attempting to call ConfigManager.Instance.GetProperties(); The error message is:

Unable to load 'paypal' section from *.config: An error occurred creating the configuration section handler for paypal: [C:\Users\Peter\AppData\Local\Temp\Temporary ASP.NET Files\vs\324c5a82\84589666\assembly\dl3\c1001f82\1f0b2ff7_8494d001\PayPal.dll] Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations. 

Stack trace:

[ConfigException: Unable to load 'paypal' section from *.config: An error occurred creating the configuration section handler for paypal: [C:\Users\Peter\AppData\Local\Temp\Temporary ASP.NET Files\vs\324c5a82\84589666\assembly\dl3\c1001f82\1f0b2ff7_8494d001\PayPal.dll] Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations. (C:\Users\Peter\Source\Workspaces\ROA101.01 - American Sniper\VR.WebApp\web.config line 10)]
   PayPal.Api.ConfigManager..ctor() +149
   PayPal.Api.ConfigManager.get_Instance() +92
   VR.WebApp.Providers.PayPalProvider.Create(Decimal dollarAmount, String returnUrl) i

Do you have any idea on what is going on?

@peternxyz
Copy link
Author

Seems like to only have broken in version 1.4.3. Rolling back to version 1.4.2 works ok for me.

@jziaja
Copy link
Contributor

jziaja commented May 22, 2015

Thanks for reporting this, @pageroller. It looks like this might be related to some changes that were made with respect to declaring certain classes as internal instead of public. I'll do some more testing and get this fixed ASAP.

Also, the <accounts> config section is only used by the older Classic SDKs and is not used by this SDK. Are you using this SDK along with one of the Classic SDKs?

@jziaja jziaja added the sdk-bug label May 22, 2015
@peternxyz
Copy link
Author

The error disappeared when I downgraded it, so I think it may have been just something else triggering it internally. Thanks for taking a look though!

@jziaja
Copy link
Contributor

jziaja commented May 22, 2015

I wonder if this could have to do with the fact that our build process performs the strong-name signing on the PayPal.dll file as a post-build process. The InternalsVisibleTo assembly attribute was added so the unit test project could still test the internal classes.

It may be time to add the SNK as part of the project here on GitHub as it's beginning to cause more problems (along with complicating the build process). This is also what Microsoft recommends here for open source projects:

If you are an open-source developer and you want the identity benefits of a strong-named assembly, consider checking in the private key associated with an assembly into your source control system.

@jziaja
Copy link
Contributor

jziaja commented May 22, 2015

@pageroller would you mind sharing how you have your project setup along with what your web.config file looks like? I tried reproducing this with both the Samples project here and a newly-created project, but I'm not seeing the exception thrown in either one. I also tried running the projects both with and without an <accounts> section in the config, and it was able to be loaded just fine in each case when calling ConfigManager.Instance.GetProperties().

@VickyMahir
Copy link

I have same issue while calling ConfigManager.Instance.GetProperties().
I have use PayPal.NET SDK version 1.4.3 .

So please tell me how to solve this issue?

@jziaja
Copy link
Contributor

jziaja commented May 25, 2015

@VickyMahir, the current solution if you're experiencing this issue is to downgrade to version 1.4.2. Currently, I'm unable to reproduce the issue on my end so any details you can help provide would be great.

The following information should help in tracking down the cause of this bug:

@VickyMahir
Copy link

@jziaja , I have resolved issue in version 1.4.3 using below code so is it ok?

var apiContext = new APIContext(token);
apiContext.Config = config; //PayPal.Api.ConfigManager.Instance.GetProperties();

// Define any custom configuration settings for calls that will use this object.
apiContext.Config["connectionTimeout"] = "10000"; // Quick timeout for testing purposes

//// Define any HTTP headers to be used in HTTP requests made with this APIContext object
if (apiContext.HTTPHeaders == null)
{
    apiContext.HTTPHeaders = new Dictionary<string, string>();
    apiContext.HTTPHeaders.Add("apiUsername", auth.Username);
    apiContext.HTTPHeaders.Add("apiPassword", auth.Password);
    apiContext.HTTPHeaders.Add("apiSignature", apiSignature);
}

@jziaja
Copy link
Contributor

jziaja commented May 25, 2015

@VickyMahir, what is config set to in your code?

@VickyMahir
Copy link

@jziaja , Nothing in config file.

Every thing in my code file

@jziaja
Copy link
Contributor

jziaja commented May 25, 2015

I meant on this line in the code you posted above:

apiContext.Config = config; //PayPal.Api.ConfigManager.Instance.GetProperties();

What is the value of config here? Is it null or set to something else?

Also, are you using this SDK in combination with one of the Classic SDKs?

@VickyMahir
Copy link

@jziaja , Value of config is

            var config = new Dictionary<string, string>();
            config.Add("mode", "sandbox");
            config.Add("clientId", clientID);
            config.Add("clientSecret", clientSecret);

I am using only PayPal NET SDK not any other SDK in my application.

@jziaja
Copy link
Contributor

jziaja commented May 25, 2015

Thanks @VickyMahir. If you can reproduce this issue in a newly-created project, would you mind emailing me the zipped-up project files at jziaja@paypal.com?

@peternxyz
Copy link
Author

Sorry for the delay - I've emailed you a copy of the solution with the issue replicated.

@kenney777
Copy link

@pageroller do you have .net framework 4.6 RC installed? if you check the registry @ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full and if the "release" key has a value of 393273 then you probably installed VS 2015. After removing the 4.6 RC from my system and reinstalling 4.5.1 it fixed the issue for me with the 1.4.3 nuget package.

@jziaja
Copy link
Contributor

jziaja commented May 29, 2015

Thanks a ton to @kenney777 for discovering the issue with .NET 4.6 RC. 👍

Another developer on StackOverflow also encountered this issue and was able to resolve it by uninstalling .NET 4.6 RC.

The root cause for the issue looks to be that .NET 4.6 RC is a bit stricter when executing a strong-name signed assembly with respect to how the assembly, class, and property attributes are defined in the assembly. Regarding this SDK, the .NET framework's behavior has changed in .NET 4.6 RC regarding the following attributes:

  • Specifying the assembly attribute InternalsVisibleTo() in a strong-name signed assembly that is missing a PublicKey declaration will throw an error. Currently, we have a post-build step prior to publishing that strong-name signs the PayPal.dll assembly with a private SNK. By default, the project isn't setup to use an SNK, which means the InternalsVisibleTo() declaration is intentionally missing a PublicKey reference to the PayPal.Tests project. The reason we didn't discover this issue internally prior to release is we currently run our tests on a system whose highest, installed .NET framework is 4.5.1.
  • The IsRequired parameter of a ConfigurationProperty property attribute is honored in .NET 4.6 RC, whereas it looks to have been ignored in previous versions of .NET. The place where this is causing a problem is for the <accounts> config property. This property was intentionally left in for compatibility reasons with the Classic SDKs and is not used by this SDK. For this reason, I'm going to change its value to false to make it optional for this SDK.

We're currently discussing internally what a better strategy might be on the strong-name signing. I know there's a lot of opinions flying around the open-source .NET world regarding whether or not an open source project should publish its private key. Microsoft suggests it for open source projects, and while I don't view the strong-name key we use as a means of security, I do view it as a means of establishing a level of trust with developers using it. For that reason, I'm going to investigate using a separate, publicly-available key that will be published here on GitHub, while our internal build process will still use our own, private key. I'll be working on this setup over on the issue-101 branch if you'd like to see the changes (it's currently missing the public key as I play around with the project settings and).

Until this change is finalized (which I'll use this thread to provide updates on), please feel free to voice your opinion of how the strong-name signing should be handled for an open source project.

Thanks! 👍

@Jaans
Copy link

Jaans commented May 30, 2015

Regarding strong-name signing - I agree with your approach. This may be open source, but I for one would definitely want to know whether the binary I'm using is signed by PayPal or someone else who may have "fiddled" with it (given it's accessible to everyone). Users who build the SDK themselves, can provide their own key for strong naming.
Obviously this is IMO.

jziaja added a commit that referenced this issue Jun 1, 2015
- Addresses #101
- SDK and Tests projects are now both setup to be signed with a strong-name key in the projects here on GitHub.
- NOTE: The released version of the SDK will continue to be signed with a private strong-name key.
@jziaja
Copy link
Contributor

jziaja commented Jun 1, 2015

Would yall mind trying out this beta release for version 1.4.4 and see if it resolves the .NET 4.6 RC compatibility issue?

For NuGet, you can run the following command in the Package Manager console to get the 1.4.4 beta:

PM> Install-Package PayPal -Pre

I tested this build on Windows 8.1 with .NET 4.6 RC. Using version 1.4.3, I was able to reproduce the error. Using 1.4.4 beta, the error went away, and I was able to successfully load the config (without the need for an <accounts> section as well).

Thanks!

@hmemcpy
Copy link

hmemcpy commented Jun 2, 2015

Had the same issue with 1.4.3 (rolling back to 1.4.2 helped!)
Confirming 1.4.4 works - the issue is resolved! (Using VS2015 RC)
Thank you @jziaja!

@jziaja
Copy link
Contributor

jziaja commented Jun 2, 2015

Thanks for confirming, @hmemcpy! I'll get this officially released by the end of today (want to run another round of tests on it first).

jziaja added a commit that referenced this issue Jun 2, 2015
- Addresses #101
- SDK and Tests projects are now both setup to be signed with a strong-name key in the projects here on GitHub.
- NOTE: The released version of the SDK will continue to be signed with a private strong-name key.
@jziaja
Copy link
Contributor

jziaja commented Jun 2, 2015

1.4.4 is now released!

Thanks again to everyone here for all your help! 👍

@jziaja jziaja closed this as completed Jun 2, 2015
@sandipgend
Copy link

sandipgend commented Dec 23, 2016

i used paypal 1.4.4 dll but it give me following error

Unable to cast object of type 'PayPal.SDKConfigHandler' to type 'System.Xml.XmlNode

@ppmtscory
Copy link

@sandipgend this issue is very old and may or may not be the same root cause for your issue. With that said, please open a new issue with any/all specific details that you can provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants