Svcutil.exe for .NET 4.0?

2019-03-08 13:32发布

问题:

I was trying to use svcutil.exe to generate proxy classes for a service but when I use the /reference option to reference an assembly that is built for .NET 4.0 I get an error.

Could not load file or assembly [...] or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

So it seems that I am using an old version of svcutil.exe. I am using the one in "C:\Program Files\Microsoft SDKs\Windows\v7.0A which was the latest one I could find. Is there a later version somewhere that I am supposed to use?

回答1:

I had the same issue. If your project is set to use the .NET 4.0 Framework, you must choose the right version of SvcUtil.exe, or it will throw an error: "Could not load..."

  • If you look in "Microsoft SDKs\Windows\v6.0A\Bin", you will see that the version of that exe is "3.0.4506.2152".
  • The version of SvcUtil.exe in "Microsoft SDKs\Windows\v7.0A\Bin" is exactly the same, so it threw me for a loop as well.

However, there is another version of SvcUtil.exe located in "Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools" which is version "4.0.30319.1", and if you use it, everything should work.



回答2:

The latest version of the SDK for .Net 4.0 is available at

http://msdn.microsoft.com/en-us/windows/bb980924.aspx

svcutil.exe which resides in v7.1/bin has version 3.0.4506.2152.

svcutil.exe which resides in v7.1/bin/NETFX 4.0 Tools has version 4.0.30319.1.



回答3:

According to this link for .Net 4.0 you should use one in C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin.

http://msdn.microsoft.com/en-us/library/aa347733.aspx

Seems a little strange though, if the one in the v7.0A dir is too old.



回答4:

Why not rebuild as .NET 3.5 to generate the classes? I suspect the types you're generating classes for don't rely on any .NET 4.0 functionality. The cs files won't care what version the DLL was built for so you can use them in a 4.0 project just fine.



回答5:

I'm having the same problem.

Microsoft says that you can only use .Net 4 DLLs with the new SvcUtil that comes wit the latest version of .Net (http://msdn.microsoft.com/en-us/library/aa347733.aspx) but that version seems to be the one you are mentioning above. It won't access .Net 4 DLLs as references at all.



回答6:

Answering my own question. The new version of svcutil will probably come with v7.1 of the Windows SDK that is released in mid-June.



回答7:

Update: Newest version of util is not v7.0 as per:

Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

SvcUtil.exe v8.0A is now available after installing Visual Studio 2012 (VS 2012)

"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\SvcUtil.exe"

What you really want is the full definition for turning a WSDL file into a service client:

/n:*,MyCompany.Services.Client /out:IServiceInterface.cs ServiceDefinition.wsdl.xml

Where service definition.wsdl is obviously the ?wsdl response from any old soap endpoint.

Minions and Trolls remember! Everything is now Async so look for and take advantage of the new Async support generated by v8.0 of SVCUtil.exe