2

Can you use the InternalsVisibleTo assembly attribute in a AssemblyInfo file of a MonoTouch Library to allow MonoTouch Unit Test (Touch.Unit) access to the internals of the MonoTouch library?

This is something that is great to use in non-MonoTouch world to allow testing of internals without having to jump through hoops. However I am not able to get it working with a MonoTouch Unit Test. So before I go any futher I figured I would ask if it is even possible, since this is an iOS Application that is the test runner, so not sure if an iOS application which is compiled to native code can even do this.

Rodney S. Foley
  • 10,190
  • 12
  • 48
  • 66

1 Answers1

1

Yes, it should (or it's a bug) even if I do not recall trying it myself.

The key point is that [InternalsVisibleTo] is mostly a compiler trick and it is supported by the C# compiler (smcs) shipped with MonoTouch (as it's used inside the BCL). As such there's no reason why it should not work from a Touch.Unit-based application.

Now keep in mind that all other rules still applies. E.g. if the the managed linker is enabled when all unused code will be removed (even if marked with the attribute).

poupou
  • 43,413
  • 6
  • 77
  • 174
  • Well the issue I have then is two fold: 1) The Touch.Unit application is not being signed and strong named. I have set it up to be signed and strong named but its not using the information. 2) The Touch.Unit application is not getting an assembly version. It's version is always 0.0.0.0 even though I have an AssemblyInfo.cs that states it should be 1.0.0.0. Also I tried it with all 3 link behaviors and no change. I am just trying to get it to work in the simulator first before attempting it on hardware. – Rodney S. Foley Dec 30 '12 at 18:38
  • The error message provided by MD is: Error CS0281: Friend access was granted to 'MonoTouchUnitTests, PublicKeyToken=0c7aa341ab3f9c12', but the output assembly is named 'MonoTouchUnitTests, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Try adding a reference to 'MonoTouchUnitTests, PublicKeyToken=0c7aa341ab3f9c12' or change the output assembly name to match it – Rodney S. Foley Dec 30 '12 at 18:42
  • @RodneyFoley That looks like build issues - which are way earlier than runtime issues that could affect Touch.Unit. Please attach your solution to a bug report and we'll have a look at it (it's likely configuration related, but maybe the tooling is hiding the *right* choices). – poupou Dec 30 '12 at 18:55
  • I had posted this in Xamarin Forums, and here is the solution for that. I will write up a bug as well, thanks. http://cdn.vanillaforums.com/xamarin.vanillaforums.com/FileUpload/38/a0e79c883a7f30400458c7dd8b9cce.zip – Rodney S. Foley Dec 30 '12 at 19:16