Dynamic web service proxies need to be loaded from disk

In our application we generate web service proxies at runtime itself using something similar to this. Initially we were generating the assembly in memory by using ICodeCompiler interface and setting CompilerParameters.GenerateInMemory to true. This works fine but throws an exception when you try to invoke a web service, the message of the exception goes something like “Unable to generate a serializer for type from assembly because the assembly may be dynamic. Save the assembly and load it from disk to use it with XmlSerialization.”, the only vagure reference to this issue is in this kb article http://support.microsoft.com/default.aspx?scid=kb;en-us;815251

It turns out that for use with XmlSerializer the assembly needs to be loaded from disk! So now we write the assembly to disk, load it using Assembly.LoadFrom() and invoke the web service using reflection. Works like a charm šŸ™‚

Leave a Reply