私はここインターフェースなぜNullReferenceExceptionが発生していますか?私はインターフェイスを持っているよう
public interface IConfig
{
string name { get; set; }
string address { get; set; }
int phone { get; set; }
List<string> children { get; set; }
}
を持っているだけで3アプリの設定を持っている私のconfigファイルではありません4です。
<add key="name" value="abc" />
<add key="address" value="100 Norin Street" />
<add key="phone" value="709-111-111111" />
起動時に、私はDictionaryAdapterFactoryを使用してapp.configファイルの値を入力しています。私はここでapp.configの値を正常に取得しています。
private readonly IConfig _config;
private readonly DictionaryAdapterFactory _factory;
_factory = new DictionaryAdapterFactory();
_config = _config.GetAdapter<IConfig>(ConfigurationManager.AppSettings);
実行時に、List型の子の値を入力する必要があります。しかし、私はnull例外を取得しています。どうして?
//loop
_config.children.Add(item.values);
ここで問題は何ですか?
私は試しましたが、このエラーが発生しました。 {"System.Collections.Generic.List'1 [System.String]"と入力すると、 'System.String'型のオブジェクトをキャストすることができません。 – user1327064
あなたのメッセージはより多くのコードを表示します。 –
@ user1327064どのコード行が "キャストできません"という例外が投げられましたか? – phoog