XSD.EXE to generate F# Classes off of XSD


I am trying to use the tool XSD.EXE to generate some class files from an XSD. Whether there is anything to be gained from the resulting files is another question, but I would like to see what is generated. I found this reference, which notes:

Which, thanks to Luke over on the F# Visual Studio team, means I can do this:

xsd.exe fpml-asset-4-z.xsd /classes /l:”Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider, FSharp.Compiler.CodeDom, Version=, Culture=neutral, PublicKeyToken=a19089b1c74d0809″

Which is splendid. I don't have the same version of the code dom - so looking at the GAC I changed the line to:

xsd.exe RIXML-datatypes-2_3_1.xsd /classes /l:"Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider, FSharp.Compiler.CodeDom, Version=2.0.0,0, Culture=neutral, PublicKeyToken=a19089b1c74d0809"

Which yields:

C:\Users\Desktop\CSharpSamples\ResearchUploader\Fc-RixmlLib>xsd.exe RIXML-datatypes-2_3_1.xsd /classes /l:"Microsoft.FSharp.Compiler.CodeDom.FSharpCodePr ovider, FSharp.Compiler.CodeDom, Version=2.0.0,0, Culture=neutral, PublicKeyToken=a19089b1c74d0809" Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved. Error: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

If you would like more help, please type "xsd /?".


asked on Stack Overflow Dec 1, 2010 by akaphenom

3 Answers


I had the same problem "Exception from HRESULT: 0x80131047" - did not manage to solve it but there is an ugly workaround:

  1. Create a new C# console application
  2. See this post for how to programatically do the same thing as xsd.exe
  3. Add reference to your F# powerpack's CodeDom dll
  4. Use Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider instead of CSharpCodeProvider

Spent an hour trying to get xsd.exe to work, and it took me only 5 mins to bruteforce it this way..

This could be easily made into xsdfs.exe or something to save people the trouble of making xsd.exe to use the f# code dom :)

answered on Stack Overflow Jan 4, 2013 by markolaban • edited May 23, 2017 by Community

That looks correct to me. Can you double check that the assembly is installed in GAC?
Here is a command that you can enter to "Visual Studio Command Prompt":

> gacutil -l | find "FSharp.Compiler.CodeDom"

I got:

FSharp.Compiler.CodeDom, Version=, Culture=neutral, 
PublicKeyToken=a19089b1c74d0809, processorArchitecture=MSIL
answered on Stack Overflow Dec 1, 2010 by Tomas Petricek

Leave off the Microsoft part, and after you installed to GAC, it should work. They changed names a while back.

I can, after installing (disassemble and assemble - ildasm, gacutil fun) use both xsd.exe and the in-editor C# method (rewriting to F#). Thanks :)

answered on Stack Overflow Jun 18, 2015 by Rob Jens

User contributions licensed under CC BY-SA 3.0