Bug 21255 - Exception on lazy import
Summary: Exception on lazy import
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.2.5
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-11 07:02 UTC by evnik
Modified: 2016-05-25 00:16 UTC (History)
3 users (show)

Tags:
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:
Status:
RESOLVED NORESPONSE

Description evnik 2014-07-11 07:02:34 UTC
If we have a lazy MEF import like this:
[Import]
private System.Lazy<ILoggerService> logger;

and Linker behavior option is set in "Link SDK assemblies only"
an exception is thrown on first composition:
	Unhandled Exception:
	...
	at System.ComponentModel.Composition.ReflectionModel.ImportType.CheckForLazyAndPartCreator (System.Type) <0x000b0>
	at System.ComponentModel.Composition.ReflectionModel.ImportType..ctor (System.Type,System.ComponentModel.Composition.Primitives.ImportCardinality) <0x0008c>
	at System.ComponentModel.Composition.AttributedModel.AttributedModelDiscovery.CreateMemberImportDefinition (System.Reflection.MemberInfo,System.ComponentModel.Composition.Primitives.ICompositionElement) <0x000c0>
	at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetImportDefinitions () <0x000c8>
	at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.DiscoverExportsAndImports () <0x00038>
	at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetExports () <0x00010>
	at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePartDefinition.get_ExportDefinitions () <0x0005c>
	at System.ComponentModel.Composition.Hosting.TypeCatalog.CreateIndex () <0x000e8>
	at System.Lazy`1.InitValue () <0x00260>
	at System.Lazy`1.get_Value () <0x00034>
	at System.ComponentModel.Composition.Hosting.TypeCatalog.GetCandidateParts (string) <0x00038>
	at System.ComponentModel.Composition.Hosting.TypeCatalog.GetCandidateParts (System.ComponentModel.Composition.Primitives.ImportDefinition) <0x00098>
	at System.ComponentModel.Composition.Primitives.ComposablePartCatalog.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition) <0x00074>
	at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition) <0x00020>
	at System.ComponentModel.Composition.Hosting.AggregateCatalog.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition) <0x000fc>
	at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) <0x001a8>
	at System.ComponentModel.Composition.Hosting.CatalogExportProvider/InnerCatalogExportProvider.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) <0x00054>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0005c>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0001c>
	at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) <0x00070>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0005c>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0001c>
	at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) <0x00244>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0005c>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0001c>
	at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) <0x00150>
	at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition,System.Collections.Generic.IEnumerable`1<System.ComponentModel.Composition.Primitives.Export>&) <0x0005c>
	at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports (System.ComponentModel.Composition.Primitives.ImportDefinition,System.ComponentModel.Composition.Hosting.AtomicComposition) <0x00030>
	at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore (System.Type,System.Type,string,System.ComponentModel.Composition.Primitives.ImportCardinality) <0x00094>
	at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore<T> (string,System.ComponentModel.Composition.Primitives.ImportCardinality) <0x00054>
	at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue<T> (string) <0x00040>
	at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue<T> () <0x00038>
	at TestApplication.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication,MonoTouch.Foundation.NSDictionary) <0x000c8>
	at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c8>
	...
	43  UIKit                               0x319d02ff <redacted> + 274
	44  UIKit                               0x319cfd4f <redacted> + 1390
	45  UIKit                               0x319ca353 <redacted> + 714
	46  UIKit                               0x3196541f <redacted> + 3130
	47  UIKit                               0x31964721 <redacted> + 72
	48  UIKit                               0x319c9b3d <redacted> + 664
	49  GraphicsServices                    0x33df570d <redacted> + 608
	50  GraphicsServices                    0x33df52f7 <redacted> + 34
	51  CoreFoundation                      0x2f1b79df <redacted> + 34
	52  CoreFoundation                      0x2f1b797b <redacted> + 346
	53  CoreFoundation                      0x2f1b614f <redacted> + 1398
	54  CoreFoundation                      0x2f120c27 CFRunLoopRunSpecific + 522
	55  CoreFoundation                      0x2f120a0b CFRunLoopRunInMode + 106
	56  UIKit                               0x319c8dd9 <redacted> + 760
	57  UIKit                               0x319c4049 UIApplicationMain + 1136
	at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00110>
	at MonoTouch.UIKit.UIApplication.Main (string[],string,string) <0x000dc>
	at TestApplication.Main (string[]) <0x0003c>
	at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c8>
	...

Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
	  at System.ComponentModel.Composition.ExportServices.CreateStronglyTypedLazyFactory (System.Type exportType, System.Type metadataViewType) [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.ReflectionModel.ImportType.CheckForLazyAndPartCreator (System.Type type) [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.ReflectionModel.ImportType..ctor (System.Type type, ImportCardinality cardinality) [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.AttributedModel.AttributedModelDiscovery.CreateMemberImportDefinition (System.Reflection.MemberInfo member, ICompositionElement origin) [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetImportDefinitions () [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.DiscoverExportsAndImports () [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.AttributedModel.AttributedPartCreationInfo.GetExports () [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePartDefinition.get_ExportDefinitions () [0x00000] in <filename unknown>:0 
	  at System.ComponentModel.Composition.Hosting.TypeCatalog.CreateIndex () [0x00000] in <filename unknown>:0 
	  at System.Lazy`1[System.Collections.Generic.IDictionary`2[System.String,System.Collections.Generic.List`1[System.ComponentModel.Composition.Primitives.ComposablePartDefinition]]].InitValue () [0x00000] in <filename unknown>:0

In case of importing direct type (without Lazy) there are no exceptions.
If Linker behavior option is set in "Don't link" there are no exceptions. This point is so frustrating, when you use different linker options in different solution configurations.
Comment 1 Prashant manu 2014-07-14 05:44:55 UTC
Could you please provide us the test steps you followed and attach a small complete project that demonstrates this behavior?

Also can you please add the logs from the following places?:
Xamarin.iOS Build Host
For Build Host Log: Location:  Open 'Xamarin.iOS Build Host'->Go to Xamarin.iOS Build Host->View Build Host Log> mtbserver.log

For VS IDE log: Location: C:\User\AppData\Local\Xamarin\Log\
For iOS Trace log: Location: C:\Users\User\AppData\Local\Xamarin\Log\MonoTouchVS
Comment 2 Sebastien Pouliot 2016-05-25 00:16:33 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!