ラベル C# の投稿を表示しています。 すべての投稿を表示
ラベル C# の投稿を表示しています。 すべての投稿を表示

2022年10月23日日曜日

Visual Studio 2022 でリンクしないアセンブリを指定する

Xamarin.AndroidでAWSSDK.S3を使用している。Debugビルドの時は問題なく動作していたのだが、Releaseビルドだとエラーが出てしまう。
AndroidRuntime	android.runtime.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'Amazon.S3.AmazonS3Config' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Amazon.Util.Internal.PlatformServices.ServiceFactory' threw an exception. ---> System.MissingMethodException: Default constructor not found for type Amazon.Util.Internal.PlatformServices.NetworkReachability
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00076] in :0 
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache) [0x00009] in :0 
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) [0x00027] in :0 
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00020] in :0 
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in :0 
  at System.Activator.CreateInstance (System.Type type) [0x00000] in :0 
  at Amazon.Util.Internal.PlatformServices.ServiceFactory..ctor () [0x00091] in :0 
  at Amazon.Util.Internal.PlatformServices.ServiceFactory..cctor () [0x00082] in :0 
   --- End of inner exception stack trace ---
  at Amazon.S3.AmazonS3Config..cctor () [0x0000a] in :0 
   --- End of inner exception stack trace ---
  ・・・略・・・

リンクの問題らしい。Androidプロジェクトのプロパティを見てみると前者のビルドではリンク「なし」だが、後者のビルドでは「SDKおよびユーザーアセンブリ」だ。ここで消えているのだろう。
試しに「SDKアセンブリのみ」にしてみると確かに動作するようになる。このままでも良いのだが、無駄なものが入るのは避けたい。
今回の場合はアセンブリのリンクをスキップに「AWSSDK.Core;Amazon.Util.Internal.PlatformServices」を入れたところ、Releaseビルドでも動作するようになった。他のアセンブリで同様の作業を行いたい場合は「アセンブリ名;名前空間」を入力すればよい。
参考: Linking on Android#linkskip

2020年2月11日火曜日

「Xamarin.Forms.ImageSource.FromResource」メソッドをリリースビルドで使う場合の注意点

表題の関数を使ったアプリを起動すると、エラーコード「0x80040905」とともに強制終了してしまった。
AndroidとiOS では問題ないのにUWPで失敗するのはなぜなのか...と悩んで色々調べてみた結果、.Net Naitiveを使用する場合はアセンブリ情報を渡さないと実行できないとのこと。

39685 – ImageSource.FromResource doesn't work on UWP in release

4年も前からある問題のようだが、なぜドキュメントに載っていないのか...
この問題を解決するにはbugzillaで述べられているように、「Assembly.GetExecutingAssembly()」を第2引数に渡せばよい。

ImageSource.FromResource("Namespace1.Namespace2.image.png", Assembly.GetExecutingAssembly());


ちょっとだけ賢くなった。

2019年4月1日月曜日

KeyboardPing Ver1.0.0 リリース

KeyboardPingをリリースしました。
キーボードが正しく動いているかどうか確認するプログラムで、遠隔地にあるサーバーに接続されているキーボードの正常確認や、(多分)ゲーム等でのキー連打に使えます。
公開したのはソースコードのみなので、実行ファイルは自分自身でビルドして下さい。

GitHub: https://github.com/Soushi-Atsumi/KeyboardPing