I am writing an invoicing work-flow and using PayPal Invoicing API.
I have written a demo ASP.NET Web Application (.Net Framework) and have all the PayPal API calls working fine (I can call 'create', 'send', 'get' methods).
My next step is to write the same but as a Windows Console Application with the final step to move the code into a Windows Service Application so that my workflow will run in the background on my server to raise invoices, send them, and check for payment.
So, the first stage (Web app demo) works great, the issue is with my second stage of development: Using PayPal API in a Windows Console Application.
Just like the Web Application, I am using Visual Studio 2019 with PayPal installed through the NuGet Packages Manager:
PM> Install Package PayPal
The project's packages.config entry reads:
<package id="PayPal" version="1.9.1" targetFramework="net472" />
The same PayPal and .NET Framework versions as the working Web application.
In the App.config configuration file I have the added the necessary paypal section (copy & paste from the Web.config file of the working Web application):
<configuration>
...
<paypal>
<settings>
<add name="mode" value="sandbox" />
<add name="clientId" value="<MYCLIENTID>" />
<add name="clientSecret" value="MYCLIENTSECRET" />
</settings>
</paypal>
</configuration>
The Windows Console Application builds OK.
But, before I have even written any code to use the PayPal API, the application refuses to run. I get the following error reported about the paypal section in App.config:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at <MYAPPNAME>.<MYAPPNAME>.fgs_gamesEntities..ctor() in D:\source\repos\<MYAPPNAME>\<MYAPPNAME>\Models\fgs_games.Context.vb:line 20
at <MYAPPNAME>.Functions_General.RecordException(String apiKey, String FileName, String FunctionName, Int32 TryCatchInstance, Exception err) in D:\source\repos\<MYAPPNAME>\<MYAPPNAME>\App_Functions\Functions_General.vb:line 10
at <MYAPPNAME>.InvoicingCycle.Main() in D:\source\repos\<MYAPPNAME>\<MYAPPNAME>\InvoicingCycle.vb:line 133
This exception was originally thrown at this call stack:
System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(bool)
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)
System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
System.Configuration.ClientConfigurationSystem.EnsureInit(string)
Inner Exception 1:
ConfigurationErrorsException: Configuration system failed to initialize
Inner Exception 2:
ConfigurationErrorsException: Unrecognized configuration section paypal. (D:\source\repos\<MYAPPNAME>\<MYAPPNAME>\bin\Debug\<MYAPPNAME>.exe.Config line 33)
With line 33 pointing to the start of the paypal section in App.config.
I have re-installed the "PayPal" package but still the error persists.
Has anyone come across this error before? Did you fix it, and, if yes, how!
Has anybody got the PayPal SDK to operate in a Windows Console Application, or is the PayPal SDK only written for Web applications?
Kind regards,
Paul
User contributions licensed under CC BY-SA 3.0