Errors Creating WebPart Subclass In Another Assembly
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?
Answer
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:
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
Assembly a = System.Reflection.Assembly.ReflectionOnlyLoadFrom(filename);
static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
{
return System.Reflection.Assembly.ReflectionOnlyLoad(args.Name);
}
However, if you need a solution for your project, just add the assemblies to the GAC and it will be able to resolve them.
Related Questions
- → Licensing system for client side code web application
- → Can ASP.NET AJAX partial rendering work inside a SharePoint 2007 application page?
- → Windows Sharepoint Services (WSS) and Forms Authentication - Passing those credentials to other ASP.NET Forms Authentication Apps
- → Bypass invalid SSL certificate errors when calling web services in .Net
- → Errors creating WebPart subclass in another assembly
- → Do I have to use InfoPath forms for every task within a SharePoint workflow?
- → Hide SharePoint web part using javascript onclick method
- → How do I check if a Sharepoint Document Library has the Require Approval flag set, using the Sharepoint API?
- → Jquery - JS Clear table before new search, whitin function or out?
- → Automatically open Office add-in on SharePoint Online
- → Knockout unable to process binding in a specific function
- → Reformat list to grouped structure
- → Hide/Remove ContentType from a SP List with JavaScript