开发者

Unable to load assembly in strongly signed silverlight code

开发者 https://www.devze.com 2023-04-12 10:14 出处:网络
In a Silverlight 4 app I\'m trying to instantiate an object whose type isn\'t known until run-time, usi开发者_如何转开发ng this code:

In a Silverlight 4 app I'm trying to instantiate an object whose type isn't known until run-time, usi开发者_如何转开发ng 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.

Do not use this member in your application. If you do, your code will throw a MethodAccessException. This member is security-critical, which restricts it to internal use by the .NET Framework for Silverlight class library.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消