Search code examples
c#sgen

SGEN.exe - Microsoft.Xml namespace not found


I have a strange issue with my generated serialization .dll. The .dll is successfully generated I can reference it in my project, all the types are contained within the namespace Microsoft.Xml.Serialization.GeneratedAssembly as expected, even the intellisense is picking up the types and namespaces. But when I go to build the project referencing any of the types within the generated assembly I get an error along the lines of:

Error 2 The type or namespace name 'Xml' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Rather odd, no? The namespace clearly exists as far as intellisense is concerned and I've never had an issue like this before. I tried to regenerate the assembly, still the same problem.

For now I have run sgen.exe with the flag /keep and just copied the generated source into my project which is fine. I was just curious if there was a way to fix this issue or if anyone else has ever come across it before.

EDIT:

It turns out that the issue is because the generated assembly is targeting a version of the .NET framework greater than the assembly that is referencing it. Now the question becomes - how do I generate a serialization assembly with Sgen that targets a specific .NET framework version.


Solution

  • Ok so after reading the answer on this question I managed to generate a serialization assembly that has the correct "runtime version" for .NET 3.5 and everything works as expected, sorry for wasting time.