Discord.Addons.Interactive.InteractiveBase.PagedReplyAsync Not Working - c#

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

Related

.NET6 Lambda throws System.BadImageFormatException

I have a .NET6 project published as a zip file to AWS Lambda.
When I test it in the AWS console I get the following error:
Unhandled exception. System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
In Lambda the architecture is set to x86_64 with the runtime set to .NET 6 (C#/PowerShell)
I am publishing the solution on a Windows machine with the following command:
dotnet publish -r linux-x64 --no-self-contained .\src\MyApp.Api -c Release -o .\dist\publish
Can anyone help here?
I believe this error is due to targetting an incorrect architecture but can't see what I'm doing wrong.
Edit:
MyApp.Api.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>MyApp.Api</AssemblyName>
<PackageId>MyApp.Api</PackageId>
<AWSProjectType>Lambda</AWSProjectType>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RootNamespace>MyApp.Api</RootNamespace>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.4.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyApp.Core\MyApp.Core.csproj" />
</ItemGroup>
</Project>
MyApp.runtimeconfig.json:
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}
MyApp.Api.deps.json:
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0/linux-x64",
"signature": ""
},
// removed for brevity

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.

OrderBy throws Could not load file or assembly System.Data.Entity

Trying to get DataTables to work in a ASP.NET Core 2 project. When the following line of code executes, the application throws exception on OrderBy
var data = (from app in _context.Applications select app);
//Sorting
if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
{
data = data.OrderBy(sortColumn + " " + sortColumnDir);
}
The exception is:
{System.TypeInitializationException: The type initializer for 'System.Linq.Dynamic.ExpressionParser' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
at System.Linq.Dynamic.ExpressionParser..cctor()
--- End of inner exception stack trace ---
at System.Linq.Dynamic.ExpressionParser..ctor(ParameterExpression[] parameters, String expression, Object[] values)
at System.Linq.Dynamic.DynamicQueryable.OrderBy(IQueryable source, String ordering, Object[] values)
at System.Linq.Dynamic.DynamicQueryable.OrderBy[T](IQueryable`1 source, String ordering, Object[] values)
at assetreportv2.Controllers.HomeController.LoadData() in C:\Users\chentiangemalc\Documents\Visual Studio 2017\Projects\DataTableTest\DataTableTest\Controllers\HomeController.cs:line 64}
The csproj file is currently configured like so:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="bootstrap" Version="4.0.0" />
<PackageReference Include="Entityframework" Version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
<PackageReference Include="System.Linq.Dynamic" Version="1.0.7" />
<PackageReference Include="WindowsAzure.Storage" Version="8.3.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
Is there a way to use this OrderBy in ASP.NET Core, or suggest an alternative option?
Sorry I'm a bit late to your question, but I had exactly this problem and I've just fixed it. I'm also using Core 2.0 and was using System.Linq.Dynamic and got that error when I used an OrderBy extension, but I uninstalled it and installed System.Linq.Dynamic.Core instead, and now it's working perfectly

Use of System.IO.Stream detected as an incompatible type when overriding FileConfigurationProvider

I'm attempting to create a custom FileConfigurationProvider implementation for some configuration elements in a .Net Core WebApi application.
It looks something like this..
public class MyProvider : FileConfigurationProvider
{
public MyProvider(FileConfigurationSource source) : base(source) { }
public override void Load(Stream stream)
{
try
{
// Stream reading things
}
catch
{
throw new Exception("Failed to load stream.");
}
}
}
Despite the simplicity of this example, the override of Load(Stream stream) gives me an indicator in VS2017 that there is no suitable method for override. Furthermore an additional error hint states that FileConfigurationProvider(System.IO.Stream) is not implemented.
Extracting to a delegate using ReSharper has revealed a new hint for the call to Load(Stream stream) stating that Argument type System.IO.Stream [System.IO, Version=4.1.0.0...] is not assignable to parameter of type System.IO.Stream [System.Private.CoreLib, Version=4.0.0.0...]
Despite these error hints I can still successfully build and run this code.
Can someone help me understand what is wrong here?
The csproj is as follows..
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
I've also tried being more explicit in the framework defs...
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
</PropertyGroup>
There is the bug in JetBrains bug tracker https://youtrack.jetbrains.com/issue/RSRP-464676

Roslyn project.Documents is empty when run on Build server

I have a unit Test that checks that all my service methods make a call to some authorization method.
I'm checking this in a unit Test using Roslyn.
The test runs fine on my local machine but fails on the build server, because project.Documents is empty.
I'm using VS 2017 and mstest V2.
The build server is a private on prem build agent in VSTS.
[TestMethod]
public async Task All_public_Service_Methods_should_check_authorization()
{
var workspace = MSBuildWorkspace.Create();
var project = await workspace.OpenProjectAsync(pathToCsprojFile).ConfigureAwait(false);
Console.WriteLine($"AssemblyName is {project.AssemblyName}"); // same output
Console.WriteLine($"FilePath is {project.FilePath}"); // same output
Console.WriteLine($"Documents are {string.Join(Environment.NewLine,project.Documents.Select(d => d.FilePath))}"); // empty on build server
//...
}
This is the csproj, that I'm trying to load
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.5</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DocumentationFile>bin\Debug\netstandard1.5\adremes.Exchange.Services.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DocumentationFile>bin\Release\netstandard1.5\adremes.Exchange.Services.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="adremes.Common" Version="1.4.0" />
<PackageReference Include="AutoMapper" Version="5.2.0" />
<PackageReference Include="AutoMapper.Collection" Version="2.1.2" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.7.1" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\adremes.Exchange.Common\adremes.Exchange.Common.csproj" />
<ProjectReference Include="..\adremes.Exchange.Data\adremes.Exchange.Data.csproj" />
</ItemGroup>
</Project>

Categories