The name 'DeviceId' Does not exist in the current context on Main Program CSharp file.
using Microsoft.Azure.Devices.Client;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceClientApplication
{
class Program
{
private static string s_connectionString = Environment.GetEnvironmentVariable("IOTHUB_CONN_STRING_CSharp");
private static TransportType s_transportType = TransportType.Amqp;
public static int Main(string[] args)
{
if(args.Length < 1)
{
Console.WriteLine("\nUsage:\n");
Console.WriteLine("\tServiceClientApplication <deviceID> [connectionString]\n");
return 1;
}
if(string.IsNullOrEmpty(s_connectionString) && args.Length > 1)
{
s_connectionString = args[1];
}
ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType);
var sample = new ServiceClient(serviceClient);
sample.RunSampleAsync(deviceId).GetAwaiter().GetResult();
Console.WriteLine("Done.\n");
return 0;
}
}
}
ServiceClient.cs file has the following methods.
using Microsoft.Azure.Devices.Client;
using System;
using System.Text;
using System.Threading.Tasks;
namespace ServiceClientApplication
{
public class ServiceClient
{
private readonly ServiceClient serviceClient;
public ServiceClient(ServiceClient serviceClient)
{
serviceClient = serviceClient ?? throw new ArgumentNullException(nameof(serviceClient));
}
public async Task RunSampleAsync(string deviceId)
{
var str = "Testing eNtsa Project";
var message = new Message(Encoding.ASCII.GetBytes(str));
await serviceClient.SendAsync(deviceId, message).ConfigureAwait(false);
}
private Task SendAsync(string deviceId, object message)
{
throw new NotImplementedException();
}
internal static ServiceClient CreateFromConnectionString(string s_connectionString, TransportType s_transportType)
{
throw new NotImplementedException();
}
}
}
What am imissing here exactly? deviceId on method RunSampleAsync(string deviceId), so how does this string object be outside method definition? How do i fix this error from that line of ; sample.RunSampleAsync(deviceId).GetAwaiter().GetResult();?