views:

712

answers:

6

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?

A: 

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.

ho1
I checked and they are both the same version, 3.0.4506.2152, so I get the same error trying that one.
D.H.
Try this instead maybe: http://stackoverflow.com/questions/896629/how-to-run-clr-2-application-as-clr-4-application
ho1
A: 

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.

nedruod
I want to run svcutil as a build event so that means always having my referenced assembly compiled as .Net 3.5. It works for now since there is no 4.0 functionality in there yet, but I want to be able to add it later. I am still interested in finding the actual reason for my problem. Is there no version of svcutil available that supports .Net 4? Will there be?
D.H.
I'll mark this as the accepted answer since it is an acceptable work-around for now. Still interested in more answers though.
D.H.
A: 

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.

Chris
A: 

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.

D.H.
+4  A: 

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.

Boris
Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools is the correct answer. Thanks!
Mark
A: 

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.

Sharken