Could not load file or assembly 'System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
RknaikIris opened this issue · 1 comments
####Which PnP repository should you use to report the issue?####
Please navigate to the appropriate repository by clicking on the link below and create your issue there. You can delete this section after you have navigated to the correct repository.
- PnP AspNetCore Authentication- https://github.com/SharePoint/PnP/tree/master/Solutions/AspNetCore.Authentication/src/OfficeDevPnP.Core.Framework.Authentication
Category
[x] Bug
[ ] Enhancement
Environment
[ ] Office 365 / SharePoint Online
[ ] SharePoint 2016
[x] SharePoint 2013
If SharePoint on-premises, what's exact CU version:
Expected or Desired Behavior
Should be able to create SharePoint context
Observed Behavior
Exception is thrown from OfficeDevPnP.Core.Framework.Authentication.SharePointContext class, method
public static SharePointContextProvider GetInstance(SharePointConfiguration configuration)
Line: - _tokenHandler = new TokenHandler(configuration);
Exception is thrown
Could not load file or assembly 'System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
Steps to Reproduce
- Create a nuget package of OfficeDevPnP.Core.Framework.Authentication, include all the DLLs from the project
- Create asp.net core 2.2 project
- Add Nuget from step #1.
Run the project by pressing F5.
I have updated code of OfficeDevPnP.Core.Framework.Authentication project to support HighTrust apps.
I getting exception while trying to read certificate information .
My understanding is issue occurs due to bit mismatch i.e. 32 bit vs 64 bit.
Using "DumpBin.exe -headers" I inspected the headers of System.IdentityModel.dll its 32 bit
Below is the few starting line
PE signature found
File Type: DLL
FILE HEADER VALUES
14C machine (x86)
3 number of sections
563C1C4C time date stamp Thu Nov 5 22:19:40 2015
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
I build projects i.e. OfficeDevPnP.Core.Framework.Authentication, SharePointPnP.IdentityModel.Extensions and Core Web Project with "Any CPU" as platform target.
I Followed suggestion provided in thread https://github.com/dotnet/cli/issues/7532 and installed both 32 bit and 64 bit version of dotnet core
and added file "Directory.Build.targets" at the root of web project with contents as below
$(MSBuildProgramFiles32)\dotnet\dotnet
$(ProgramW6432)\dotnet\dotnet
I hosted app on IIS Express.
Still having the issues
Hi RknaikIris,
I have had the same issue for an Azure function that tried to connect to SPO and that used App Permissions. I played a bit around with the referenced package versions and got it working.
My references currently look like this:
"SharePointPnPCoreOnline": "3.3.1811",
"Microsoft.IdentityModel.Clients.ActiveDirectory" : "3.19.8",
"System.Security.Cryptography.X509Certificates" : "4.3.2",
"AngleSharp" : "0.9.9"
Hope it helps.
Br,
Anisia Pop