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 instantiate ServiceContext in .NET Core #50

Closed
attrib75 opened this issue Oct 9, 2018 · 18 comments
Closed

Cannot instantiate ServiceContext in .NET Core #50

attrib75 opened this issue Oct 9, 2018 · 18 comments

Comments

@attrib75
Copy link

attrib75 commented Oct 9, 2018

OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(systemSettings.AccessToken);
ServiceContext serviceContext = new ServiceContext(systemSettings.RealmId, IntuitServicesType.QBO, oauthValidator);

thows:

Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

StackTrace:

at Intuit.Ipp.Core.Configuration.LocalConfigReader.ReadConfiguration()
at Intuit.Ipp.Core.ServiceContext..ctor()
at Intuit.Ipp.Core.ServiceContext..ctor(String realmId, IntuitServicesType serviceType, IRequestValidator requestValidator)
at PiMarketing.Controllers.CampaignsController.d__17.MoveNext() in C:\Dev2\Pi_Marketing\PiMarketing\PiMarketing\Controllers\CampaignsController.cs:line 576

Its looking for the old ConfigurationManager that doesn't exist in .NET core

@nimisha84
Copy link
Collaborator

This is a dll hell issue- old version of dll being referenced or multiple versions of same dll causing issues. Please delete all references of the prob dll. Then clean code and do a build again after adding the dll back.

@nimisha84 nimisha84 reopened this Oct 9, 2018
@attrib75
Copy link
Author

attrib75 commented Oct 9, 2018

But this was added via Nuget

@nimisha84
Copy link
Collaborator

Yes, even if our dotnet SDK dll was added via Nuget, it can conflict with some local ref in your code.
Try the steps I suggested above. Dll hell is a very common issue. If it is still not resolved then my team will look into it.

@nimisha84
Copy link
Collaborator

Create a new sample proj to add Nuget package for dotnet SDK, do you still get the error? If not, then dll hell issue is confirmed.

@nimisha84
Copy link
Collaborator

Was this fixed by steps suggested above?

@scottieslg
Copy link

I just got this same error, which led me here.

I installed System.Configuration.ConfigurationManager from NuGet (and I also had to install DevDefined.OAuth), but this fixed it.

It would sure be nice to have a .Net Core library.

@nimisha84
Copy link
Collaborator

Thanks for the feedback. We are working on adding support for .Net Standard in future.

@nimisha84
Copy link
Collaborator

We are working on releasing the beta version of our DLLS for .net standard which you can use with .Net Core 2.1 projects.
Please let me know if you are interested in testing those out and giving us your feedback if you see any issues.

Thanks,
Nimisha

@nimisha84 nimisha84 reopened this Apr 9, 2019
@nimisha84
Copy link
Collaborator

Please reply with your email ids, in case you are interested. I can send the zipped SDK dlls and steps to download any additional dependencies from Nuget. Later, in a few weeks when we release it, we will be releasing the NUget package with required dependencies.

@rbonestell
Copy link

I am also experiencing a similar issue with my .NET Core 2.2 app, but I am unable to discern a solution from this issue thread:

FormatException: Input string was not in a correct format.
System.Number.StringToNumber(ReadOnlySpan<char> str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, bool parseDecimal)
System.Number.ParseInt32(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info)
Intuit.Ipp.Core.Configuration.LocalConfigReader.ReadConfiguration()
Intuit.Ipp.Core.ServiceContext..ctor()
Intuit.Ipp.Core.ServiceContext..ctor(string realmId, IntuitServicesType serviceType, IRequestValidator requestValidator)

I am using the preview nuget package mentioned in another thread; https://www.nuget.org/packages/IppDotNetSdkForQuickBooksApiV3_NetStandard2_0/7.5.1-beta

Here is my code which is failing to initialize the ServiceContext object:

        public string GetCompanyInfoFromAPI(AuthTokens qboAuthTokens)
        {
            OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator(qboAuthTokens.AccessToken);

            ServiceContext serviceContext = new ServiceContext(qboAuthTokens.CompanyID, IntuitServicesType.QBO, oauthValidator);
            serviceContext.IppConfiguration.MinorVersion.Qbo = "23";

            QueryService<CompanyInfo> querySvc = new QueryService<CompanyInfo>(serviceContext);
            CompanyInfo companyInfo = querySvc.ExecuteIdsQuery("SELECT * FROM CompanyInfo").FirstOrDefault();

            string output = JsonConvert.SerializeObject(companyInfo, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });
            return output;
        }

The above code was adapted from the QBO SDK developer documentation: https://developer.intuit.com/app/developer/qbo/docs/develop/sdks-and-samples-collections/net#connect-to-quickbooks-online

@nimisha84
Copy link
Collaborator

nimisha84 commented Apr 21, 2019

Can you enable fiddler logs to run along with your local code?The beta package we had released had some caching issues with 4.7.2 dlls. We are generating another nuget release soon and will update you. Wait for that.
This issue you have mentioned here can be for multiple reasons. Just want to be sure by verifying your logs.

Steps to use fiddler-

Download Fiddler from Google and run it alongside your code to log raw requests and responses along with URL and headers. When you download Fiddler, open it, go to Tools > Fiddler Option > Enable (Tick Mark) Capture HTTPS connects > Enable Decrypt Https traffic. That’s it. No other setting is required. The .NET localhost is by default captured in Fiddler, so after you have enabled https traffic in Fiddler just run your code. (Fiddler should be open.) You will see requests and responses logged in Fiddler. You should set 'decode the raw request body' by clicking on the yellow bar in Fiddler. Then go to the File menu on top, select Save all session > Save the fiddler session. A .saz file is created, which can be viewed later.

@rbonestell
Copy link

Hi @nimisha84!

Using Fiddler showed no requests being sent as a result of instantiating a ServiceContext object before my code crashed. The error appears to be in the LocalConfigReader.ReadConfiguration() code where it's looks to be attempting to convert a string to an Int32, as per my stack trace above.

@nimisha84
Copy link
Collaborator

Ok, let me validate this again then. Thanks

@rbonestell
Copy link

I was able to figure out the cause of this problem! I had simply copied the example appsettings.json content that you had posted in another issue here, referencing .NET Core, and I didn't put in any values for the Retry section, causing the config reader to throw an exception. Updated with example values like so, and it works:

"Retry": {
    "Mode": {
      "LinearRetry": {
        "Enable": "false",
        "RetryCount": "3",
        "RetryInterval": "3"
      },
      "IncrementalRetry": {
        "Enable": "false",
        "RetryCount": "3",
        "InitialInterval": "3",
        "Increment": "1"
      },
      "ExponentialRetry": {
        "Enable": "true",
        "RetryCount": "3",
        "MinBackoff": "1",
        "MaxBackoff": "3",
        "DeltaBackoff": "1"
      }
    }
  }

@nimisha84
Copy link
Collaborator

Retry settings should not be mandatory. Did you set one of them to true and not pass any values or did you have enable= false for everything and still got the error?

@nimisha84
Copy link
Collaborator

It looks like you set it to true and not set any other values. Fixed the issue. Please test with this package going forward-
IppDotNetSdkForQuickBooksApiV3 -> 7.5.0.3-beta

@rbonestell
Copy link

That is correct, I had copied the example config you had posted here (#3 (comment)) without noticing that the exponential retry was enabled. Everything is working now, thanks for your update!

@nimisha84
Copy link
Collaborator

Thanks. Corrected the example too.

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

No branches or pull requests

4 participants