Registering a dll into the GAC

markkurten
markkurten used Ask the Experts™
on
When i run the following command, which is in a .bat file
gacutil" /i somefile.dll
it appears to run fine, however my application that uses this dll doesnt work.

to get my application to work, i need to run

gacutil" /u somefile.dll then recycle the app pool then run
gacutil" /i somefil.dll then recycle the app pool.

Is there anyway using a batch file or if i made a .net app to do the registering of the files, that i would then be able to verify the dll was registered successfully in the GAC?

Appreciate any insight.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mohamed OsamaSenior IT Consultant

Commented:
you will need to use GACUTIL command line as follows
gacutil /if assembly.dll
gacutil /cdl
the second one will delete the download cache & hopefully force your application to check for the updated assembly without restarting the application pool.






Full stack Software Engineer
Commented:
to register dll u need to follow this steps:

1. use sn tool to generate cryptographic key pair
i.e sn -k c:\mydll.snk

2. once the snk file was generated go back to your dll project in visual studio.
goto Properties ->Signing, check "sign the assembly" option and browse to the snk file.

3. rebuild the dll project.

4. use the following function to register/unregister and validate your dll:

static void Register(string dllFullPath, string gacutilPath, bool register)
        {
            string dllName = Path.GetFileNameWithoutExtension(dllFullPath);
            if (register)
            {
                if (Directory.Exists(string.Format(@"c:\windows\assembly\GAC_MSIL\{0}", dllName)))
                {
                    Console.WriteLine("{0} already exists in GAC, skip ...", dllName);
                    return;
                }

                Process p = Process.Start(gacutilPath, string.Format("-i \"{0}\"", dllFullPath));
                p.WaitForExit();
                if (p.ExitCode == 0)
                {
                    Console.WriteLine("{0} registered.", dllName);
                }
            }
            else
            {
                if (!Directory.Exists(string.Format(@"c:\windows\assembly\GAC_MSIL\{0}", dllName)))
                {
                    Console.WriteLine("{0} is not registered in GAC, skip ...", dllName);
                    return;
                }

                Process p = Process.Start(gacutilPath, string.Format("-u \"{0}\"", dllName));
                p.WaitForExit();
                if (p.ExitCode == 0)
                {
                    Console.WriteLine("{0} unregistered.", dllName);
                }
            }

hope it helped u :)
Meir RivkinFull stack Software Engineer

Commented:
markkurten: have u managed to register the dll?
Mohamed OsamaSenior IT Consultant
Commented:
or if you don't mind using a 3rd party tool , GACView from NIRSOFT has proven very helpful to me lately.
http://www.nirsoft.net/dot_net_tools/gac_viewer.html

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial