How to fix ClientCredential namespace not found - c#

I get the following error message within visual code even though I've added every reference I can find that's relevant to the issue but I'm still not able to get past the error. First time using visual code. What am I missing?
Offending line
var creds = new ClientCredential(applicationId, clientSecret); // This line fails to compile
Error received
The type or namespace name 'ClientCredential' could not be found
References added
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.0.3" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
<PackageReference Include="System.ServiceModel.Http" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" />
<PackageReference Include="WindowsAzure.ServiceBus" Version="6.0.0" />
</ItemGroup>

Copy Vignesh's comment , it will be helpful to others.
Just add "using Microsoft.IdentityModel.Clients.ActiveDirectory;" before the code.

Related

Selenium test case running locally but not on azure pipeline using chrome driver

My selenium testcases running locally in visual studio but when I check in the code on Azure build pipeline, its failing to locate the first element itself. Getting No such element exception.
Below is the CSProject nuget packages and dependencies I have added:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<PublishChromeDriver>True</PublishChromeDriver>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetSeleniumExtras.PageObjects" Version="3.11.0" />
<PackageReference Include="DotNetSeleniumExtras.PageObjects.Core" Version="4.3.0" />
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="ExtentReports" Version="4.1.0" />
<PackageReference Include="ExtentReports.Core" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1001" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.15.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Selenium.Support" Version="4.3.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.3.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="108.0.5359.7100" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="107.0.1418.42" />
</ItemGroup>
ChromeDriver runs successfully with the below error snippet.
<UnitTestResult executionId="00ad0f0d-8aea-41d7-8981-13961152aed9" testId="76a081c3-ed49-d739-5a18-7669ad294fce" testName="CreateSustainingProjectAndApproveGateDecision("Engineering Services")" computerName="compName" duration="00:00:20.4944700" startTime="2022-12-27T01:28:02.1595758-06:00" endTime="2022-12-27T01:28:22.6539741-06:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Failed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="00ad0f0d-8aea-41d7-8981-13961152aed9">
<Output>
<ErrorInfo>
<Message>OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"xpath","selector":"//button[contains(#id,'create')]"}
(Session info: chrome=108.0.5359.125)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.</Message>
<StackTrace> at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
`at OpenQA.Selenium.WebDriver.FindElement(By by)
at PC.SeleniumUI.Tests.Start_Browser() in E:\AdosBuilds\ADOS-Agent1\1\s\UnitTests.cs:line 56
--TearDown
`
If anyone has ever faced this issue on Azure server, can guide me?
I have tried the options like
waiting for a 25 seconds delay, adding await delay instaed of Thread.sleep
Adding the below options
var options = new ChromeOptions();
options.AddArguments("--headless"); //for headless mode
options.AddArguments("--window-size=800,600");//The invisible browser window is only 800x600 in size
options.AddArguments("start-maximized"); // open Browser in maximized mode
options.AddArguments("disable-infobars"); // disabling infobars
options.AddArguments("--disable-extensions"); // disabling extensions
options.AddArguments("--disable-gpu"); // applicable to windows os only
options.AddArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.AddArguments("--no-sandbox");
options.AddArguments("--disable-blink-features='BlockCredentialedSubresources'");
options.AddArguments("--whitelisted-ips='10.5.243.86'");
Pass the authentication parameters
using CssSelector instead of Xpath

Activity.Current is null in Azure function with BlobTrigger

I have an Azure function(V3) that uses BlobTrigger binding and written in C#.
In order to add custom properties in Application Insights RequestTelemetry for it using
Activity.Current?.AddTag("TraceId", traceId);
I need to access the Activity.Current based on the suggestion from this Stackoverflow answer. However, it didn't work due to Activity.Current is NULL.
My package configuration looks like as follow:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.9.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.0-beta.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.14" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.8" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
And my function looks like as follow:
[FunctionName("Create-Thumbnail")]
public async Task CreateThumbnail([BlobTrigger("input/{name}", Source = BlobTriggerSource.EventGrid, Connection = "AzureWebJobsStorage")] Stream image,
IDictionary<string,string> metadata,
string name,
ILogger log,
ExecutionContext context)
{
Activity.Current?.AddTag("TraceId", traceId);
}
I have been doing research for whole day but failed to find any solution. Does anyone know what could be the issue?
Currently it can be working in HTTP Trigger Functions that were ending up in the Custom Properties of Requests in application insights are no longer. Refer here
The same Activity.Current value is null issue available in github Azure Function host & Application Insights
The Application Insights .NET SDK uses DiagnosticSource (DiagnosticSourceUsersGuide) and Activity (ActivityUserGuide) steps to collect and correlate telemetry.
Please open an issue in the Functions repo link here.
Thanks to this GitHub issue, I manage to get it work after downgrading System.Diagnostics.DiagnosticSource to to version 4.6
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />

