views:

373

answers:

4

I've got a WCF service, hosted in IIS, which is built in Visual Studio. The WCF service library references a few other assemblies, which are part of the same Visual Studio solution.

I deploy all the assemblies to the GAC, then start a service client, and see it fail trying to resolve one of the referenced client assemblies. I've added a breakpoint in the WCF service contructor, and it appears to not try to load its referenced assemblies using qualified names (and thus not find them in the GAC). If I run an Assembly.Load in the immediate window, once breaked into the WCF contructor, within IIS, I'm able to load each of the missing dlls using qualified (publickeytoken and such) names.

Why does the CLR, or my service library, attempt to load the libraries using names only?

A: 

Are the versions in the GAC different than those that you built with? If so, then you can force your app to use a specific version of your assembly. In web.config, add the following:

<configuration>
   .......
   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
       <assemblyIdentity name="SomeLibrary" publicKeyToken="31bfe996bd364e76"/>
       <bindingRedirect oldVersion="0.5" newVersion="1.0"/>
     </dependentAssembly>
    </assemblyBinding>
   </runtime>
   ........
</configuration>
Robert Durgin
No, it's the same version. The gac is completely cleaned out before I build the solution (to avoid any confusions). Also, the only version of the libraries is 1.0.0.0.
Benson
+1  A: 

Try updating the IIS web app web.config that with the following

<compilation debug="true">
      <assemblies>
        <add assembly="MyWcfAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=AAAAAAAAAA"/>

From my experience this is needed sometimes when the dll isn't copied local and needs to be read from the GAC.

You also need to reload your app domain for your web page to use the latest assembly installed into your GAC. You can reload your app domain by doing an iisreset, touching the web.config or iis manager.

Ryu
A: 

We have sometimes experiance caching problems. The system has previously tried to access something from the GAC, it was not there, it remebers that, next time it does not bother to check.

Try doing an IIS reset after you add the assembilies to the GAC.

Also it is not enough that the version matches the public key token must also match.

Shiraz Bhaiji
A: 

One thing you could try is using the fully qualified assembly name of your service. It is my understanding that when dealing to the GAC, that's the only way to go.

Apart from that, you could enable Fusion logs to see from where is your application try to load the assembly from, and why its'failing. Scott Hanselman has a pretty good tutorial on how to use them.

Ramiro Berrelleza