When I try to execute C# unit tests I get the following error:
System.InvalidOperationException: Cannot resolve scoped service ‘Microsoft.Extensions.Options.IOptionsSnapshot`1[HiveMQtt.Client.Options.HiveMQClientOptions]’ from root provider.
I do not get this error when I execute the actual application on my laptop. Also other engineers are able to run the test on their computers without receiving the error. If I execute the tests from the .NET command line, I get the same error.
I seriously doubt this is a Hive MQTT related error but I thought I would ask if anyone else has seen this error and was able to resolve the error.
I have tried numerous “fixes” including:
- Using a clean clone of the git repo that has the source code
- Uninstall and re-install VS and .NET runtimes
Regards,
Doug
Hi @dougscg ,
I hope my message finds you well
The error message indicates that there is an issue resolving the scoped service Microsoft.Extensions.Options.IOptionsSnapshot<HiveMQtt.Client.Options.HiveMQClientOptions>
from the root provider. This error typically occurs when there is a problem with the dependency injection configuration or the registration of the required service.
Based on the error message, there doesn’t appear to be anything inherently wrong with the HiveMQtt.Client.Options.HiveMQClientOptions
service itself. Instead, the issue lies in resolving it from the root provider, which suggests a problem with the dependency injection setup or configuration.
There are a few things to check:
- Project dependencies
- Check the project properties
- Check which SDKs are present
To check project dependencies in your VS go to Solution Explorer, HiveMQtt, Tests, HiveMQtt.Test, Dependencies. Check the framework and its version.
To check the project properties, in your VS, to to the menu Project, HiveMQtt.Test Properties
Then proceed to Build, General and check the “Target Framework”
To check for the present SDKs, go to the Preferences and then proceed to Build and Debug, .NET Core
I hope this helps
Best regards
Dasha from HiveMQ Team
Morning Dasha.
Thank you for your very thorough response! After reviewing your response, I realize that I probably left some information out.
In our project we are using the HiveMQtt NuGet package, 0.2.0. Also, my development environment is Visual Studio Community 2022, 17.6.4, on Windows.
I’ll review my project settings against the information you provided.
Again, thank you for a very thorough response.
Regards,
Doug