Thursday, March 31, 2011

Switching to Release Build causes runtime error in Web Reference

I've got a problem with a SOAP Web Reference that was generated by Visual Studio 2005 (.NET framework is v2.0.50727.42) - it works fine under the Debug build configuration (and has for months) but now that I want to go live and have compiled using the Release configuration, it has stopped working.

Exceptions are raised at runtime whenever I call a method on the Web Reference. The most common exception is:

System.InvalidOperationException: There was an error generating the XML document. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'MayriseWebServices.RefuseService.PremiseSummaryStructure'  Key being added: 'MayriseWebServices.RefuseService.PremiseSummaryStructure'

The language for the project and the generated Web Reference is VB.NET rather than C#. As the generated Reference.vb code doesn't actually change, just the build type, I can't find anything there, and I obviously can't debug the Release build.

I've noticed that the Release build splits off a *.XmlSerializers.dll assembly from the main build. Are there known problems with this?

I'd rather not go live with the Debug build for obvious reasons. Maybe I should do some reading about CodeDOM, I have been meaning to!

I should mention that I've found a post with reasons why a Release build will run differently but it seems to be focused on C++.

Thanks for any help you can give.

UPDATE: The third suggestion to turn off the serialization assemblies has fixed the problem. I changed the "Generate serialization assemblies" setting from "Auto" to "Off" in the Advanced Compile Options, and my tests pass now. I wasn't aware of that setting.

I'm not sure what the underlying problem with the serialization assemblies is. I'll provide an update if I get a chance to debug the Release assembly using your advice in the second suggestion.

From stackoverflow
  • I do not have an answer for you, though I have some thoughts on how to troubleshoot this issue.

    1. Since this is a runtime error that only occurs with a RELEASE build, not a DEBUG build, I am wondering whether the VB compiler emits the same IL or not. What you might want to do is compile your DEBUG version of the assembly, then compile the RELEASE version of the assembly. Once you have both a DEBUG and RELEASE version of the assembly, use ILDASM.exe to perform a dissassembly of both assemblies. Save the files as text and use WinDiff.exe to compare them. This may or may not provide you with some clues.
    2. You may want to alter your project settings for the RELEASE configuration to generate the PDBs (/debug:pdbonly). This will allow you to debug as long as you start the process from within Visual Studio.
    3. The *.XmlSerializers.dll assemblies that are generated are intended to improve the initial calls that cause serialization to occur. As a troubleshooting step, you can turn that off in the RELEASE configuration of your project properties to see whether or not you still have the same issue.

    I hope this helps.

0 comments:

Post a Comment