Help with Console App and Using being ignored

Hotpuppy

New member
Joined
Jun 17, 2017
Messages
4
Programming Experience
10+
Hi,
I'm reasonably new to C# and Visual Studio. I'm stumped on a problem and hoping someone else can point me in the right direction.

I have a console application that I wrote to retrieve data from a vendor system via a primitive Web API (IBM's flavor of XML) and write it to my system's database (via SQL calls). The app works well and does what it should. It's a bit slow, but it works, updating 16,000 products in about 3 hours. Each product can be in multiple websites and there is some business logic being applied to maintain the data in my system.

I've recently upgraded to a new computer and had to reinstall Visual Studio. I'm running 2017 Community edition. I'm an Army of One, need to be thrifty as I'm a startup and Community does everything I need it to. I don't think this is the issue, but I'm including it here just in case.

I'm trying to add some code to my console application that will send me a status email via SendGrid's API. I'm following their example here: https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/csharp.html

I've installed the package via NuGet.

The problem is that Visual Studio is ignoring my using statements. They remain dimmed out and when I try to build it complains that I don't have the SendGrid namespace defined. When I comment out the using statements and the sendgrid code it works fine. Before I give up and send via SMTP I'd like to see if I can solve the problem and learn something.

The Sendgrid helpers using is staying active, but the others are indicating that the namespace isn't being used.

For a variety of reasons I'm not including all of my code. Here is the pertinent parts that should execute Sendgrid and send me a status email:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Globalization;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http;
using System.Net.Mail;
using SendGrid;
using SendGrid.Helpers.Mail;


           var myMessage = new SendGridMessage();
            myMessage.AddTo("me@me.com");
            myMessage.From("faithful@system.com");
            myMessage.Subject("Vendor Inventory Complete " + howmany + "records");
            myMessage.Text("Run Time: " + elapsedtime);
            var transportweb = new SendGrid.Web("shhh!Secret");
            transportweb.DeliverAsync(myMessage).Wait();



I'm also getting a compile error "SendGridMessage .Subject cannot be used like a method. Along with a bunch of similar failures and a prompt about if I am missing a directive.

This is really frustrating as it's a pretty simple example and I've copied it exactly. What am I missing?
 
Last edited by a moderator:
It appears to be two different libraries, your example and link is for Nugets "SendGrid.Net40 v5.1", but the Github link on that page is for another library available on Nuget as "SendGrid v9.4.1" and the code examples are different using a SendGridClient and not SendGrid.Web. Here are code examples for the library you have installed:
GitHub - sendgrid/sendgrid-csharp: Official C# Client Library for the SendGrid Web API

From/Subject/Text are properties by the way, not methods, there are examples for both libraries on setting those.
 
Thank you. I guess that should have been something obvious for me to check. I really appreciate your help on this and will try to remember that in the future. I had expected that the example of SendGrid's product on their website would actually work. This seems to be a really common problem with platforms like SendGrid, EasyPost etc. It compounds the challenge of learning their tools when the examples don't work.
 
I've opened a ticket with Sendgrid to get their example updated. In the meanwhile I'll look at the examples on Git and see if I can make sense of them. Thanks again for taking the time to help me out. I'm really glad I found this forum. There is alot of information on another forum/site but the crowd there seems hostile to newbies. That is a shame because we all should strive to help each other out. That is the soul of the internet and what makes it magical.
 
I had expected that the example of SendGrid's product on their website would actually work.
It should work with their library "SendGrid.Net40 v5.1" from Nuget.
 
They came back and agreed that the documentation is out of date and asked me to use v3 of the API . so I'm going to explore that.
 
Back
Top Bottom