Reputation: 3033
I am following the documentation here Setting Up for Microsoft C# Development and at this step Building the C# vSphere DLLs I get the following in Developer Command Prompt:
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin>build.bat
1 file(s) copied.
Fixing HttpNfcLeaseInfo type, adding missing leaseState property
Generating VimService.cs
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
Copyright (c) Microsoft Corporation. All rights reserved.
Generating files...
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin\VimService.cs
Compiling original VimService.dll
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.6.1055.0]
Copyright (c) Microsoft Corporation. All rights reserved.
Generating XML serializers...
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin\VimServiceSerializers.cs
1 file(s) copied.
Optimizing VimService.cs by stripping serializer hint attributes.
Compiling optimized VimService.dll
FAILED
Looking at build.bat
it looks like it is failing on this line:
echo Compiling optimized VimService.dll
csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs >nul || goto ERROR
If I run csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs
manually i get the following:
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin>csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs
Microsoft (R) Visual C# Compiler version 1.3.1.60616
Copyright (C) Microsoft Corporation. All rights reserved.
VimServiceSerializers.cs(32548,98): error CS8078: An expression is too long or complex to compile
I also tried with VS2017:
C:\Users\user\Downloads\VMware-vSphereSDK-6.5.0-4571253\SDK\vsphere-ws\dotnet\bin>csc /t:library /out:Vim25Service.dll VimService.cs VimServiceSerializers.cs
Microsoft (R) Visual C# Compiler version 2.0.0.61213
Copyright (C) Microsoft Corporation. All rights reserved.
VimServiceSerializers.cs(31372,109): error CS8078: An expression is too long or complex to compile
A behavior to note, on VimServiceSerializers.cs(#####,##)
the line and column are different every time.
Googling error CS8078, found it is an issue with the compiler running out of stack space. https://stackoverflow.com/a/8160109/6656422
How do I successfully compile VmWare's code?
Upvotes: 5
Views: 1446
Reputation: 416
Even now with the latest version of vSphere 8 this is a problem.
The best way to do this is to generate the DLL without the serialization assembly (which compiles quickly) and then generate the serialization assembly separately using sgen.exe.
sgen.exe takes ages to run but because it's running outside of the development evenvironment it does complete successfully.
It's quite faffy but fine when it's all completed - I've documented the whole process here:
https://david-homer.blogspot.com/2024/11/solved-compile-vsphere-management-sdk.html
Upvotes: 0
Reputation: 4020
The answer given by splitting the if ...else into individual if statements is one solution. The other option is to check the version of the C# compiler being used to compile the code. I have seen that the csc.exe bundled with .NET 4.5, 4.6 can compile such code without generating any errors. But the Roslyn .NET compiler fails to compile such code and generates CS8078 errors. So if you don't want to modify the code the other option is to change the C# compiler. For example the below csc.exe can compile such code -
C:\Windows\Microsoft.NET\Framework\v4.0.30319>csc.exe /version
Microsoft (R) Visual C# Compiler version 4.6.1055.0
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.
Upvotes: 2
Reputation: 46628
I figured it out. The serializer CS file has long uninterrupted stretches of if ... else if ... else if ...
clauses. The compiler has to deal with the whole if/else expression at once, which causes it to run out of stack space.
Fortunately, each branch in these else if
s terminates with a return
statement. This makes all the else if
s functionally equivalent to just independent if
statements, which are parsed independently.
After making this substitution in a number of places, the file compiles. Here's my modified VimServiceSerializers.cs: https://1drv.ms/u/s!Al6mzY0CpY7EnHqBRDyg-z0ctrjk
Upvotes: 3