microsoft / microsoft/sqlmanagementobjects
Could not load file or assembly Microsoft.Identity.Client, Version=4.22.0.0
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 143
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
I have a .NET 4.8 framework Windows application that is using Microsoft.SqlServer.SqlManagementObjects (v161.47027.0) in its own class. I am unit testing that class in a separate .NET 4.8 library test project.
However when I run a test like so:
[Test]
public void SqlAgentJobDoesntExist_ThrowsException()
{
var connection = new SqlConnectionStringBuilder(ConnectionString); //ConnectionString coming from app.config in the test project
var sqlAgent = new SqlAgentService(connection);
Assert.Throws<NullReferenceException>(() => { var result = sqlAgent.ExecuteJob("NotFound"); });
}
It is throwing an error around this bit of code in my service class:
public CompletionResult ExecuteJob(string jobName)
{
try
{
var connection = new ServerConnection(_connectionBuilder.DataSource, _connectionBuilder.UserID, _connectionBuilder.Password);
var server = new Server(connection);
var job = server.JobServer.Jobs[jobName]; //<-- throwing error here
...
Error:
Microsoft.SqlServer.Management.Common.ConnectionFailureException : Failed to connect to server XXXXXXXXXXX.
----> System.TypeInitializationException : The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception.
----> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.Identity.Client, Version=4.22.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Two reasons this is odd:
- The application itself is working fine (the main project), this error is only happening in my unit test project
- It's odd because SMO already installs Microsoft.Identity.Client as a dependency when adding as a NuGet package. Why is it asking for this older 4.22 version?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failing test around SqlAgentService.ExecuteJob and inspect the separate .NET 4.8 test project's app.config and package references. Compare the Microsoft.Identity.Client versions resolved by the test project and Microsoft.SqlServer.SqlManagementObjects, then verify that the test no longer raises the assembly-loading error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- databases, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100