xxxxプログラマのメモ

先人に感謝と敬意:自分の困ったこと調べたことのメモ

K8S Clientから指定するコンテナ名は小文字!

K8S Clientから指定するコンテナ名は小文字!

spec: new V1PodSpec(containers:
	new List<V1Container>
	{
		new V1Container
		{
			Name =  CName.ToLower(), //小文字じゃないと動作しなかった[2019/12/06]
			Image =  ImageName,
			VolumeMounts = new List<V1VolumeMount>....

勘違いかもしれません。

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Nullable`1[xxxx]'

.Net Core 3.x で作成していると以下のエラーが発生。

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Nullable`1[xxxx]'

Nullableの内容を含むApiのレスポンスがHasValueプロパティを含む形でシリアライズされているため、解釈しようとして例外が発生している模様。

Dictionaryでの類似トラブルを参考に以下のように対応。
github.com

Api

Microsoft.AspNetCore.Mvc.NewtonsoftJson を参照に追加

Startup.cs

        public void ConfigureServices(IServiceCollection services)
{
            services.AddMvc(option => option.EnableEndpointRouting = false).AddNewtonsoftJson();
}


docs.microsoft.com


Thanks!

Reference only specific build target #特定のビルドターゲットでのみの参照設定

NetFrameworkとNetCoreのマルチターゲット時に、NetFrameworkビルド時にのみ参照させてる設定

  <ItemGroup Condition="'$(TargetFramework)' == 'net45'">
    <Reference Include="System.ComponentModel.DataAnnotations" />
  </ItemGroup>

stackoverflow.com

Thansk!

EF でSQLを確認

#if DEBUG
            // 以下、LoggerFactory の構築方法が v.2.x 以前と異なる。
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddFilter(
                    category: DbLoggerCategory.Database.Command.Name,
                    level: LogLevel.Debug);
            });

            var option = new DbContextOptionsBuilder<db1Context>()
                .UseLoggerFactory(loggerFactory)
                .Options;

            using (var db = new db1Context(option))
#else
            using (var db = new db1Context())
#endif

mseeeen.msen.jp

Thanks!