DirectoryModuleCatalog fails with Exception "The invoked member is not supported in a dynamic assembly."

Topics: Prism v2 - WPF 3.5
Apr 21, 2010 at 10:43 AM
Edited Apr 21, 2010 at 11:39 AM

Hello,

 

I have upgraded my app to use Enterprise Library 5.0 / Unity 2.0 and a personally build Composite Application Library with References to the new Assemblies.

 

Now, when application starts, I'm getting an exception "The invoked member is not supported in a dynamic assembly." in class 'DirectoryModuleCatalog.Desktop' in method 'InnerLoad' - Line 60 =  "loadedAssemblies.AddRange(assemblies)" .

        /// <summary>
        /// Drives the main logic of building the child domain and searching for the assemblies.
        /// </summary>
        protected override void InnerLoad()
        {
            if (string.IsNullOrEmpty(this.ModulePath))
                throw new InvalidOperationException(Resources.ModulePathCannotBeNullOrEmpty);

            if (!Directory.Exists(this.ModulePath))
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture, Resources.DirectoryNotFound, this.ModulePath));

            AppDomain childDomain = this.BuildChildDomain(AppDomain.CurrentDomain);

            try
            {
                List<string> loadedAssemblies = new List<string>();

                var assemblies = (
                                     from Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()
                                     where !(assembly is System.Reflection.Emit.AssemblyBuilder)
                                           && !String.IsNullOrEmpty(assembly.Location)
                                     select assembly.Location
                                 );

                loadedAssemblies.AddRange(assemblies);
...

I also tried with an empty directory, but it gives me the same error.

My Solution is using VS2010 .Net4.0 ...

Any idea what's wrong ?

Bye, Stefan

Update: I take the 'DirectoryLookupModularity'-Sample from the Quickstarts and there I have got the same exception after upgrading the solution from .net3.5 to .net4.0.

 Update II: While deeper searching the KnowledgeBase I found, that there are two patched pre versions

 - one prepared for unity2.0/entlib5.0 http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=205372

- one for usage with .net4 http://compositewpf.codeplex.com/wikipage?title=Migrating%20Prism%20v2.1%20to%20.Net%204.0%20RC&referringTitle=VS%202010%20and%20.Net%204.0

So now I will merge both and hope that goes right...

Apr 23, 2010 at 5:38 PM
Edited Apr 23, 2010 at 5:40 PM

Just an FYI - I got around this by modifying the above referenced code (i.e. the query for assemblies) like this:

 

 var assemblies = (
             from Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()
             where !assembly.IsDynamic
                 && !String.IsNullOrEmpty(assembly.Location)
             select assembly.Location
         );

 

* Note the change from !(assembly is System.Reflection.Emit.AssemblyBuilder) to !assembly.IsDynamic