Could not load file or assembly 'Azure.Core, Version=1.0.2.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified

Navjot 46 Reputation points
2023-03-14T00:01:05.7033333+00:00

Describe the bug
We are implementing some changes in our Web load test and performance testing project (in Visual Studio) to enable webtests to fetch passwords from an encrypted SQL DB by using master key stored in Azure key vault. For this we have installed below 3 NuGet packages:

  • Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider
  • Microsoft.IdentityModel.Clients.ActiveDirectory
  • Newtonsoft.Json

During this implementation, we are getting below error: 

Error Message:

System.IO.FileNotFoundException HResult=0x80070002   Message=Could not load file or assembly 'Azure.Core, Version=1.0.2.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.  

Source=Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider

  StackTrace:    at Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.AzureSqlKeyCryptographer..ctor(TokenCredential tokenCredential)    at Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.SqlColumnEncryptionAzureKeyVaultProvider..ctor(TokenCredential tokenCredential, String[] trustedEndpoints) at WebAndLoadTestProject1.GetAllCredentialsToExcel.PreWebTest(Object sender, PreWebTestEventArgs e)

 

Line of code where it throws above error:

Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.SqlColumnEncryptionAzureKeyVaultProvider akv1 = new Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.SqlColumnEncryptionAzureKeyVaultProvider(new LegacyAuthCallbackTokenCredential());

Fusion log:

Pre-bind state information ===\r\n

LOG: DisplayName = Azure.Core, Version=1.0.2.0, Culture=neutral, PublicKeyToken=92742159e12e44c8\n (Fully-specified)\r\nLOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : Azure.Security.KeyVault.Keys, Version=4.0.3.0, Culture=neutral, PublicKeyToken=92742159e12e44c8.\r\n===\r\nLOG: This bind starts in LoadFrom load context.\r\nWRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().\r\nLOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\QTAgent_40.exe.Config\r\nLOG: Using host configuration file: \r\nLOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.\r\nLOG: Post-policy reference: Azure.Core, Version=1.0.2.0, Culture=neutral, PublicKeyToken=92742159e12e44c8\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/Azure.Core/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/Azure.Core/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/PrivateAssemblies/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/PrivateAssemblies/Azure.Core/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/PublicAssemblies/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/PublicAssemblies/Azure.Core/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/DataCollectors/Azure.Core.DLL.\r\nLOG:

Attempting download of new URL file:///Q:/WebAndLoadTestProject1/TestResults/Out/Azure.Core.DLL.\r\nWRN: Comparing the assembly name resulted in the mismatch: Minor Version\r\nLOG:

Environment:
Visual Studio version is 16.11.9
Runtime Environment:
OS Name: Windows
OS Version: 2019 Server

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
334 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Anna Xiu-MSFT 27,221 Reputation points Microsoft Vendor
    2023-03-14T09:56:57.8333333+00:00

    Hi @Navjot

    Welcome to Microsoft Q&A! 

    For ‘Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider’ NuGet package, which version did you install?

    Please check if the installed ‘Azure.Core’ package version is 1.0.2

    Besides, you can update your VS2019 to the latest version with Visual Studio Installer.

    Then, add the following elements to the first configuration property group:

    <PropertyGroup>
        ...
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
        <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
      </PropertyGroup>
    
    

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    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.


  2. Navjot 46 Reputation points
    2023-03-16T21:15:45.8533333+00:00

    Hi AnnaXiu-MSFT,

    In Same PT solution we implemented this code using a Unittest instead of a Webtest and it worked fine without any issues. So whenever this piece of code is called via webtest we see this error. So, can it be a limitation of webtest functionality in Visual Studio 2019?. Will be really helpful if you can please provide more insights on this.


  3. Navjot 46 Reputation points
    2023-03-16T21:17:46.7133333+00:00

    Hi AnnaXiu-MSFT,

    In Same PT solution we implemented this code using a Unittest instead of a Webtest and it worked fine without any issues. So whenever this piece of code is called via webtest we see this error. So, can it be a limitation of webtest functionality in Visual Studio 2019. Will be really helpful if you can please provide more insights on this.

    0 comments No comments