Bug 19580 - "internal" property cannot access from NUnit testcase having same Namespace
Summary: "internal" property cannot access from NUnit testcase having same Namespace
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.2.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-05-06 23:16 UTC by kochizufan
Modified: 2014-05-08 07:35 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description kochizufan 2014-05-06 23:16:16 UTC

I compile couchbase-lite-net for iOS and Android. 
And when I writing test-code, there are inaccessible bug which is not occured in Android but occured in iOS.

Situation is,

In logic code, Couchbase.Lite.Database includes internal property.

#### Code ####
namespace Couchbase.Lite 
    public partial class Database 

        internal LruCache<String, Document>             DocumentCache { get; set; }

#### Code ####

And, I wrote testcase like this:

#### Test ####
namespace Couchbase.Lite
    public class TestsSample

        public void TestCreateDocument()

            var db = manager.GetExistingDatabase(DefaultTestDb); //<= This is Database class.


            db.DocumentCache.EvictAll(); //<= Not error in Android, but in iOS.


#### Test ####

This testcase pass in Android, but not in iOS, because of protection level issue.

Error says:

Error CS0122: `Couchbase.Lite.Database.DocumentCache.get' is inaccessible due to its protection level (CS0122) (Couchbase.Lite.Touch.Tests)
Both Logic and test codes are exactly same in both Android and iOS.

Is this a bug? 
Or, this is based on difference of JIT and AOT?

Environment is,

=== Xamarin Studio ===

Version 4.2.4 (build 35)
Installation UUID: 7b4d01c4-ec8d-4fd7-bcf3-46ea74a47d8b
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 302060000

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 773c77c
Build date: 2014-04-18 15:39:16-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.12.3 (Business Edition)
Android SDK: /adt-bundle-mac/sdk
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

=== Build Information ===

Release ID: 402040035
Git revision: 1173cb1c45bc56cb702e82cd21a7c9d0cea4acbf
Build date: 2014-04-17 13:45:52-04
Xamarin addins: 53bde0041263928e8bd64686f5ca5a8e4338dd76

=== Operating System ===

Mac OS X 10.9.2
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-05-07 03:53:48 UTC
This is not related to AOT/JIT, because the error happens during compilation of the C# source code (the AOT/JIT are only used at runtime).

Is all the code in the same project, or are they in different projects?

In general projects should not be able to access internal members of other projects, but this can be overcome by using the InternalsVisibleTo attribute - however it is required that assemblies are properly signed when using the InternalsVisibleTo attribute, otherwise you'll get precisely the error you're seeing.

So my initial guess would be that the iOS projects/assemblies aren't properly signed.
Comment 2 kochizufan 2014-05-07 10:38:51 UTC
Thank you for replying my report,

Yes, I devide Logic project and Test project, like this:

Android Logic:
  Project name: Couchbase.Lite.Android
  Namespace: Couchbase.Lite
Android Test:
  Project name: Couchbase.Lite.Droid.Tests
  NameSpace: Couchbase.Lite.Tests

iOS Logic:
  Project name: Couchbase.Lite.Touch
  Namespace: Couchbase.Lite
iOS Test:
  Project name: Couchbase.Lite.Touch.Tests
  NameSpace: Couchbase.Lite.Tests

But, in both Android and iOS Logic project, AssemplyInfo.cs contains

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

This setting does not contain PublicKey infomation, so I think Tests don't need proper sign..
Is it misunderstanding?

I can send zipped whole project or point git repository, if need.


Comment 3 kochizufan 2014-05-07 17:45:40 UTC
Sorry, I forgot that iOS executable's assembly name cannot include ".".

I change 

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


[assembly: InternalsVisibleTo("CouchbaseLiteTests")]

in iOS, it works...
Comment 4 Rolf Bjarne Kvinge [MSFT] 2014-05-08 07:35:54 UTC
Great that you figured it out!

I'll close the bug report then.