3

I'm using the following command, but it's not working:

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin>xsd /c /l:cs SubsystemReg.cs

Lets say this is my Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PaymentControllerGUI
{
    public class EmptyClass
    {
    }
}

and I'm trying this.

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin>xsd /c /l:cs EmptyClass.cs

Error:

invalid command line argument: 'SubsystemReg.cs'

Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
user3264676
  • 253
  • 5
  • 8
  • 20

1 Answers1

8

Using the XSD.exe, you should pass the DLL file path which your class is compiled in, instead of the CS class code file itself as you pass now.

For instance, if your class is compiled in SubsystemReg.dll, call XSD.exe like that:

XSD.exe C:\SubsystemReg.dll

Here is an example from MSDN:

The following command generates XML schemas for all types in the assembly myAssembly.dll and saves them as schema0.xsd in the current directory.

xsd myAssembly.dll  

UPDATE:

You can generate XSD from DLL for a specific type by specifying the fully-qualified path of the Type, for example:

xsd.exe YourAssembly.dll /type:YourNamespace.YourType

Per your case, just do:

xsd.exe PaymentControllerGUI.dll /type:PaymentControllerGUI.EmptyClass
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
  • I don't have dll file. This file is part of my project. I just copied it to this location and trying. – user3264676 Mar 05 '14 at 08:37
  • No problem, you can specify the required type to be generate as XSD. See my update. – Yair Nevet Mar 05 '14 at 08:40
  • I didn't understand your solution. As I'm saying I don't have dll file. – user3264676 Mar 05 '14 at 09:41
  • 1
    So you **must** have one in order to achieve what you want. Otherwise, no way to do it with `XSD.EXE`. – Yair Nevet Mar 05 '14 at 09:50
  • I assume that you are working with Visual Studio, so just compile your project, take the DLL from the BIN folder and use it as I suggest in my answer. – Yair Nevet Mar 05 '14 at 09:54
  • Tried already, not working C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin>xsd PaymentControllerGUI.dll /type:PaymentControllerGUI.SubsystemReg.cs PaymentControllerGUI is namespace and type is SubsystemReg.cs. is this correct ?? – user3264676 Mar 05 '14 at 09:57
  • 2
    No, don't do it like that. This is the convention: `xsd.exe YourAssembly.dll /type:YourNamespace.YourType` – Yair Nevet Mar 05 '14 at 09:58
  • what should I write in place of YouNamespace.YourType? – user3264676 Mar 05 '14 at 10:04
  • Dude, are you doing time pass? If you dont know please dont waste time. I have already tried this. getting error. Error: Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin\PaymentControllerGUI.dll' or one of its dependencies. Th is assembly is built by a runtime newer than the currently loaded runtime and ca nnot be loaded. – user3264676 Mar 05 '14 at 10:26
  • You are trying to open your dll from the VS folder!! – Yair Nevet Mar 05 '14 at 11:05
  • I have copied cs file and dll file to different location. then trying – user3264676 Mar 05 '14 at 11:39
  • You don't need .cs files – Yair Nevet Mar 05 '14 at 12:17
  • I don't know how you are doing but I'm not able to generate it. :( – user3264676 Mar 05 '14 at 19:35
  • @YairNevet I salute your patience. – Asad Saeeduddin Feb 23 '17 at 23:04
  • @YairNevet, just found this years later. I'm trying to do what you're saying. Using command prompt, cd to Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\, then enter this: xsd.exe "C:\MyProjects\Dev\Source\eFI\SCC.WebAPI\bin\SCC.WebAPI.dll" /type:SCC.WebAPI.Models.transactions Getting an error the dll is not of correct type: Could not load file or assembly, An attempt was made to load a program with an incorrect format. CAN I USE MY dll for the visual studio project where my class is defined? Or do I need a separate project with just the classes? Thanks – Debbie A Nov 13 '20 at 14:27
  • 1
    Oh, I just figured it out. There's a 32-bit and a 64-bit version of the xsd.exe. Had to change directory to C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\x64 and it worked!!!! My Visual Studio Project's dll is 6-bit – Debbie A Nov 13 '20 at 14:49
  • 1
    @DebbieA great, I'm glad to hear. Please upvote if it helps as you described. – Yair Nevet Nov 13 '20 at 22:51