Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schema generation with xsd.exe

Tags:

xsd

I'm trying to generate a schema for some type from an assembly with xsd.exe

Here is the command line:

xsd.exe TestAssemby.dll /t:TestType

Here is the error I got:

Error: There was an error processing 'TestAssemby.dll'. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

I copied the referenced DLL file into a folder where it is located according to this.

But still I get the same error.

  • What can be the possible reasons for such an error?
  • How should the LoaderExceptions property be used? (An example will be very helpful.)
like image 543
lm. Avatar asked Jun 17 '10 18:06

lm.


People also ask

What is XSD EXE?

The XML Schema Definition (Xsd.exe) tool generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly.

Is XSD and schema same?

An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).


2 Answers

If your xsd.exe bails out with a type load exception for an existing project (part of your solution), you can run a debug session without writing any code to catch the exception and to inspect it.

Configure your debug session in this way: in the Project Properties of your project, on the Debug page, select Start external program.

Input the full path to the xsd.exe file, e.g.:

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools\x64\xsd.exe

In the Start options, specify the required command line arguments:

YourAssembly.dll /t:Your.Type

Go to the Exception Settings (menu DebugWindowsException Settings) and activate the System.Reflection.ReflectionTypeLoadException exception. You can indeed activate all CLR exceptions if you wish.

Now, press F5 to start the debug session.

The XSD console window should appear. Then, Visual Studio should break the process and show you the Exception Thrown popup. Here, you can inspect the type load exception.

You should also see the exception in the Locals window.

Actually, this should work for any assembly too. You just need a solution and a project to start a debugging session for. This can be even an empty solution/project.

like image 118
dymanoid Avatar answered Jan 07 '23 12:01

dymanoid


For myself, the answer in the end was pretty straightforward: I was missing dependent assemblies in the same folder. xsd.exe has to be able to load all dependent classes, etc. in order to build the XSD.

As a test to see if this is the case in your situation, you could create a new project in Visual Studio (or IDE of choice), and reference the assembly of the class you're generating an XSD for. Be sure to reference the specific library file that xsd.exe is using. If your newly created project can use it and see the class, then the dependencies are good and you can rule that out at least.

like image 22
DiskJunky Avatar answered Jan 07 '23 13:01

DiskJunky