Could not load file or assembly 'Azure.Core,

navjot3019

New member
Joined
Mar 16, 2023
Messages
4
Programming Experience
1-3
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
 
Sounds to me like they (Microsoft) did not setup the dependencies for their Nuget packages properly if it needs Azure.Core, but Nuget did not automatically install it. Try adding the Nuget package for Azure.Core.
 
Sounds to me like they (Microsoft) did not setup the dependencies for their Nuget packages properly if it needs Azure.Core, but Nuget did not automatically install it. Try adding the Nuget package for Azure.Core.

Thanks Skydiver for your response. But we see Azure.core installed in our solution and is also being referenced properly. Seems like webtest is unable to pick it during compilation
 
Does the webtest also have it installed as part of the webtest project?
 
Yes it is installed. Also, in same PT solution we are not seeing this issue when invoking this code via unit test. But when invoking it through webtest this issue pops up. Not sure if its a limitation of webtest functionality.
 
I'm looking at the NuGet dependencies page for Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider:


It says that it requires at least v4.0.3 of Azure.Security.KeyVault.Keys and at least v1.6 of Azure.Core. The information you posted indicates that you are using v4.0.3 of the former and it is looking for v1.0.2 of the latter. That seems to be the disconnect. I wonder whether a redirect in web.config would be enough to fix that:
XML:
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
        <bindingRedirect oldVersion="1.0.2.0-1.6.0.0" newVersion="1.6.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
The NuGet page for v4.0.3 of Azure.Security.KeyVault.Keys says that it needs at least v1.0.2 but does work with later versions.

Note that the latest version of Azure.Security.KeyVault.Keys that should work with Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider is v4.5 and that requires at least v1.30 of Azure.Core, which should also work with Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider, so you might want to redirect all packages to the latest supported versions.
XML:
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Azure.Security.KeyVault.Keys" publicKeyToken="92742159e12e44c8" culture="neutral" />
        <bindingRedirect oldVersion="4.0.3.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
      <dependentAssembly>
        <assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
        <bindingRedirect oldVersion="1.0.2.0-1.30.0.0" newVersion="1.30.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
 
I'm looking at the NuGet dependencies page for Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider:


It says that it requires at least v4.0.3 of Azure.Security.KeyVault.Keys and at least v1.6 of Azure.Core. The information you posted indicates that you are using v4.0.3 of the former and it is looking for v1.0.2 of the latter. That seems to be the disconnect. I wonder whether a redirect in web.config would be enough to fix that:
XML:
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
        <bindingRedirect oldVersion="1.0.2.0-1.6.0.0" newVersion="1.6.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
The NuGet page for v4.0.3 of Azure.Security.KeyVault.Keys says that it needs at least v1.0.2 but does work with later versions.

Note that the latest version of Azure.Security.KeyVault.Keys that should work with Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider is v4.5 and that requires at least v1.30 of Azure.Core, which should also work with Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider, so you might want to redirect all packages to the latest supported versions.
XML:
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Azure.Security.KeyVault.Keys" publicKeyToken="92742159e12e44c8" culture="neutral" />
        <bindingRedirect oldVersion="4.0.3.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
      <dependentAssembly>
        <assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
        <bindingRedirect oldVersion="1.0.2.0-1.30.0.0" newVersion="1.30.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

First of all thanks a lot for taking out time and responding to my queries :).

We tried your suggested options as below:

1. Added below redirection in app.config but still same error came.
<bindingRedirect oldVersion="1.0.2.0-1.6.0.0" newVersion="1.6.0.0" />

2. Upgraded Azure.Security.KeyVault.Keys to v4.5 and Azure.Core to v1.30 and added below re-directions in app.config.

1679085200121.png


With this modification, i see this error : Message=Could not load file or assembly 'Azure.Security.KeyVault.Keys, Version=4.0.3.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies.
 

Latest posts

Back
Top Bottom