0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ビルド時にJsonConverterAttributeのコンストラクタでエラーが発生する罠を回避する

Last updated at Posted at 2016-05-16

はじめに

以前から謎のエラーが発生してビルドが出来ないことがあったのですが、理由が判明したので残しておきます。

対象者

PCLプロジェクトでjson.netを利用している人。

発生事象

初回のビルド時に以下のエラーが発生する。
一度ビルドに失敗したあと、再度ビルドすれば成功する。

重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態
エラー CA0001 CA0001 : mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes への参照を解決できませんでした。 アクティブ
エラー CA0001 CA0001 : モジュール 'JsonConverterAttributeError.Pcl' を読み取り中に以下のエラーが発生しました: メンバー参照を解決できませんでした: [Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed]Newtonsoft.Json.JsonConverterAttribute::.ctor。 アクティブ

発生原因

PCLプロジェクトでJsonConverterAttribute属性を利用している状態でビルドに対するコード分析を有効化することで発生する。
PCLではない場合、クラッシックデスクトップ/Windows 8/ユニバーサルなプロジェクトでは発生しない。
PCLプロジェクトでもJsonConverterAttribute属性を利用しないか、ビルドに対するコード分析を有効にしていない場合は発生しない。

というわけで、PCLプロジェクトでJsonConverterAttribute属性を利用する場合は、ビルドに対するコード分析を有効にしないことをオススメします。

今回のサンプルコードはこちらです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?