"System.NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません。"私のリリースビルドで。私は、プロダクションコードにあるものを模倣するサンプルアプリケーションを作成しました。上記のコードではVS2015のNullReferenceException C++/CLIリリースビルド
void Abc::LogService::Log(String^ message)
{
try
{
int ret = DoProcessing(message);
Exception^ ex;
if (ret == 0)
{
ex = gcnew ArgumentException("Processing done.");
}
else
{
ex = gcnew ArgumentNullException("message", "Null args");
}
throw ex;
}
finally
{
//do someother thing.
}
}
、それがあることを例外ラインをレポート:コード内throw ex;
ステートメントに対応 at Abc.LogService.Log(String message) in logservice.cpp:line 19
。この機能のリリースビルドで
MSILのように見えます:MSILコードから
.method public hidebysig instance void Log(string message) cil managed
{
// Code size 46 (0x2e)
.maxstack 4
.locals ([0] class [mscorlib]System.Exception V_0,
[1] class [mscorlib]System.Exception ex)
.try
{
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: call instance int32 Abc.LogService::DoProcessing(string)
IL_0007: ldnull
IL_0008: stloc.1
IL_0009: brtrue.s IL_0018
IL_000b: ldstr "Processing done."
IL_0010: newobj instance void [mscorlib]System.ArgumentException::.ctor(string)
IL_0015: stloc.0
IL_0016: br.s IL_0028
IL_0018: ldstr "message"
IL_001d: ldstr "Null args"
IL_0022: newobj instance void [mscorlib]System.ArgumentNullException::.ctor(string,
string)
IL_0027: stloc.0
IL_0028: ldloc.1
IL_0029: throw
IL_002a: leave.s IL_002d
} // end .try
finally
{
IL_002c: endfinally
} // end handler
IL_002d: ret
} // end of method LogService::Log
、それはステートメントIL_0028で、それがNULL値をロードし、それに続く文でスローを呼び出すことを示しています。 これは、try-finallyブロックがある場合にのみ発生します。 上記のコードのデバッグビルドは正常に動作します。
これはVS2015 v140ツールキットのバグとして聞こえますか?