我可以将 silverlight dll(仅反射)加载到 .net 应用程序中吗?
我意识到 SL 和 .net CLR 以及类库的区别,并且我不想执行任何代码(只需查询一些属性并检查某些类型是否实现了在共享程序集中声明的接口)。
但我无法使用 Assembly.LoadFrom 加载 SL dll,因为它没有找到依赖项(如 System.Windows.dll 等)。我已经尝试过 Assembly.ReflectionOnlyLoadFrom,但这给了我几乎相同的错误(无法加载依赖项),只是措辞不同......
有没有什么方法可以从 SL 外部反映 SL 程序集?
I realize the difference in SL and .net CLR and Class Library, and I don't want to execute any code (just query some attributes and check whether some types implement an interface declared in a shared assembly).
But I cannot load the SL dll with Assembly.LoadFrom, because it doesn't found the dependencies (like System.Windows.dll and such). I've tried the Assembly.ReflectionOnlyLoadFrom, but that gives me pretty much the same error (cannot load dependencies) just with different wording...
Is there ANY way to reflect an SL assembly from outside of SL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将依赖项(System.Windows.dll 等)复制到与您尝试加载的 Silverlight 程序集相同的目录中。
加载器/融合必须能够定位并加载正确的依赖程序集(即使是“仅反射”),因为重要的元数据(例如从基类继承的方法签名)可能仅驻留在这些依赖项中。
Try copying the dependencies (System.Windows.dll, etc.) to the same directory as the Silverlight assembly you are trying to load.
The loader/fusion has to be able to locate and load the correct dependent assemblies (even for "reflection only") because vital metadata (such as method signatures inherited from base classes) may only reside in those dependencies.
我已切换回 LoadFrom 而不是 ReadOnlyLoadFrom。至少现在它找到了我自己的程序集,而且只是缺少 System.Windows 等。
因此,我订阅了 AppDomain.Current.AssemblyResolve,并将我的 SL 安装文件夹作为参数传递给我的应用程序。因此,现在,对于每个未解析的程序集,我从 SL 目录 (c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0) 按名称查找它
I've switched back to LoadFrom instead of ReadOnlyLoadFrom. At least NOW it found my own assemblies, and it's only missing System.Windows and so on.
So I've subscribed to AppDomain.Current.AssemblyResolve, and passed my SL installation folder as a parameter to my app. So now, for every unresolved Assembly, I look it up by name from the SL directory (c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0)