我有 ASP.NET Core Web 应用程序,我在其中使用 swagger 使用以下内容:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.OperationFilter<ExamplesOperationFilter>();
c.OperationFilter<DescriptionOperationFilter>();
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "API",
Description = "",
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "API"); });
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
当我导航到 url/swagger 时,出现以下错误:
失败:Microsoft.AspNetCore.Server.Kestrel[13] …
我有一个在WCF服务中运行的RabbitMQ C#Client.
它偶尔会发现System.NotSupportedException: Pipelining of requests forbidden 异常.
我正在尝试重新排序结帐页面上的结算字段,但到目前为止我尝试的所有内容都无效.
这是我目前正在尝试的片段:
add_filter("woocommerce_checkout_fields", "order_fields");
function order_fields($fields) {
$order = array(
"billing_first_name",
"billing_last_name",
"billing_country",
"billing_state",
"billing_address_1",
"billing_address_2",
"billing_email",
"billing_phone"
);
foreach($order as $field) {
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;
return $fields;
}
Run Code Online (Sandbox Code Playgroud)
有些东西可以覆盖这个片段,因为它曾经为我工作.
假设我有以下两个类.
public class Father
{
public int Id { get; set; }
public int Price { get; set; }
}
public class Child: Father
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何知道特定属性是父属性(继承)还是子属性?
我试过了
var childProperties = typeof(Child).GetProperties().Except(typeof(Father).GetProperties());
Run Code Online (Sandbox Code Playgroud)
但似乎Except没有检测到父属性和子继承属性的相等性.
我正在努力IMongoCollection.Find使用 Moq 进行单元测试的模拟方法。
我试过的:
Mock<IMongoCollection<Person>> mockIMongoCollection = new Mock<IMongoCollection<Person>>();
mockIMongoCollection.SetupAllProperties();
mockIMongoCollection
.Setup(x => x.Find(
It.IsAny<FilterDefinition<Person>>(),
It.IsAny<FindOptions>()))
.Returns();
Run Code Online (Sandbox Code Playgroud)
事情是我尝试使用返回的任何内容Returns(),它不起作用,我希望能够返回可转换为的内容,List<Person>并且我无法模拟或创建方法IFindFluent<Person,Person>返回类型所建议的实例Find。
我将要打包的项目类型从 .net Framework v4.6 更改为 .net standard 2.0,现在构建定义在 Nuget 打包器步骤中失败,并且收到此错误消息。
[错误]项目的默认 XML 命名空间必须是 MSBuild XML 命名空间。如果项目是以 MSBuild 2003 格式编写的,请将 xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 添加到元素中。如果项目是以旧的 1.0 或 1.2 格式编写的,请将其转换为 MSBuild 2003 格式。
研究此错误后,我了解到 NuGet 打包步骤不适用于基于 SDK 的 csproj 格式。
最好的替代方案是什么?我在这里发现了同样的问题,但我在可用命令中找不到命令包。
我是 Angular 的新手,我正在尝试定义一个组件并在我的主页中使用它。
问题是,当使用 index.html 中的组件时,我所能看到的只是<custom-component></custom-component>空的,里面什么也没有。
所以我所做的是:
在 Angular cli 中:ng 生成自定义组件。
在 custom.component.html 中,我只有段落标记内的文本。
在index.html中,我插入了在custom.component.ts(app-custom)中找到的选择器作为标签。
我错过了什么?
更新: 我的组件的代码:
自定义组件.html
<p>
component works!
</p>
Run Code Online (Sandbox Code Playgroud)
自定义组件.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-custom',
templateUrl: './custom.component.html',
styleUrls: ['./custom.component.css']
})
export class CustomComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
索引.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TestApp</title>
<base href="/">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" …Run Code Online (Sandbox Code Playgroud) 我使用以下代码将 C# 中的 Guid 转换为 Base64:
var id = Guid.Parse("be9f1bb6-5c8e-407d-85a3-d5ef31f21b4d");
var base64=Convert.ToBase64String(id.ToByteArray());
Run Code Online (Sandbox Code Playgroud)
输出
thufvo5cfUCFo9XvMfIbTQ==
当我尝试使用以下命令在 Java 中执行相同操作时:
java.util.Base64.Encoder encoder=Base64.getEncoder();
UUID uuid = UUID.fromString("be9f1bb6-5c8e-407d-85a3-d5ef31f21b4d");
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
encoder.encodeToString(bb.array());
Run Code Online (Sandbox Code Playgroud)
输出不同
vp8btlyOQH2Fo9XvMfIbTQ==
我的 Java 代码做错了什么?如何才能获得与使用 C# 相同的结果?
我有一个多对多的关系,我正在使用 ASP.Net Core2.2 MVC 和 EF。
从我阅读的内容中我了解到,目前我必须为连接表创建一个 CLR 类。
我的代码:
楷模:
public class Post
{
public Post()
{
Categories= new List<PostCategory>();
}
public int Id { get; set; }
[Required]
public string Title { get; set; }
[Required]
public string Description { get; set; }
public List<PostCategory> Categories { get; set; }
}
public class Category
{
public Category()
{
Posts= new List<PostCategory>();
}
public int Id { get; set; }
[Required]
public string Name { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Visual Studio 2019 将我的 .Net core 应用程序 docker 映像发布到 Azure 容器注册表。
它工作正常,但突然我开始看到以下错误:
发布遇到错误。运行 docker.exe 登录命令失败。
警告!通过 CLI 使用 --password 是不安全的。使用 --password-stdin。来自守护程序的错误响应:获取https://app.azurecr.io:443/v2/:未经授权:需要身份验证
诊断日志已写入以下位置:“C:\Users\user\AppData\Local\Temp\tmp768.tmp”
当运行以下CMD命令时:
docker login https://app.azurecr.io
Run Code Online (Sandbox Code Playgroud)
我正进入(状态:
正在使用现有凭据进行身份验证...
登录成功
我重新启动了 Visual Studio 和 Docker,并且以管理员身份运行 Visual Studio。
有人遇到过类似的问题吗?
c# ×6
.net-core ×3
angular ×1
asp.net-core ×1
base64 ×1
docker ×1
hook ×1
html ×1
inheritance ×1
java ×1
mongodb ×1
moq ×1
rabbitmq ×1
reflection ×1
swagger ×1
tfs ×1
unit-testing ×1
uuid ×1
woocommerce ×1
wordpress ×1