Bug 8725 - MonoTouch cannot cope with referenced assemblies with more than 1 module
Summary: MonoTouch cannot cope with referenced assemblies with more than 1 module
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 6.0.x
Hardware: PC Mac OS
: --- enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-12-03 10:43 UTC by Marek Safar
Modified: 2017-09-28 08:23 UTC (History)
5 users (show)

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

reference file (3.00 KB, application/x-msdownload)
2012-12-03 10:44 UTC, Marek Safar
netmodule (2.00 KB, application/octet-stream)
2012-12-03 11:21 UTC, Marek Safar

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 for Bug 8725 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Marek Safar 2012-12-03 10:43:37 UTC
1. Create any sample app
2. Add attached assembly
3. Ad a call "ModTest.Main (null)" to the assembly
4. Try to run it (fails even on simulator)
Comment 1 Marek Safar 2012-12-03 10:44:41 UTC
Created attachment 3048 [details]
reference file
Comment 2 Sebastien Pouliot 2012-12-03 11:02:16 UTC
Just adding the reference I get:

error MT0009: Error while loading assemblies: /Users/poupou/Downloads/test-416.exe
	Module not found : test-416-mod.netmodule
  at MonoTouch.Tuner.MonoTouchResolver.AddAssembly (System.String fileName) [0x00000] in <filename unknown>:0 
  at MTouch.Main2 (System.String[] args) [0x00000] in <filename unknown>:0 
  at MTouch.Main (System.String[] args) [0x00000] in <filename unknown>:0 

while building (the linker disabled but the resolver is still used). Did you get something different ?
Comment 3 Marek Safar 2012-12-03 11:21:45 UTC
Created attachment 3049 [details]
Comment 4 Marek Safar 2012-12-03 11:22:08 UTC
Forget to attach the netmodule
Comment 5 Sebastien Pouliot 2012-12-03 11:50:48 UTC
Can you post what error you're getting ? and which branch you're using ?
Comment 6 Marek Safar 2012-12-03 11:59:12 UTC
I get error MT0009: Error while loading assemblies: /Users/marek/git/mono/mcs/tests/projects/MonoTouch/bin/iPhoneSimulator/Debug/test-416.exe

This is with 6.1 but maybe that's because of MD cannot cope with dependencies correctly
Comment 7 Sebastien Pouliot 2012-12-03 12:06:15 UTC
Ok, that one is fixed (locally) it was related to new [LinkWith] code. After that it works... and prints 5.

But you can get MT1010 when symlink'ing is not possible and that will need more changes. Anyway the good news is that it's not a runtime issue.
Comment 8 Sebastien Pouliot 2012-12-03 20:37:31 UTC
The first problem is that (unless we symlink) we copy all the assemblies without loading them. That's a lot faster (than using Cecil) but we can't know about extra, .netmodule, files.

There's a performance impact to load them using Cecil - but it might not be a huge one since we'll, in many case, end up doing so. The fast-path (symlink'ing) would stay fast (as it already works). I'll try this out and do some timings.
Comment 9 Sebastien Pouliot 2012-12-05 11:55:23 UTC
Even if the .netmodule file is copied the (old 0.6.*) Mono.Cecil does not like loading this:

--- inner exception
System.ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
  at System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) [0x00000] in <filename unknown>:0 
  at System.Collections.ArrayList.get_Item (Int32 index) [0x00000] in <filename unknown>:0 
  at System.Collections.CollectionBase.System.Collections.IList.get_Item (Int32 index) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.ModuleReferenceCollection.get_Item (Int32 index) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.ReflectionReader.GetExportedTypeScope (MetadataToken scope) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.ReflectionReader.VisitExternTypeCollection (Mono.Cecil.ExternTypeCollection externs) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.AggressiveReflectionReader.ReadExternTypes () [0x00000] in <filename unknown>:0 
  at Mono.Cecil.AggressiveReflectionReader.VisitTypeDefinitionCollection (Mono.Cecil.TypeDefinitionCollection types) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.ReflectionReader.VisitModuleDefinition (Mono.Cecil.ModuleDefinition mod) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.StructureReader.TerminateAssemblyDefinition (Mono.Cecil.AssemblyDefinition asm) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.AssemblyDefinition.Accept (IReflectionStructureVisitor visitor) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.AssemblyFactory.GetAssembly (Mono.Cecil.Binary.ImageReader irv, Boolean manifestOnly) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.AssemblyFactory.GetAssembly (Mono.Cecil.Binary.ImageReader reader) [0x00000] in <filename unknown>:0 
  at Mono.Cecil.AssemblyFactory.GetAssembly (System.String file) [0x00000] in <filename unknown>:0 
  at MonoTouch.Tuner.MonoTouchResolver.ReadAssembly (System.String file) [0x00000] in <filename unknown>:0 
  at MonoTouch.Tuner.MonoTouchResolver.AddAssembly (System.String fileName) [0x00000] in <filename unknown>:0 

I'll check if that's fixed with master (Cecil 0.9.x).
Comment 11 PJ 2013-11-19 16:44:43 UTC
This bug was targeted for a past milestone, moving to the next non-hotfix active milestone.
Comment 12 GouriKumari 2016-01-12 22:26:50 UTC
Moving milestone to "far future".
Comment 13 Rolf Bjarne Kvinge [MSFT] 2017-09-28 08:22:34 UTC
I think a lot of pieces are missing to get proper support for additional assembly modules (tests, AOT, bundle creation, etc), so maybe we should just add this as a known limitation (https://developer.xamarin.com/guides/ios/advanced_topics/limitations/)
Comment 14 Rolf Bjarne Kvinge [MSFT] 2017-09-28 08:23:15 UTC
Also additional assembly modules is very rarely used