3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Xamarin.iOSでInternalsVisibleToを指定する時の注意

Last updated at Posted at 2014-05-17

c#で指定可能なinternalというアクセシビリティ、同一のアセンブリ以外からのアクセスを禁止するものですが、何でもかんでも禁止してしまうとテストプロジェクトを書いたりする際に問題になります。
それを回避するため、intetnalを指定したアセンブリのAssemblyInfo.csの中で、InternalsVisibleToという、アセンブリを指定する事でそこからのアクセスのみ許す機構があります。

AssemblyInfo.cs
[assembly: InternalsVisibleTo("Couchbase.Lite.Tests")]

が、これ、アクセスを許す先のアセンブリが、Xamarin.iOSのアプリケーションプロジェクトだとうまく動きません。
試行錯誤を繰り返した結果、どうもXamarin.iOSだと、アプリケーションのアセンブリ名が(理由はよく判りませんが)ドットを抜いたものになってしまうので、そのドットを抜いたアセンブリ名を指定してやらないといけないようです。

アセンブリ名指定

上記のアセンブリ名指定のダイアログで、Xamarin.iOSのアプリケーションのアセンブリ名のみ、勝手にドットが外れたものになっているのはよく見ると思います。
このドットなしのアセンブリ名を指定してやらないと、うまくinternalへのアクセスができません。

AssemblyInfo.cs
[assembly: InternalsVisibleTo("CouchbaseLiteTests")]

こんな感じで。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?