Getting TypeLoadException while using AppAuthentication library
See original GitHub issueGetting TypeLoadException while trying to use AppAuthentication for accessing SQL Database using Managed Identities.
Link with details on what I am trying to achieve - https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi
Exception or Stack Trace Exception: System.TypeInitializationException: ‘The type initializer for ‘System.Data.SqlClient.SqlAuthenticationProviderManager’ threw an exception.’
InnerException (1 of 2): ArgumentException: Failed to instantiate an authentication provider with type ‘Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider, Microsoft.Azure.Services.AppAuthentication’ for ‘ActiveDirectoryInteractive’.
InnerException (2 of 2): TypeLoadException: Could not load type ‘Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider’ from assembly ‘Microsoft.Azure.Services.AppAuthentication’.
To Reproduce Steps to reproduce the behavior:
- Add “Microsoft.Azure.Services.AppAuthentication” Nuget package to ASP.NET web app project.
- Add configuration based on this link
Code Snippet
<SqlAuthenticationProviders> <providers> <add name="Active Directory Interactive" type="Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider, Microsoft.Azure.Services.AppAuthentication" /> </providers> </SqlAuthenticationProviders>
Expected behavior Application should be able to load SqlAppAuthenticationProvider, as per the documentation from AppAuthentication dll.
Setup (please complete the following information):
- OS: Windows 10
- IDE : Visual Studio 2017
- Microsoft.Azure.Services.AppAuthentication - version 1.2.1
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Issue Analytics
- State:
- Created 4 years ago
- Comments:12
Top GitHub Comments
Changing the web app target framwork to 4.7.2 seems to solve it.
The file sdk/mgmtcommon/AppAuthentication/Azure.Services.AppAuthentication/SqlAppAuthenticationProvider.cs only has contents if the .NET version is 4.7.2.
I’m not sure why 4.7.2 is required, but it should probably fail more gracefully if the target framework is wrong.
@elafnitzegger - I closed the issue as it seemed like issue was not reproducible anymore. I will try to upload the sample solution that is working for me. Would you be able to share the sample project where you are facing the issue to compare and get to root of this issue?
I will reopen the issue now for further troubleshooting and let admins decide on when to close.