Issue when using both MSAF ans SMF on Windows Phone

Nov 15, 2011 at 10:12 AM

Hi,

I'm working on a Windows Phone projet, and trying to use both the SMF library (http://smf.codeplex.com , latest) and Microsoft's Silverlight Analytics Framework (http://msaf.codeplex.com , latest). They both use MEF for their plug-in architecture and it seems this is somehow causing an issue.

When referencing SMF libraries only, the projet launches fine and videos can be played. However, as soon as I try to reference assemblies from MSAF, I'm trying to use the Google Analytics implementation, an ReflectionTypeLoadException exception is thrown in SMF's AssemblyCatalog class, more specifically the InnerCatalog property.

Here is the stack trace of the exception.

   at System.Reflection.Module.GetTypes()   at System.Reflection.Assembly.GetTypes()   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_Parts()   at System.ComponentModel.Composition.Hosting.AggregateCatalog.<.ctor>b__0(ComposablePartCatalog catalog)   at System.Linq.Enumerable.<SelectManyIterator>d__1a`2.MoveNext()   at System.Linq.Enumerable.<SelectManyIterator>d__1a`2.MoveNext()   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)   at System.ComponentModel.Composition.Hosting.DeploymentCatalog..ctor()   at Microsoft.SilverlightMediaFramework.Core.PluginsManager.InitializeCompositionContainer()   at Microsoft.SilverlightMediaFramework.Core.PluginsManager..ctor()   at Microsoft.SilverlightMediaFramework.Core.SMFPlayer..ctor()   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)   at MS.Internal.TypeProxy.<>c__DisplayClass30.<GetCreateObjectDelegate>b__2a()   at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId)   at MS.Internal.XamlManagedRuntimeRPInvokes.CreateInstance(XamlTypeToken inXamlType, XamlQualifiedObject& newObject)   at MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr pContext, IntPtr pComponent, UInt32 cUriStringLength, String uriString, UInt32 cXamlStrLength, Byte* pXamlStr, UInt32 cAssemblyStrLength, String assemblyStr)   at MS.Internal.XcpImports.Application_LoadComponent(IManagedPeerBase componentAsDO, String resourceLocator, UnmanagedMemoryStream stream, UInt32 numBytesToRead, String assemblyString)   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)   at Redacted.InitializeComponent()   at Redacted..ctor()   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)   at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark)   at System.Activator.CreateInstance(Type type)   at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)   at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)   at System.Delegate.DynamicInvokeOne(Object[] args)   at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)   at System.Delegate.DynamicInvoke(Object[] args)   at System.Windows.Threading.DispatcherOperation.Invoke()   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)   at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

This causes the assembly catalog to not be initialized correctly, therefore videos cannot play anymore because the plugins are not referenced.

Would anybody have an idea about what could cause this issue and how to fix it ?

 

Thanks,

Guillem

Coordinator
Nov 15, 2011 at 10:44 PM

Hi Guillem, not really familar with the projects that you are referencing (will check the out), can you check to see if all the types that you are expecting to be composed are part of your catalog.  Any details on what type it is trying to load and failing would be useful.

cheers

-alok

Nov 18, 2011 at 7:09 AM

Hi alok,

thanks for the reply.

It seems all the types I expect to be composed for the Silverlight Media Framework (i.e. the various playback plug-ins) are properly loaded by MEF when I only reference assemblies from the SMF package and no other assembly requiring it.

Here is the list of assemblies coming from SMF:

Microsoft.SilverlightMediaFramework.Compatibility.Phone
Microsoft.SilverlightMediaFramework.Core.Phone
Microsoft.SilverlightMediaFramework.Plugins.Phone
Microsoft.SilverlightMediaFramework.Plugins.Progressive
Microsoft.SilverlightMediaFramework.Utilties.Phone

However when I add the Google.WebAnalytics dll from the Microsoft Silverlight Analytics Framework, the reflection exception ReflectionTypeLoadException is thrown when trying to build the InnerCatalog. Here is the code extract from the project.

        private TypeCatalog InnerCatalog
        {
            get
            {
                this.ThrowIfDisposed();

                if (this._innerCatalog == null)
                {
                    lock (this._thisLock)
                    {
                        if (this._innerCatalog == null)
                        {
                            var catalog = new TypeCatalog(this._assembly.GetTypes(), _definitionOrigin);
                            this._innerCatalog = catalog;
                        }
                    }
                }
                return this._innerCatalog;
            }
        }

this._assembly.GetTypes() is the part throwing the exception and the assembly is "Google.WebAnalytics, Version=1.4.6.0, Culture=neutral, PublicKeyToken=null"

I must say I did not even bother knowing exactly what types are being catalogued from that dll since it plainly fails to load that early. And I confess my knowledge of the inner workings of MEF is superficial at best.

Maybe I am missing something obvious ?

Cheers,
Guillem

Nov 18, 2011 at 5:45 PM

Which version of the Analytics framework are you using?

Michael

Nov 21, 2011 at 7:39 AM

Hello Michael,

I has hoped I could find out just by viewing the dll details in the explorer, but the version numbers are invariably '1.0.0'. Shouldn't they be set to the current version number ?

I must have been using version 1.5.1 or 1.5.2 which was the latest at the time. I noticed this morning that version 1.5.3 released last saturday contains updates for SMF 2.6 so I am going to try it out.

 

I'll post another reply if the problem has been fixed.

 

Thanks again,

Guillem