why I just can't make the MEF load my stuff?

Topics: Prism v4 - Silverlight 4
Jan 25, 2011 at 4:15 PM

I basically follow the Prism sample ModularityWithMef.Silverlight

My catalog xaml is very simple

 

    <Modularity:ModuleInfoGroup InitializationMode="OnDemand">
        <Modularity:ModuleInfo Ref="CustomerManagement.Silverlight.xap" ModuleName="CustomerManagementModule" ModuleType="CustomerManagement.CustomerManagementModule, CustomerManagement" />
    </Modularity:ModuleInfoGroup>


the module itself simply has nothing in it

 

namespace CustomerManagement {
     [ModuleExport(typeof(CustomerManagementModule), InitializationMode = InitializationMode.OnDemand)] 
public class CustomerManagementModule : IModule { } }

and then I use the exact same method to load the module

 

ModuleManager.LoadModule("CustomerManagementModule");

 

I wire up the download event, OK, I can see the total bytes is exactly the same to the file size, so that means the program is downloading it properly, but why the heck it is still throwing out 4004 exception?

 

Could anyone give me a hint? thanks a lot!

Jan 25, 2011 at 5:51 PM

ok, I gave up using MEF, just using the approach in ModularityWithUnity works fine.MEF is really a pain in the ass.

 

However, I get another question, does anyone know how to setup the bytes in each downloading chunk by using ModuleManager?

It is very strange, when I run the Prism sample, the ModuleE.xap is only 160K, but the DownloadProgressChanged is fired 4 times.

When I run mine, my xap is more than 800K, but the event is only fired 2 times. Why?

 

The second question is, I tried to use a BusyIndicator to wrap my main region, it's like this:

 

            <toolkit:BusyIndicator Grid.Row="1" IsBusy="{Binding IsDownloading}">
                <toolkit:BusyIndicator.BusyContent>
                    <StackPanel >
                        <TextBlock FontSize="18" Foreground="DarkSlateBlue" FontWeight="Bold">
                    Package is Loading ...
                        </TextBlock>
                        <TextBlock Text="{Binding Progress}" FontSize="18" />
                    </StackPanel>
                </toolkit:BusyIndicator.BusyContent>
                <ItemsControl regions:RegionManager.RegionName="MainRegion" Style="{StaticResource RegionContentTemplate}">
                </ItemsControl>
            </toolkit:BusyIndicator>

I update the property data in the ProgressChanged event, but the BusyIndicator is just not triggered. However, when the downloading is down, the BusyIndicator will flash very quick. It's almost like, when downloading, the screen is frozen. I thought it's an Async operation. Did I miss anything? thanks!

 

Jan 25, 2011 at 8:48 PM

Hi,

The reason you are experiencing such a fast download time on your xap file versus the one on the Modulartiy Quickstart, is because the ModularityWithMef.Silverlight.Web project of the solution uses an HttpHandler, which simulates a slow download for each requested module. On real production environments, you will experience a normal download time and the events will fire more times compared when doing such an operation on Visual Studio internal webserver, Cassini.

In the other hand, based on my understanding of your scenario, you need to indicate that the application is busy when you start doing a long operation and indicate that it is no longer busy when is finished. Using the BusyIndicator control helps you to achieve this by setting the IsBusy property. The expected behavior of the BusyIndicator is to freeze the screen while the Isbusy property is set to true.

One possible way to workaround this, is instead of set the values on the LoadModuleProgressChanged event is set the property when you start the long operation, that means when you click a button or fire an action to download the module, and finally set the IsBusy property back to false when the LoadModuleCompleted event is fired.

I hope you find this information useful.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic

 

Jan 25, 2011 at 8:56 PM
mbronzovic wrote:

Hi,

The reason you are experiencing such a fast download time on your xap file versus the one on the Modulartiy Quickstart, is because the ModularityWithMef.Silverlight.Web project of the solution uses an HttpHandler, which simulates a slow download for each requested module. On real production environments, you will experience a normal download time and the events will fire more times compared when doing such an operation on Visual Studio internal webserver, Cassini.

In the other hand, based on my understanding of your scenario, you need to indicate that the application is busy when you start doing a long operation and indicate that it is no longer busy when is finished. Using the BusyIndicator control helps you to achieve this by setting the IsBusy property. The expected behavior of the BusyIndicator is to freeze the screen while the Isbusy property is set to true.

One possible way to workaround this, is instead of set the values on the LoadModuleProgressChanged event is set the property when you start the long operation, that means when you click a button or fire an action to download the module, and finally set the IsBusy property back to false when the LoadModuleCompleted event is fired.

I hope you find this information useful.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic

 

Hi,

 

since you mentioned it, I now realize the Web project does have a HttpHandler to simulate a slowly download, haha, that's nice.

I think I probably need a better way to show the Progress instead of using BusyIndicator so the window won't get frozen.

 

thanks again!

Jan 26, 2011 at 12:16 PM

Is it true that MEF is not working as in the example provided, I imetated the code in the quickstart, can't get it to work .... always this nasty exception error

ModuleTypeLoadingException ...

any help on this ...

Reagrds

Jan 26, 2011 at 12:56 PM

Dear Guys,

I just figure it out ... none of the PRISM dll should be copy local , all should be set to FALSE.

It just worked !!

Regards,

Waleed