我正在尝试检查object变量是否是(int, int),如果可以,我将使用强制类型转换的变量,因此我尝试了以下代码:
//this one gives the error
public void MyMethodWithIs(object val)
{
if(val is (int id, int name) pair)
{
ConsoleWriteLine($"{pair.id}, {pair.name}");
}
}
//This one works
public void MyMethodWithAs(object val)
{
var pair = val as (int id, int name)?;
if(pair!=null)
{
ConsoleWriteLine($"{pair.id}, {pair.name}");
}
}
Run Code Online (Sandbox Code Playgroud)
该MyMethodWithIs方法在编辑器中给出以下错误:
找不到适用于类型的合适的解构实例或扩展方法
我的问题
为什么一个工作正常,而另一个却出现错误呢?我认为它MyMethodWithIs更具可读性,适合用于我的案子,但由于出现错误,我无法使用它。
checkboxSelection: true在 Angular & Javascript 中,我在其中一列中使用了 Ag-Grid 。
每当单击任何行的复选框时,我都需要调用一个函数...该怎么做?再次,如何在 Ag-Grid 中选中复选框时调用函数?
我正在尝试使用 XML-RCP 与 python 服务器通信,但是当我尝试编译以下代码时,出现异常“System.MissingMethodException: '找不到方法:'System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly( System.Reflection.AssemblyName、System.Reflection.Emit.AssemblyBuilderAccess)'.'" 显示,我没有找到有关此问题的文档
using CookComputing.XmlRpc;
using System;
[XmlRpcUrl("http://192.168.5.211:8000")]
public interface FlRPC : IXmlRpcProxy
{
[XmlRpcMethod("add")]
int add(int x, int y);
}
class Program
{
static void Main(string[] args)
{
FlRPC proxy = XmlRpcProxyGen.Create<FlRPC>();
Console.WriteLine(proxy.add(2, 3));
}
}
Run Code Online (Sandbox Code Playgroud)
我只是想跳过这个问题继续我的项目!
我创建了一个带有选择器“app-circle”的组件。组件的 HTML 包含一个圆的 SVG。
我想要的是 - 在我的主 HTML 中使用多个“app-circle”来绘制具有不同属性(例如颜色)的多个圆圈。但我似乎无法做到这一点。基本上,我的目的是将“app-circle”重新用作多个对象。
(请原谅我的幼稚;我是 angular 和 web 开发的新手,我的经验主要是在 C# 中,这可能是我在环绕 angular/web 概念和工作方式时发现困难的原因)
这是代码: -
主文件
<div class="diagram-wrapper">
<app-circle></app-circle>
<app-circle></app-circle>
</div>
Run Code Online (Sandbox Code Playgroud)
circle.component.html
<svg class="range" height="100" width="100">
<circle class="circle" cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>
Run Code Online (Sandbox Code Playgroud)
circle.component.ts
import { Component, OnInit, AfterViewInit } from '@angular/core';
@Component({
selector: 'app-circle',
templateUrl: './circle.component.html',
styleUrls: ['./circle.component.scss']
})
export class CircleComponent implements OnInit, AfterViewInit {
constructor() { }
ngOnInit() { }
ngAfterViewInit() {
// Circle logic (fill colors, etc.)
}
Run Code Online (Sandbox Code Playgroud) 我有一个在 Kestrel(Ubuntu) 下运行的 ASP.NET Core Web API,我遇到了一个奇怪的情况:当我运行前 20 个 API 调用的系列时,前 3-5 个调用很慢,然后响应时间是好的。然后我做了一个短暂的延迟(可能是一分钟甚至更短)并再次运行一系列 API 调用,并且前几次调用再次很慢,只有在前 3-5 次调用之后响应时间才正常。
最初,我认为问题出在 Kestrel 配置中,因此我进行了以下设置:
var host = new WebHostBuilder()
.UseKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 200;
options.Limits.MaxConcurrentUpgradedConnections = 200;
options.Limits.MaxRequestBodySize = 10000;
options.Limits.MinRequestBodyDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10)));
options.Limits.MinResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10)));
options.Limits.KeepAliveTimeout = TimeSpan.FromDays(2);
})
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
Run Code Online (Sandbox Code Playgroud)
它帮助我使我的服务更快地工作,但问题仍然存在。
该服务的基本逻辑如下:1) 获取请求对象 2) 将其解析为 POCO 类的实例 3) 使用多个 SELECT 调用 DB 以获取所有需要的数据(为此我使用 Dapper以及允许一次性运行多个SQL查询的方法)4)使用新接收的数据更新对象的实例并将对象插入数据库
就是这样。
而且我无法弄清楚是什么导致了这种延迟(空闲时间)。
我猜测也许我应该有一些虚拟调用来保持服务运行。所以我添加了一个包含 Timer …
I have a standard pipeline agent that works for CI whenever a pull request merged into master. It was working fine until I merged a pull request created by a visual-studio-2019 developed branch. Now I am getting
error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.
It is working fine when I push any changes with vs2017.
What should I do to avoid this error?
P.S: I want to keep using …
continuous-integration azure-devops azure-pipelines visual-studio-2019
我在我的 .netcore 程序中使用了 grpc,我想构建一个 docker 镜像来使用它。
这就是我在 dockerfile 中构建程序的方式
RUN dotnet publish -r linux-musl-x64 --no-restore -c Release -o /out
Run Code Online (Sandbox Code Playgroud)
我复制到其他图像,就像我的图像一样
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY --from=build /out ./
ENTRYPOINT ["./MyService"]
Run Code Online (Sandbox Code Playgroud)
问题是关于运行时映像。如果我使用“microsoft/dotnet:2.2-runtime-deps-alpine”没有问题,但如果使用“mcr.microsoft.com/dotnet/core/runtime-deps:2.2-alpine3.9”
我收到一条错误消息。
Unhandled Exception: System.IO.IOException: Error loading native library "/app/libgrpc_csharp_ext.x64.so". Symbol not found: PAL_dlerror
at Grpc.Core.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives)
at Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary()
at Grpc.Core.Internal.NativeExtension.LoadNativeMethods()
at Grpc.Core.Internal.NativeExtension..ctor()
at Grpc.Core.Internal.NativeExtension.Get()
at Grpc.Core.GrpcEnvironment.GrpcNativeInit()
at Grpc.Core.GrpcEnvironment..ctor()
at Grpc.Core.GrpcEnvironment.AddRef()
at Grpc.Core.Server..ctor(IEnumerable`1 options)
at MyService.Program.Main(String[] args) in /code/MyService/Program.cs:line 32
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?这两张图有什么区别?我只能找到第二one`s Dockerfile上泊坞窗枢纽
我想知道在 C# 中将变量插入字符串的不同方法。
我目前正在尝试将值插入到我正在构建的 json 字符串中:
Random rnd = new Random();
int ID = rnd.Next(1, 999);
string body = @"{""currency"":""country"",""gold"":1,""detail"":""detailid-979095986"",""tId"":""help here""}";
Run Code Online (Sandbox Code Playgroud)
如何将“ID”添加到字符串主体中?
在 asp.net core 2.1 应用程序中使用旋转将视图转换为 pdf 时会出现错误
值不能为空。参数名称:path1
下面是我的代码
var rpt = new ViewAsPdf();
//rptLandscape.Model = Model;
rpt.PageOrientation = Rotativa.AspNetCore.Options.Orientation.Landscape;
rpt.PageSize = Rotativa.AspNetCore.Options.Size.A4;
rpt.ViewName = "Test";
byte[] arr = await rpt.BuildFile(actionContextAccessor.ActionContext);
System.IO.File.WriteAllBytes(Path.Combine(env.WebRootPath, "PDFStorage", "File.pdf"), arr);
Run Code Online (Sandbox Code Playgroud)
虽然它成功地将网页返回为 pdf,但我想将它存储在一个文件夹中。此错误的可能原因是什么?,我已经检查了所有,它甚至不包含名称 name1 的属性
更新 1:错误不在 Path.Combine() 中,错误在它之前。
byte[] arr = await rpt.BuildFile(actionContextAccessor.ActionContext);
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Moq 和 xunit 编写单元测试。在此测试中,我必须模拟两个 httpClient 调用。
我正在为 dotnetcore API 编写单元测试。在我的 API 中,我必须对另一个 API 进行 2 次 HTTP 调用才能获取我想要的信息。- 在第一次调用中,我从该 API 获得了一个 jwt 令牌。- 在第二次调用中,我使用在第一次调用中获取的令牌进行了 GetAsync 调用以获取我需要的信息。
我不知道如何模拟这两个不同的调用。在此代码中,我只能模拟一个 httpClient 调用
var handlerMock = new Mock<HttpMessageHandler>(MockBehavior.Strict);
handlerMock
.Protected()
// Setup the PROTECTED method to mock
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
// prepare the expected response of the mocked http call
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = HttpStatusCode.BadRequest,
Content = new StringContent(JsonConvert.SerializeObject(getEnvelopeInformationsResponse), Encoding.UTF8, "application/json")
})
.Verifiable();
Run Code Online (Sandbox Code Playgroud)
你知道我该怎么做才能获得两个不同的调用并获得两个不同的 HttpResponseMessage 吗?
c# ×6
.net-core ×2
angular ×2
asp.net-core ×2
javascript ×2
ag-grid ×1
asp.net-mvc ×1
azure-devops ×1
docker ×1
grpc ×1
httpclient ×1
kestrel ×1
moq ×1
rotativa ×1
sql-server ×1
string ×1
valuetuple ×1