question

johnjohn-0472 avatar image
0 Votes"
johnjohn-0472 asked johnjohn-0472 commented

Unable to use “OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext” inside ASP.NET core (.NET 5)

I have the following CSOM code inside my ASP.NET CORE (.NET 5.0):-


 var siteUrl = config.GetSection("SP").GetSection("SiteURL").Value;           
 string clientId = "****";
 string clientSecret = "***";
    
      using (ClientContext context = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))
    
         {

but i am getting this error:-

 System.TypeInitializationException
   HResult=0x80131534
   Message=The type initializer for 'OfficeDevPnP.Core.Utilities.TokenHelper' threw an exception.
   Source=OfficeDevPnP.Core
   StackTrace:
    at OfficeDevPnP.Core.Utilities.TokenHelper.set_Realm(String value)
    at OfficeDevPnP.Core.AuthenticationManager.EnsureToken(String siteUrl, String realm, String appId, String appSecret, String acsHostUrl, String globalEndPointPrefix)
    at OfficeDevPnP.Core.AuthenticationManager.GetAppOnlyAuthenticatedContext(String siteUrl, String realm, String appId, String appSecret, String acsHostUrl, String globalEndPointPrefix)
    at OfficeDevPnP.Core.AuthenticationManager.GetAppOnlyAuthenticatedContext(String siteUrl, String appId, String appSecret)
    at ServiceDeskSharePointIntegration.Program.Main(String[] args) in C:\Users\****\source\repos\ServiceDeskSharePointIntegration\ServiceDeskSharePointIntegration\Program.cs:line 47
    
 Inner Exception 1:
 TypeLoadException: Could not load type 'System.Web.Configuration.WebConfigurationManager' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.


when i hover over the related package i got this error:-


82955-left.png


office-sharepoint-online
left.png (17.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AmosWu-MSFT avatar image
1 Vote"
AmosWu-MSFT answered johnjohn-0472 commented

SharePointPnPCoreOnline is no longer maintained, please use PnP Framework (https://github.com/pnp/pnpframework) going forward.
And test code for your reference:

 ClientContext ctx = new AuthenticationManager().GetACSAppOnlyContext("https://contoso.sharepoint.com/sites/dev", "app id", "app secret", AzureEnvironment.Production);


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AmosWu-MSFT thisworked 100% for me thanks

1 Vote 1 ·