C# 開発

【C#】.NET Core 対応・エラー対応

2025.02.01 (.NET9) EntitiyFrameWork Core
Microsoft.Data.SqlClient.SqlException: ''$' 付近に不適切な構文があります。'

このように書いていた。

where vdt集計年月.Contains((x.集計年月 ?? ""))

そうすると、エラーが発生。以下のように書き直した。

where (x.集計年月.CompareTo(vdt集計年月[0]) >= 0 && x.集計年月.CompareTo(vdt集計年月[11]) <= 0)

2025.01.20 (.NET9) プロパティ
プロパティ 'PValue' は、プロパティ コンテンツのコード シリアル化を構成しません

using System.ComponentModel;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string PValue { get; set; }

2025.01.20 Shift-JIS を扱う
System.NotSupportedException: 'No data is available for encoding 932. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

private void button1_Click(object sender, EventArgs e)
{
    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}

2025.01.20 null 参照の可能性があるものの逆参照です。

private void button1_Click(object sender, EventArgs e)
{
    // エラー発生
    listBox1.Items.Add(treeView1.SelectedNode.Text);

    // エラー対応
    if (treeView1.SelectedNode is not null)
    {
        listBox1.Items.Add(treeView1.SelectedNode.Text);
    }
}

-C# 開発