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:
[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:
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:
{
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:
<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.