In a Silverlight 4 app I’m trying to instantiate an object whose type isn’t known until run-time, using this code:
Assembly assembly = Assembly.LoadFrom("Name.Of.Some.dll");
Type type = assembly.GetType("Full.NameSpace.And.ClassName");
object o = Activator.CreateInstance(type);
However, the Assembly.LoadFrom() call results in an exception:
{System.MethodAccessException: Attempt by security transparent method 'Mosaic.Layers.LayerParamChangeHandlerInfo.CreateParamHandler()' to access security critical method 'System.Reflection.Assembly.LoadFrom(System.String)' failed.
I’ve done some Googling for the error, but I still can’t figure out why I’m getting the exception (something related to the assemblies being strongly signed, I believe) and, more importantly, how to solve the problem and create my object.
You are not allowed to call this method from your own code, cause its security critical and restricted to be used only internal in .NET Framework.
The only available Load method for assemblies in Silverlight is Assembly.Load(string). If you want to dynamically load an assemblies, take a look at this approach.