Discord.Addons.Interactive.InteractiveBase.PagedReplyAsync Not Working

So I'm testing out the Discord.Addons.Interactive namespace to see what it offers. So I write a little InteractiveBase that looks something like this:
public class Interactive : InteractiveBase
{
[Command("book")]
private async Task BookAsync()
{
await PagedReplyAsync(new PaginatedMessage
{
Title = "Book",
Color = HelperFunctions.GenColor(),
Pages = "This is a book".Split(" ")
});
}
}
So I run the discord bot, everything is well, and then I test out the new book command. Then all of a sudden this happens:
Discord.Commands.CommandException: Error occurred executing "book" for USERNAME#XXXX in SERVER/CHANNEL.
---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Discord.Rest.RestUserMessage> Discord.WebSocket.ISocketMessageChannel.SendMessageAsync(System.String, Boolean, Discord.Embed, Discord.RequestOptions)'.
I don't see what I did wrong, but if you do please tell me.
EDIT:
Someone asked for the project file so here it is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Addons.Hosting" Version="3.1.1" />
<PackageReference Include="Discord.Addons.Interactive" Version="2.0.0" />
<PackageReference Include="Discord.Net" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images" />
</ItemGroup>
</Project>
https://github.com/foxbot/Discord.Addons.Interactive/issues/33
There seems to be an issue between Discord.Addons.Interactive and Discord.Net having the right versions. That's what usually causes System.MissingMethodException

Could not load file or assembly 'SeleniumExtras.WaitHelpers

I am trying to use
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("logonIdentifier")));
However I am getting an error Could not load file or assembly 'SeleniumExtras.WaitHelpers. I am using
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="TestProject.SDK" Version="0.63.1" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<PublishChromeDriver>true</PublishChromeDriver>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\testForLogin\testForLogin.csproj" />
</ItemGroup>
</Project>
It works locally but when I tried pushing it to the testproject.io I get the above error message.
I am not able to change it to the recommend selenium web driver version.
The package you are using is not .NET Core compliant. With some restructure of the code what you need is available with
using OpenQA.Selenium.Support.UI;
Then take the code that used the SeleniumExtras wait helpers and change to use methods on your driver class such as
WebDriverWait browserWait = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
browserWait.Until(driver => driver.FindElement(By.Id("logonIdentifier")).Displayed);
You could easily check the properties on the driver as well, say for the Url, such as
const string expectedUrl = "https://www.google.com";
browserWait.Until(driver => driver.Url == expectedUrl);
Then go remove the package you are no longer using from your project
dotnet remove package DotNetSeleniumExtras.WaitHelpers
Which funny enough is pretty much the homepage of https://www.selenium.dev/documentation/en/ but when you search you tend to get distracted by the SeleniumExtras project.

Missing assemblies when reflecting into unit test project

When reflecting into a unittests assembly (System.Reflection.Assembly.GetTypes()) from a console app I get a slew of file not found errors.
I tried adding a bunch of packages with minimal success, I'm unsure that is the way to go.
This is my project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="PossumLabs.Specflow.Core" Version="1.0.0-CI00024" />
<PackageReference Include="PossumLabs.Specflow.Selenium" Version="1.0.0-CI00030" />
<PackageReference Include="Selenium.Chrome.WebDriver" Version="74.0.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="SpecFlow" Version="3.0.225" />
<PackageReference Include="SpecFlow.MsTest" Version="3.0.225" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.0.225" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
</ItemGroup>
</Project>
Could not load file or assembly
'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot
find the file specified.
Same goes for
Microsoft.VisualStudio.TestPlatform.TestFramework
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
Microsoft.VisualStudio.TestPlatform.ObjectModel
Microsoft.VisualStudio.TestPlatform.TestFramework
I want to get these to copy to my output folder so that I can reflect into the unit test DLL.
No Answer, just workaround;
This happened when reflecting into a Microsoft DLL; it seems that in .net core reflection changed a little bit and just blindly reflecting over every dll in a folder is no longer safe. Filtering the Dll by their dependency was possible, and that if how I narrow the scope; But even though I load every DLL the GetTypes will throw an error as mentioned above.
How you filter is less important than that you filter down what DLL's you look into.
Both start the same
foreach (string dll in Directory.GetFiles(path, "*.dll"))
assemblies.Add(Assembly.LoadFile(dll));
Bad code:
foreach (var assembly in assemblies)
{}
Good Code:
foreach (var assembly in assemblies.Where(a=>a.GetReferencedAssemblies().Any(x=>x.Name.Contains("YourCompanyNamespace"))))
{}

Categories