1

I have a v4.0 assembly that is both in the GAC (4.0 location) for runtime use and in a location on disk for designtime use. I have the designtime DLL's location set in the registry so that I can add it via Add Reference in Visual Studio.

I also have a service that is using this DLL. I added it via Add Reference and can compile without issue while referencing its classes. However, when I run my service, it doesn't pull the DLL from the GAC, and I get an error that the service can't find a class in the GACked DLL. I can change "copy local" to true and it will work just fine, but that defeats the purpose of having the DLL in the GAC.

Any suggestions on how to troubleshoot?


I can add as reference to a new console app and access the object. Not sure what the issue is with the service.


It may not be finding the type.. but I can reference the type from the console app (using the GACked assembly), so I'm not sure why it can't find it when running the service.

zimdanen
  • 5,508
  • 7
  • 44
  • 89
  • I'm not sure what could cause this. But I would try running Process Monitor while running the program. It may reveal clues to understanding why the DLL can't be reached. – Francis Gagnon Nov 26 '12 at 17:23
  • 1
    Some odds that you use the wrong version of gacutil.exe, .NET 4 uses a different GAC. Get help from Fuslogvw.exe – Hans Passant Nov 26 '12 at 17:27
  • @Hans - I'm using the right gacutil (4.0.30319.1), and it's in the right GAC. – zimdanen Nov 26 '12 at 17:31
  • @zimdanen - Once you have a trace, I would start by searching for the DLL in question (ctrl + f). By doing this, you may find the lines where your service attempted to get the DLL. If that doesn help, I would just start filtering the results down starting by including only the service process. – Francis Gagnon Nov 26 '12 at 17:34
  • @FrancisGagnon - I don't see the DLL mentioned anywhere in my WebDev.WebServer40.EXE process's entries.. – zimdanen Nov 26 '12 at 17:37
  • Well, document your question better by showing the binding log you get from Fuslogvw.exe – Hans Passant Nov 26 '12 at 17:39
  • @HansPassant: Just running it should show any failed bindings, right? It doesn't show anything when I run the service. It may be finding the DLL but not the type? But I can reference the type from my console app and instantiate it.. – zimdanen Nov 26 '12 at 17:46
  • @zimdanen - Search for the DLL in an unfiltered trace to see if it's there. If it doesn't show up, we have to wonder why the service doesn't even try to get it. It should try to find the DLL in it's local directory first and work its way to the GAC. – Francis Gagnon Nov 26 '12 at 17:50
  • Looks like you got your answer. It also seems I was wrong on the DLL load order. http://stackoverflow.com/questions/954257/the-order-of-assemblies-being-loaded – Francis Gagnon Nov 26 '12 at 18:05

1 Answers1

3

You will need to add the assembly under the system.web tag in the machine.config

<system.web>
    <compilation>
        <assemblies>
            <add assembly="YOUR_DLL_NAME, Version=1.1.0.0, Culture=neutral, PublicKeyToken=YOUR_KEY_TOKEN" />  
        </assemblies>
    </compilation>
</system.web>

Depending on your setup, the configuration file can be found: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config or C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

stafy
  • 81
  • 2
  • Thanks! Looks like a [config-based reference is needed if I'm not using pre-compiled code](http://stackoverflow.com/a/530688/128217). – zimdanen Nov 26 '12 at 17:55