UWPのリリースビルドアプリでMissingInteropDataExceptionが出た
UWPの開発でデバッグ中(デバッグビルド)では全然問題が無かったのに、リリースビルドで実行したら例外が出ちゃった話です。
ソースはこんな感じ
class Coordinate { public double Latitude { get; set; } public double Longitude { get; set; } } var points = new[] { new Coordinate { Latitude = 35, Longitude = 139 }, new Coordinate { Latitude = 36, Longitude = 140 } }; var line = new MapPolyline(); line.StrokeColor = Colors.Red; line.StrokeThickness = 10; line.Path = new Geopath(points.Select(p => new BasicGeoposition { Latitude = p.Latitude, Longitude = p.Longitude })); Map.MapElements.Add(line);
Coordinateクラスは適当に作りました。 座標データを元に地図に線を描きます。
今回問題となるのはline.Path
に入れるGeopath
のコンストラクタ部分です。
Geopath(IEnumerable<BasicGeoposition> positions)
なのでpoints.Select
でIEnumerable<BasicGeoposition>
に変換してます。
デバッグ実行時は何の問題もなく動きますがリリースビルド時はnew Geopath
の行で下のようになります。
型 'System.Runtime.InteropServices.MissingInteropDataException' の例外が System.Private.Interop.dll で発生しましたが、ユーザー コード内ではハンドルされませんでした 追加情報:ComTypeMarshalling_MissingInteropData この例外のハンドラーがある場合は、プログラムを安全に続行できます。
はい、ワカリマセン。
解決法
// 旧 line.Path = new Geopath(points.Select(p => new BasicGeoposition { Latitude = p.Latitude, Longitude = p.Longitude })); // 新 line.Path = new Geopath(points.Select(p => new BasicGeoposition { Latitude = p.Latitude, Longitude = p.Longitude }).ToArray());
Geopath
の引数を遅延実行させなくしました。
こういうものなんですかねぇ・・・