tags:

views:

55

answers:

2

The solution to this problem is add the DLLs to the GAC as was suggested in one of the responses to my posting. As I noted in one of my responses, the gacutility will not be available in the environment where this process needs to run. Because of this the simple solution of the gacutility is not an option. To resolve this I derived a Posh function that will add DLLs to the GAC:

param([string]$dllPath)

[string]$publicToken = $null [string]$val = $null [string]$version = $null

if (test-path) $dllPath) { $baseFileName = [System.IO.Path]::GetFileNameWithoutExtension($dllPath) $targetName = "c:\windows\assembly\GAV_MSIL\" + $baseFileName

# Get the key and public token
$val = sn -Tp $dllPath

# Get the version w/o loading
$version = [System.reflection.AssemblyName]::GetAssemblyName($dllPath).Version

# Proceed if the token is valid
if ($val -ne -null)
{
    $vals = $val.split(" ")
    $publicToken = $vals[$vals.length-1]
    $targetNameSub=$targetName + "\" + $version + "__" + $publicToken

    if (!(test-path $targetName))
    {
        Md $targetName | Out-Null
    }

    Md $targetNameSub | Out-Null

    # Copy the DLL to the GAC
    copy-item $dllPath $targetNameSub | Out-Null
}

}

I have tested this and it works very well. In my research I found something that indicated that the gacutility makes entries to the registry which I am not doing. But this function does work quite well.

I have tried to reverse the process to come up with a Posh function to remove the GAC entries but I have not been successful yet each time getting an access denied on the DLL file removal.

+2  A: 

It sounds like the problem is that tools.Utilities.dll itself is fine but one if it's dependencies is unavailable inside of c:\Program Files\subDir. This is suggested by both the error message and the fact that moving the DLL to a different folder fixes the issue. It's likely the missing dependency is available in the new folder.

The easiest way to verify this is to use fuslogvw.exe to see exactly what error is preventing tools.Utilities.dll from loading.

JaredPar
A: 

Add the Assembly to your GAC:

gacutil /i Assembly.dll
cristobalito
The gacutil option appears to be the most straight forward solution. However when I attempt to add the DLL to the GAC I recieve an error that states "Failure adding assembly to the cache: Unknown Error. I tried it with a path to the assembly and then cd'd to the dll directory and tried the same thing. But I received the same error. Not sure where to look for details on the error.
I found the gacutil that I was using was from a .NET 1.x version. Unfortunately, though the delivered software will be under .NET 3.5 or higher the GAC will not be part of the installed system. If I manually copy the files to the gac I can use this class and methods without errors. Since the GAC is a view is it possible to write a powershell script that mimicks the actions of the gacutility?
Sorry - no idea. How come you can't use the GAC in the install? I'm not a deployment guru (and don't really use it myself) so sorry I can't be of more assistance.
cristobalito
If there is interest, a DLL can be added to the GAC without the gacutility.