在另一个程序集中创建 WebPart 子类时出错
我正在尝试创建 WebPart 的子类,它将充当我们创建的任何 WebPart 的父类。 如果我在同一个项目中创建一个空类,我就可以像人们所期望的那样继承它。 但是,如果我尝试将其放置在另一个程序集中(我能够引用和使用其中的类),我会收到以下错误:
无法加载一种或多种请求的类型。 检索 LoaderExceptions 属性以获取更多信息。
其他可能相关的信息(我通常不是 SharePoint 开发人员):我编译 dll,从开发项目引用它们,并将它们复制到 SharePoint 实例的 /bin 目录中。 程序集均已签名。 我正在尝试使用 VS2008 的“部署”功能进行部署。
不幸的是,这似乎不是 SharePoint 特定的错误,并且我不确定如何解决该问题。 有没有人经历过这个,你有什么建议吗?
I am trying to create a subclass of WebPart that will act as a parent to any WebParts we create. If I create an empty class in the same project, I am able to inherit from it as one would expect. However, if I try to place it in another assembly -- one that I've been able to reference and use classes from -- I get the following error:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Other information that may be pertinent (I am not normally a SharePoint developer): I compile the dlls, reference them from the dev project, and copy them into the /bin directory of the SharePoint instance. The assemblies are all signed. I'm am attempting to deploy using VS2008's 'deploy' feature.
Unfortunately, this does not appear to be a SharePoint specific error, and I'm not sure how to solve the problem. Has anyone experienced this and do you have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我发现问题了。 由于某种原因,打包任务使用反射。 当它发现您的类继承自另一个域中的类时,它会尝试使用反射来加载它。 但是,反射不执行绑定策略,因此不会加载该域。
打包程序的作者可以通过添加以下代码来解决此问题:
但是,如果您的项目需要解决方案,只需将程序集添加到 GAC 即可解决它们。
OK, I found the problem. The packaging task uses reflection for some reason or another. When it finds that your class inherits from a class in another domain, it tries to load it using reflection. However, reflection doesn't do binding policy, so that domain isn't loaded.
The authors of the packaging program could solve this by adding the following code:
However, if you need a solution for your project, just add the assemblies to the GAC and it will be able to resolve them.