sgen fails when solution platform is x64

Hi - hope someone can help with this one.

I have a project written in C# running under .Net 2.0 that contains some web services and client interfaces that make use of those web services via standard web references.
I have today added an x64 platform to build the solution for an x64 test server, however the client interface assemblies will not build due a failure running sgen to generate the xml serialization assemblies.

Here is the sgen output:

C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\sgen.exe /assembly:"S:\xyz\obj\x64\Release\xyz.dll" /proxytypes /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /compiler:/delaysign-
Error: An attempt was made to load an assembly with an incorrect format: S:\abc\bin\x64\Release\abc.dll.
- Could not load file or assembly 'file:///S:\abc\bin\x64\Release\abc.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1892,9): error MSB6006: "sgen.exe" exited with code 1.
Done building project "xyz.csproj" -- FAILED.

Everything builds and runs ok when the platform is AnyCPU, but x64 platform will not work.

I am performing the build on a 32bit machine - is there a problem running agen on a 32 bit machine when trying t build a solution for a 64 bit one? Hopefully not, cos everything else is ok.
I'm stuck - any suggestions would be gratefully received.

cheers
Mark

[1848 byte] By [MarkBennetts] at [2008-1-10]
# 1

Mark,

You may see this problem because you are not building against the 64bits version of the CLR framework. Try using C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727 for your reference CLR path. This assumes you have this version installed already.

Does this help?

-Chris

ChristopherScrosati-MSFT at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 2

Actually, you should be able to generate 64bits CLR from a 32bits machine without the previous requirements I stated.

Error MSB6006 is kind of generic, you might want to activate a more verbose project build output. This will help you trace this more efficiently. To do this in VS2005:

Open Tools menu, select "Options..."

Expand "Projects and Solutions"

Select "Build and Run"

The last option is "MSBuild project build output verbosity:". Select Detailed.

Rebuild your project. You should get more info about the error you are getting.

Hopefully, this will get you unblocked. Can you post what is the result? This should be useful for other people doing cross-platform dev.

Thanks,

-Chris

ChristopherScrosati-MSFT at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 3
Thanks for the response Chris.

I upped the output verbosity, but it isnt really much more help, and like you say in your previous post, I should be able to build a x64 assembly from a x86 machine. I'm not even sure if I can install the x64 version of the clr or sdk on it even.

Anyway - here are the more verbose build outputs relating to the sgen error (names/paths changed). The crux of the problem seems to be the "incorrect format" error while loading one of the other referenced assemblies from the same solution.

Target GenerateSerializationAssemblies:
Building target "GenerateSerializationAssemblies" completely.
Output file "obj\x64\Release\xyz.XmlSerializers.dll" does not exist.
Using "SGen" task from assembly "Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "SGen"
Command:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\sgen.exe /assembly:"xyz\obj\x64\Release\xyz.dll" /proxytypes /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /compiler:/delaysign-
The "SGen" task is using "sgen.exe" from "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin\sgen.exe".
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: An attempt was made to load an assembly with an incorrect format: abc\bin\x64\Release\abc.dll.
- Could not load file or assembly 'file:///abc\bin\x64\Release\abc.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

If you would like more help, please type "sgen /?".
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(1892,9): error MSB6006: "sgen.exe" exited with code 1.
Done executing task "SGen" -- FAILED.
Done building target "GenerateSerializationAssemblies" in project "xyz.csproj" -- FAILED.

Thanks again
Mark

MarkBennetts at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 4

There is indeed a missing dependency by the look of it.

I see this in your output:

Building target "GenerateSerializationAssemblies" completely.
Output file "obj\x64\Release\xyz.XmlSerializers.dll" does not exist.

Can you try the following?

Right-click your project, go into Properties

Select the Build tab

Last option is "Generate serialization assembly". Set this to Off.

This will disable the generation of the projectName.XmlSerializers.dll. The counterpoint to this is that at run-time, your app will probably be less performant on the first access since these serializers will be generated dynamically instead of at compile time.

I will try to dig around and find another solution for you.

Does this work?

-Chris

ChristopherScrosati-MSFT at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 5
Hi Chris,

The missing output file is the one thats supposed to be generated by sgen - i'm asuming the message that it does not exist is just information that the existing one could not be deleted prior to generating a new one - but I'm just guessing here.

Anyway, I disabled the serialization assembly generation and it does indeed compile now. So as long as the assemblies are generated on the target machine as you suggest then that will be fine. The web service "clients" are both services, so I can always make a dummy web service call at startup time to ensure the serialization assemblies have been generated to avoid the time "hit" later on when a real call is made for operational work.

One thing I didnt notice before as I was concentrating efforts on sgen problems was that the actual web service Host project is not building correctly (which I guess could be causing the sgen problem too).
Heres the output:

Validating Web Site
(0): Build (web): Could not load file or assembly 'Dummy' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I've looked and looked, and all project references look correct in the solution. The web service implementation assembly builds ok, its just the host project that has the asmx file in it. Ive tried clearing the bin folder and rebuilding but still get the same problem. I changed the "Dummy" assemblies version, and it gets correctly copied to the Host projects bin file too. Again this works ok in (Any CPU) platform build, just fails on x64.

Thanks
Mark

MarkBennetts at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 6
Hi Chris - have been doing some further experimenting, and found something interesting.

I created a new project from scratch with basically no code in it and I get the same issue.

Here is what I did:

1) Create empty solution
2) Add new Web Site from popup menu (select ASMX web service), using File System as the location
2) Add new class library project
3) Add Reference from web service to the other class library
4) build solution

The Host project (web service) fails to build saying :

Build started: Project: S:\...\Testx64.Host\, Configuration: Debug .NET
Validating Web Site
Building directory '/Testx64.Host/App_Code/'.
(0): Build (web): Could not load file or assembly 'Testx64.DependentDummyx64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Validation Complete

Now if I add another web service project to the solution, but add it using the Add->New Project from the popup menu rather than the Add->New Web site, and add the same dummy project reference to it, this one builds ok. Its only the web service that is structured with the AppData, AppCode and Bin folders (ie hasnt got a project file) that fails to build correctly.

Really confusing!

Regards
Mark.

MarkBennetts at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...
# 7
OK Me again!

I can see whats happening now - running file monitor from Sys Internals when building the Web service its attempting to load the dependant assembly from the bin\Release folder instead of the x64\bin\release.

ie it would seem that as it hasnt got a project file telling it any details about the build configurations etc it just uses the default path. Also why when looking at the Build configuration manger its only showing .NET as the available platform for the web service rather than x64 as with all the others.

Any clues as to how to fix this would be appreciated.

One option I guess would be to convert the web service project type to the old project file based ones like in Studio 2003, but I'm reluctant to do this as we are using the pattern and practices Service software factory automation extensions to support our development of this project.

regards
Mark

MarkBennetts at 2007-10-3 > top of Msdn Tech,.NET Development,ASMX Web Services and XML Serialization...

.NET Development

Site Classified