2

I am generating an xmlserializer dll for my service. It is a big webservice - the build takes about 2 minutes.

To reduce the build time, I separated out the build of the xmlserializer into a separate Makefile project - given that the interface isn't changing, I thought I could compile it once, and that would be it.

But, what I have found, if I recompile the service, the xmlserializer is not longer used and the serializer code is being generated at run time.

Has anyone seen this? Is there a work around? What may be causing the xmlserializer to no longer match service assembly?

Thanks.

Update:

Ok, I've found half the answer...

https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializerversionattribute(v=vs.110).aspx

Describes the XmlSerializerVersionAttribute (which is in the generated .cs code).

The document says...

If the infrastructure finds an assembly with a matching name, the assembly is loaded and the infrastructure checks XmlSerializerVersionAttribute for a match between the found assembly's version and the current version of the parent assembly. If the version does not match, the found assembly is not used. Instead, a temporary assembly is generated for the serialization.

Looking in the .Net Framework source code shows that the ParentAssemblyId is actually the module version id, ie

Assembly.GetExecutingAssembly().GetModules()[0].ModuleVersionId

However, if I load the xmlserializer assembly manually, and change the ParentAssemblyId field on the attribute, it still doesn't work - I'm guessing the framework loads its own copy of the serializer assembly.

Frank
  • 81
  • 5

1 Answers1

0

I ended up adding a post build step to change the module id of the assembly (in a debug build).

I tried fody.MVID (as described here can-i-specify-the-module-version-id-mvid-when-building-a-net-assembly ), but I couldn't get it to work (version mismatches).

In the end I used the code in this blog post - https://blogs.msdn.microsoft.com/johnls/2005/08/13/changing-mvids/

Frank
  • 81
  • 5