I'm using LoadFrom to call a remote assembly (DLL file is located on a server share). When I try to call any classes or methods from the assembly, however, VS2012 is telling me the namespace or type cannot be found. I would assume this is because the LoadFrom only executes at runtime.
Do I need to define each individual class within my code as needed, or will it all just magically work once I build the project?
Here's the snippet of code I'm working with - it's part of a larger click event on a form button. * Unfortunately I can't roll the remote DLL up into the app because it's an AutoCAD plugin and must be deployed as a single DLL file using local code only.*
// Load SharePoint assembly file from server share
Assembly SPAssembly;
SPAssembly = Assembly.LoadFrom(@"\\server_name\spapps\ISAPI\Microsoft.SharePoint.dll");
// Specify web context & add user to group
using(SPSite oSiteCollection = new SPSite("http://sub.companyweb.com"))
{
using(SPWeb oWebsite = oSiteCollection.OpenWeb("/subsite"))
{
using(SPWeb oWebsiteRoot = oSiteCollection.RootWeb)
{
// Add new account to security group on app site
SPUser theUser = elevatedSite.RootWeb.EnsureUser("i:0#.f|extmembershipprovider|" + newUsername);
SPGroup theGroup = elevatedSite.RootWeb.Groups["SharePoint Group"];
theGroup.AddUser(theUser);
theGroup.Update();
}
}
}
The problem I'm running into is that SPSite, SPWeb, and elevatedSite all return errors since they come from the SharePoint DLL. The overall code takes information entered into this form application, creates a SharePoint account in a SQL database, then adds the account to a group on the SharePoint site. The last part requires the SharePoint reference, and is the snippet I've shared.
Keep in mind that, while I'm using this in a SharePoint context, my question is NOT specific to SharePoint.
I need to know how to properly reference and use a remote assembly DLL file - one not located in the project folder, but at some centralized location that all users would have read access to.