GacInstall on Sharepoint Timer Job a.k.a SPJobDefinition

565 Views Asked by At

I am trying to implement a plugin architecture to our Sharepoint solution at the moment where administrators can upload dll files which will be installed and processed by our solution.

Implementation requires GAC installation of the uploaded dll, which I have accomplished using

private void InstallToGac(byte[] libraryContent, string filename)
        {
            string path = tempFolder + filename;
            File.WriteAllBytes(path, libraryContent);
            try
            {
                new System.EnterpriseServices.Internal.Publish().GacInstall(path);
            }
            catch (Exception ex)
            {
                Logger.Error("Error while installing dll to GAC.", ex);
                throw;
            }
            finally
            {
                File.Delete(path);
            }
        }

This simply installs the dll to GAC and works fine if it is called within Sharepoint context. However, it wouldn't work on multi-server environment since this will only install it on the front-end where the administrator uploaded the file. So, I have moved the code above to a timer job, by inheriting SPJobDefinition. GacInstall does not install the dll to GAC anymore. On debug mode GacInstall line works fine without throwing any exception but without any effect either.

System.Security.Principal.WindowsIdentity.GetCurrent().Name;

returns Network Service within the timer job. I work on single server Sharepoint 2010 Foundation but I need this to work on 2007/2010/2013 on both single and multi server environments.

1

There are 1 best solutions below

0
On BEST ANSWER

Turns out Network Service was the problem all along. I did not consider it as a problem since my all Sharepoint App pools run via Network Service and somehow function fine.. Changing the "Log On As" of "Sharepoint 2010 Timer" service on "Local Services" fixed it.

Also, it turns out that GacInstall(path) does not throw exception in some cases including this one, and generate Windows Event with no useful information as mentioned here.