I found a simple test template on the web to get started learning C# / .NET but I have run in to a few errors when I try to execute the program.
"An unhandled exception of type 'System.UriFormatException' occurred in System.dll
Additional information: Invalid URI: The format of the URI could not be determined."
If fails at ServiceContent sc = c.Connect("server01.dom1"); in VS2013.
Here is the full exception detail:
Can anyone help me with what I have wrong with my syntax?
"An unhandled exception of type 'System.UriFormatException' occurred in System.dll
Additional information: Invalid URI: The format of the URI could not be determined."
If fails at ServiceContent sc = c.Connect("server01.dom1"); in VS2013.
C#:
[COLOR=#0B374D][FONT=Courier]using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using VMware.Vim;namespace vmwaretest{ class Program { static void Main(string[] args) { VimClient c = new VimClient(); ServiceContent sc = c.Connect("server01.dom1"); UserSession us = c.Login("xxxxxx", "xxxxxxx"); IList<VMware.Vim.EntityViewBase> vms = c.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, null, null); foreach (VMware.Vim.EntityViewBase tmp in vms) { VMware.Vim.VirtualMachine vm = (VMware.Vim.VirtualMachine)tmp; Console.WriteLine((bool)(vm.Guest.GuestState.Equals("running") ? true : false)); Console.WriteLine(new Uri(vm.Guest.IpAddress != null ? vm.Guest.IpAddress : "0.0.0.0")); Console.WriteLine((string)vm.Client.ServiceUrl); Console.WriteLine(vm.Guest.HostName != null ? (string)vm.Guest.HostName : ""); Console.WriteLine("----------------"); } } }}
[/FONT][/COLOR]
Here is the full exception detail:
C#:
[COLOR=#0B374D][FONT=Courier]System.UriFormatException was unhandled HResult=-2146233033 Message=Invalid URI: The format of the URI could not be determined. Source=System StackTrace: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at VMware.Vim.VersionUtils.GetVIServerSupportedVersions(String serviceUrl) at VMware.Vim.VersionUtils.GetVIServerVersion(String serviceUrl) at VMware.Vim.VimClient.Connect() at VMware.Vim.VimClient.Connect(String serviceUrl) at vmwaretest.Program.Main(String[] args) in c:\Users\Administrator\Documents\Visual Studio 2013\Projects\vmwaretest\vmwaretest\Program.cs:line 15 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
[/FONT][/COLOR]
Can anyone help me with what I have wrong with my syntax?