How to load assembly from Stream or byte [] in WP7?

I want to load the assembly at runtime using a Stream or Byte array.

In .net you can use Assembly.Load(Byte[], Byte[]) http://msdn.microsoft.com/en-us/library/twt16z2x.aspx

In standard Silverlight, you can use AssemblyPart.Load() http://msdn.microsoft.com/en-us/library/cc190521%28v=VS.96%29.aspx

But on Windows Phone 7, none of these methods are available.

+7
source share
1 answer

Well, as you pretty much discovered; you cannot do this. The design does not allow you to load an assembly that is not supplied in your XAP. This is a security design because they donโ€™t want you to download and run arbitrary code that has not passed Marketplace validation.

This is on par with how Apple controls its App Store. Why this function is not, and why I doubt that it will be added:

  • Trading floor. Microsoft requires all applications to pass Blackbox validation. They are probably looking for a number of things, such as performance, major mistakes, risky material, and user interface consistency. Allowing the developer to download and run any build completely bypasses the Marketplace. This harms the user in several ways. The first is that the developer will be tempted to use it as a means of distributing updates outside the Marketplace or to sneak in particular (like porn), which Microsoft does not allow on their site.
  • Security. The ability to load an assembly is a powerful feature that can be good and bad. If the developer implemented it incorrectly, it may be possible to use it. Secondly, this could be a technical limitation (or time limit) for Microsoft regarding how this will affect the application sandbox. Or, even worse, the seemingly harmless application loads another assembly after it has already passed the test, and then starts to do something bad; like logging keys and downloading it somewhere. Since he walked around the Marketplace, Microsoft would never have been able to catch him before she hit the public.

What you can do, as OJ suggests in the comments, make assemblies as part of your XAP and use one of the Assembly.Load overloads that let you load it by name. You can dynamically load assemblies, they just have to be part of your XAP.

+10
source

All Articles