2.0 Web Service Problem with 1.1 Assembly Redirections (I challenge you)

This is a problem I have been trying to resolve for over three weeks now with no success. I shall try to explain the problem as clearly as I can as it can get very confusing.

I have a Visual Studio 2005 .NET 2.0 Web Service Project which has a single web service class called HelloService. This service has the following content:

        private Service.Service service = new Service.Service();

        
[WebMethod]
        
public string HelloWorld()
        {
            
return this.service.GetMessage();
        
}

 As you can probably see there is a Service declared at the top - this is a Visual Studio .NET 2005 Class Library with a single class called Service that has the following content:

        Engine.Engine engine = new Engine.Engine();

        public string 
GetMessage()
        {
            
return this.engine.GetMessage();
        
}

We now have an Engine class, this is a Visual Studio .NET 2003 Class Library with a single method with the following signature:

        public string GetMessage()
        {
            
return "Hello, world!";
        
}

As you can see we have a very simple hierarchy: the web service calls GetMessage() on Service that then calls GetMessage() on Engine which return the string "Hello, world!"

This is where it gets complicated, all the projects are compiled with strong names, and are deployed. The project Web Service and Service are compiled as version 1.0.0.0, the Engine is compiled as 1.0.1.0.

If we invoke the web service and invoke the HelloWorld method we indeed get the correct response, "Hello, world!".
If I change the Engine version to 1.0.2.0 and recompile (making sure I do not recompile the Web Service or Service project) placing the output into the Web Service bin directory I then get a TypeLoadException, this is off course what I would expect. The Service class is being invoked and is trying to load the 1.0.1.0 assembly and since they are all strongly named it will not load the new version as they differ.

I put assembly redirections into the web.config redirecting the Engine.dll so that if 1.0.1.0 is requested to use the 1.0.2.0 version instead as below:

    <runtime>
        
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            
<dependentAssembly>
                
<assemblyIdentity name="Engine" publicKeyToken="91e1bed8f28f6600">
                    
<bindingRedirect oldVersion="1.0.1.0" newVersion="1.0.2.0" />
                </
assemblyIdentity>
            
</dependentAssembly>
        
</assemblyBinding>
    
</runtime>

On invoking the Web Service HelloWorld method again I expect to see my message, but I do not, instead I receive the dreaded TypeLoadException again.

So my challenge to you all is I must have this working and cannot for the life of me figure out how to make it work. Changing Machine.config had limited success, after restarting IIS the previous behaviour started to show. I know that this maybe a problem with the framework but I need to figure out a workaround.

If anyone is interested in trying to figure this one out then the source for the projects can be found here. 

 

2 Comments

  • Agreed the documentation does state that the bindingRedirect should be a sibling but in this example it makes little difference in solving the problem. You still receive the dreaded System.IO.FileLoadException: Could not load file or assembly 'Engine, Version=1.0.1.0, Culture=neutral, PublicKeyToken=319e0b36fe7c5768' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
    at Service.Service..ctor()
    at WebService.HelloService..ctor()

    Thanks for your comment.

  • Russell, you are a life saver! We were having the same problem and your hint about the namespace saved us after messing around with this problem for hours.

    Cheers,

    Symon.

Comments have been disabled for this content.