Silverlight Assembly.Load() only works with the full/strong name

倖福魔咒の 提交于 2019-12-12 13:20:02

问题


Apparently the implementation of Assembly.Load() in Silverlight needs a full/strong name.

E.g. this works:

Assembly.Load("MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=...");

while this will fail even if MyAssembly is already loaded:

Assembly.Load("MyAssembly");

Is there a workaround so that it's possible to use the simple name?


回答1:


As far as I know, there isn't a way to work around this in Silverlight without using the full name. However, you may be able to accomplish your ultimate goal (depending on what you're trying to do) in another way. For example, the XAML parser is a little more forgiving about assembly names, so if you're just trying to create an instance of a class within that assembly (using the default constructor), then something like

XamlReader.Load("<my:ClassName xmlns:my='clr-namespace:MyNamespace;assembly=MyAssemblyShortName' />")

should do the trick.




回答2:


One way that I got around this was to use typeof on a type contained in the assembly that I need to get a reference to:

var assembly = typeof(MyNamespace.SubNamespace.Type).Assembly;


来源:https://stackoverflow.com/questions/3015513/silverlight-assembly-load-only-works-with-the-full-strong-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!