プログラムの事とか

お約束ですが「掲載内容は私個人の見解です」

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.SelectIEnumerable<BasicGeoposition>に変換してます。 デバッグ実行時は何の問題もなく動きますがリリースビルド時はnew Geopathの行で下のようになります。 f:id:puni-o:20160518152326p:plain

型 '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の引数を遅延実行させなくしました。

こういうものなんですかねぇ・・・