title: Bing Ads API C# Example code not working
body: <p>I have tried running the C# example code and I receive the following error:</p>
  
  <blockquote>
    <p>Error code: InternalError &lt;0><br /> Message: An internal error has
    occurred.<br /> Detail: [this is blank]</p>
  </blockquote>
  
  <p>I have also tried implementing the reporting service in my own code, but have received a </p>
  
  <blockquote>
    <p>"Object reference not set to an instance of an object" error on this
    line:</p>
  </blockquote>
  
  <pre><code>response = reportingService.SubmitGenerateReport(request);
  </code></pre>
  
  <p>Here is my code, removed the ids/password/token:</p>
  
  <pre><code>using System;
  using System.ServiceModel;
  using System.Data;
  
  // BingAds.CampaignManagement is the application-defined namespace of 
  // the service reference used for this example. 
  
  using collectBingAdsData.BingAds.Reporting;
  using collectBingAdsData.BingAds.CampaignManagement;
  using collectBingAdsData.BingAds.Bulk;
  
  namespace collectBingAdsData
  {
      class Program
      {
          private static CampaignManagementServiceClient campaignManagementService = null;
          private static ReportingServiceClient reportingService = null;
          private static BulkServiceClient bulkService = null;
  
          private static DataTable BingSemData;
  
          // Specify your credentials.
  
          private static string m_password = "password";
          private static string m_username = "username";
          private static string m_token = "token";
  
          // Specify the advertiser's account ID and customer ID.
  
          private static long customerID = 123123;
          private static long[] accountIDs = { 123123 };
          private static long[] campaignIDs = { 123123 };
  
          private static string m_downloadPath = @"c:\reports\keywordperf.zip";
  
          // Shows how to request a keyword performance report and download it
          // to the specified folder.
          //
          // args[0] - Report ID. To download an existing report request instead 
          //           of requesting a new report, set args[0] to a report ID.
  
          static void Main(string[] args)
          {
              getAccountsByCutomer(customerID);
              foreach (long accountID in accountIDs)
              {
                  getCampaignsByAccount(accountID);
                  foreach (long campaignID in campaignIDs)
                  {
                      //getCampaignReport(accountID, campaignID);
                      getKeywordReport(accountID, campaignID);
                  }
              }
          }
  
          private static void getKeywordReport(long accountID, long campaignID)
          {
              KeywordPerformanceReportRequest request = new KeywordPerformanceReportRequest();
  
              request = buildKeywordPerformanceRequest(accountID, campaignID);
  
              string BingData = RequestReport(request);
          }
  
          private static void getCampaignReport(long accountID, long campaignID)
          {
              CampaignPerformanceReportRequest request = new CampaignPerformanceReportRequest();
  
              request = buildCampaignPerformanceRequest(accountID, campaignID);
  
              string BingData = RequestReport(request);
  
  
  
          }
  
          // Request the report. Use the ID that the request returns to
          // check for the completion of the report.
  
          static string RequestReport(ReportRequest report)
          {
              SubmitGenerateReportRequest request = new SubmitGenerateReportRequest();
              SubmitGenerateReportResponse response = new SubmitGenerateReportResponse();
  
              try
              {
                  // Set the header information.
  
                  request.DeveloperToken = m_token;
                  request.UserName = m_username;
                  request.Password = m_password;
  
                  // Set the request information.
  
                  request.ReportRequest = report;
  
                  response = reportingService.SubmitGenerateReport(request);
              }
              catch (FaultException&lt;collectBingAdsData.BingAds.Reporting.AdApiFaultDetail&gt; fault)
              {
                  // Log this fault.
  
                  Console.WriteLine("SubmitGenerateReport failed with the following faults:\n");
  
                  foreach (collectBingAdsData.BingAds.Reporting.AdApiError error in fault.Detail.Errors)
                  {
                      if (105 == error.Code) //  InvalidCredentials
                      {
                          Console.WriteLine("The specified credentials are not valid or the " +
                              "account is inactive.");
                      }
                      else
                      {
                          Console.WriteLine("Error code: {0} ({1})\nMessage: {2}\nDetail: {3}\n",
                              error.ErrorCode, error.Code, error.Message, error.Detail);
                      }
                  }
              }
              catch (FaultException&lt;collectBingAdsData.BingAds.Reporting.ApiFaultDetail&gt; fault)
              {
                  // Log this fault.
  
                  Console.WriteLine("SubmitGenerateReport failed with the following faults:\n");
  
                  foreach (collectBingAdsData.BingAds.Reporting.OperationError error in fault.Detail.OperationErrors)
                  {
                      switch (error.Code)
                      {
                          case 106: //  UserIsNotAuthorized
                              Console.WriteLine("The user is not authorized to call this operation.");
                              break;
  
                          case 2004: // ReportingServiceNoCompleteDataAvaliable
                              Console.WriteLine("The report cannot request complete data because " +
                                  "complete data is not available based on the specified " +
                                  "aggregation, scope, and time period values.");
                              break;
  
                          case 2007: // ReportingServiceInvalidReportAggregation
                              Console.WriteLine("The requested aggregation is not valid for the " +
                                  "specified reporting period.");
                              break;
  
                          case 2008: // ReportingServiceInvalidReportTimeSelection
                              Console.WriteLine("The report time period is not valid.");
                              break;
  
                          case 2009: // ReportingServiceInvalidCustomDateRangeStart
                              Console.WriteLine("The start date of the custom date range specified " +
                                  "in the report time period is not valid.");
                              break;
  
                          case 2010: // ReportingServiceInvalidCustomDateRangeEnd
                              Console.WriteLine("The end date of the custom date range specified " +
                                  "in the report time period is not valid.");
                              break;
  
                          case 2011: // ReportingServiceEndDateBeforeStartDate
                              Console.WriteLine("The end date of the custom date range specified " +
                                  "in the report time period cannot be earlier than the start date.");
                              break;
  
                          case 2015: // ReportingServiceRequiredColumnsNotSelected
                              Console.WriteLine("The report request does not include all of the " +
                                  "required columns.");
                              break;
  
                          case 2016: // ReportingServiceDuplicateColumns
                              Console.WriteLine("The list or report columns contains duplicate " +
                                  "columns. Please ensure that there is only one {0} column.",
                                  error.Details);
                              break;
  
                          case 2017: // ReportingServiceNoMeasureSelected
                              Console.WriteLine("The list or report columns must include one or " +
                                  "more KPI columns such as Clicks and Impressions.");
                              break;
  
                          case 2028: // ReportingServiceInvalidAccountThruAdGroupReportScope
                              Console.WriteLine("The report scope cannot be null or empty.");
                              break;
  
                          case 2034: // ReportingServiceInvalidTimePeriodColumnForSummaryReport
                              Console.WriteLine("When the report aggregation type is summary, " +
                                  "you cannot include TimePeriod as a report column.");
                              break;
  
                          default:
                              Console.WriteLine("Error code: {0} ({1})\nMessage: {2}\nDetail: {3}\n",
                                  error.ErrorCode, error.Code, error.Message, error.Details);
                              break;
                      }
                  }
  
                  foreach (collectBingAdsData.BingAds.Reporting.BatchError error in fault.Detail.BatchErrors)
                  {
                      Console.WriteLine("Error code: {0} ({1})\nIndex: {2}\nMessage: {3}\nDetail: {4}\n",
                          error.ErrorCode, error.Code, error.Index, error.Message, error.Details);
                  }
              }
  
              return (null == response) ? null : response.ReportRequestId;
          }
  
          private static CampaignPerformanceReportRequest buildCampaignPerformanceRequest(long accountID, long campaignID)
          {
              CampaignPerformanceReportRequest request = new CampaignPerformanceReportRequest();
              request.Aggregation = ReportAggregation.Daily;
  
              request.Columns = new[] { 
                  CampaignPerformanceReportColumn.AccountName, 
                  CampaignPerformanceReportColumn.Impressions, 
                  CampaignPerformanceReportColumn.Clicks, 
                  CampaignPerformanceReportColumn.Conversions, 
                  CampaignPerformanceReportColumn.ConversionRate
              };
  
              request.Format = ReportFormat.Csv;
  
              request.Scope = new AccountThroughCampaignReportScope()
              {
                  AccountIds = accountIDs,
                  Campaigns = new[] {
                      new CampaignReportScope {
                          CampaignId = campaignID,
                          ParentAccountId = accountID
  
                      }
                  }
              };
  
              request.Time = new ReportTime()
              {
                  PredefinedTime = ReportTimePeriod.Yesterday
              };
              return request;
          }
  
          private static KeywordPerformanceReportRequest buildKeywordPerformanceRequest(long accountID, long campaignID)
          {
              KeywordPerformanceReportRequest report = new KeywordPerformanceReportRequest();
  
              report.Format = ReportFormat.Xml;
              report.ReportName = "My Keyword Performance Report";
              report.ReturnOnlyCompleteData = true;
              report.Aggregation = ReportAggregation.Daily;
  
              report.Scope = new AccountThroughAdGroupReportScope()
              {
                  AccountIds = null,
                  AdGroups = null,
                  Campaigns = new[] {
                      new CampaignReportScope {
                          CampaignId = accountID,
                          ParentAccountId = campaignID
                      }
                  }
              };
  
              report.Time = new ReportTime()
              {
                  //CustomDateRangeStart = new Date()
                  //{
                  //    Month = 2,
                  //    Day = 1,
                  //    Year = 2012
                  //},
                  //CustomDateRangeEnd = new Date()
                  //{
                  //    Month = 2,
                  //    Day = 15,
                  //    Year = 2012
                  //},
                  PredefinedTime = ReportTimePeriod.Yesterday
              };
  
              report.Filter = new KeywordPerformanceReportFilter()
              {
                  DeviceType = DeviceTypeReportFilter.Computer |
                      DeviceTypeReportFilter.SmartPhone
              };
  
              report.Columns = new[] {
                      KeywordPerformanceReportColumn.TimePeriod,
                      KeywordPerformanceReportColumn.AccountId,
                      KeywordPerformanceReportColumn.CampaignId,
                      KeywordPerformanceReportColumn.Keyword,
                      KeywordPerformanceReportColumn.KeywordId,
                      KeywordPerformanceReportColumn.DeviceType,
                      KeywordPerformanceReportColumn.BidMatchType,
                      KeywordPerformanceReportColumn.Clicks,
                      KeywordPerformanceReportColumn.Impressions,
                      KeywordPerformanceReportColumn.Ctr,
                      KeywordPerformanceReportColumn.AverageCpc,
                      KeywordPerformanceReportColumn.Spend,
                      KeywordPerformanceReportColumn.QualityScore
                  };
  
              return report;
          }
  
          private static void getCampaignsByAccount(long accountID)
          {
          }
  
          private static void getAccountsByCutomer(long customerID)
          {
          }
      }
  }
  </code></pre>
  
  <p>I am stuck on how I can get a report from the API, any help would be appreciated.</p>
  
  <p><strong>UPDATE:</strong> Sounds silly, but it was a incorrect campaign id passed in, Thanks for the help all.</p>