none
Eror:A new expression requires (), [], or {} after type

    Question

  • I am getting the following error.
    I aam not sure what the mistake is .
    I am assigning a value returned by a method to the variable

    public string clienttoken;

    clienttoken = c1.SetToken();  #### Error here

    Error 1 A new expression requires (), [], or {} after type 

    Friday, August 14, 2009 6:37 PM

Answers

All replies

  • Check this link.

    If that doesn't help, post more of your code.  Enough to tell where these items are given in context to the file.

    In other words, post the whole code file.


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiTwitterLinkedInForumsBrowser
    Friday, August 14, 2009 6:43 PM
  • Are you sure that the line that throws the error is inside a method?
    http://blog.voidnish.com
    Friday, August 14, 2009 6:46 PM
  • app.config file does not have any provider optionas suggested in the link given by you.
    <providerOption name="CompilerVersion" value="v3.5"/>  ---- not available in app.config section


    Here is the code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using VESample.VEStagingToken;
    using VESample.VEGeocodingService;


    namespace CVEWSTest
    {
        public partial class Form1 : Form
        {
             public string clienttoken;

            public Form1()
            {
                InitializeComponent();
              
            }
          
            private void Geocode_Click(object sender, EventArgs e)
            {
                
                     VESample.Class1 c1 = new VESample.Class1

                     clienttoken = c1.SetToken();    ###### I tried to put it in a different method but i get the same error.

                     lbl_Text.Text =  c1.GeocodeAddress(txtInput.Text, clienttoken);
            }


        }
    }

    Code in C# class file: This is accessing a Virtual earth Web Service


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using VESample.VEGeocodingService;
    using VESample.VEStagingToken;


    namespace VESample
    {
        public class Class1
        {
            public string clientToken;

            public string SetToken()
            {
                // Create a reference to the web service (VEStagingToken.CommonService)
                CommonService commonService = new CommonService();
                commonService.Url =
                  "https://staging.common.virtualearth.net/find-30/common.asmx";

                //Use your developer credentials
                //commonService.Credentials =
                //  new System.Net.NetworkCredential("VE Account ID", "VE Account Password");
                commonService.Credentials =
                 new System.Net.NetworkCredential("144534", "tr_Manager5717");
                // Create the TokenSpecification object to pass to GetClientToken.
                TokenSpecification tokenSpec = new TokenSpecification();

                //Insert the client IP address
                tokenSpec.ClientIPAddress = "0.0.0.0";

                // The maximum allowable token duration is 480 minutes (8 hours).
                // The minimum allowable duration is 15 minutes.
                tokenSpec.TokenValidityDurationMinutes = 480;

                clientToken = commonService.GetClientToken(tokenSpec);

                return clientToken;
            }

            public String GeocodeAddress(string address, string ctoken)
            {
                string results = "";
                GeocodeRequest geocodeRequest = new GeocodeRequest();

                // Set the credentials using a valid Bing Maps token
                geocodeRequest.Credentials = new VEGeocodingService.Credentials();
                geocodeRequest.Credentials.Token = ctoken;

                // Set the full address query
                geocodeRequest.Query = address;

                // Set the options to only return high confidence results
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = VEGeocodingService.Confidence.High;

                // Add the filters to the options
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                // Make the geocode request
                GeocodeServiceClient geocodeService = new GeocodeServiceClient();
                GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

                if (geocodeResponse.Results.Length > 0)
                    results = String.Format("Latitude: {0}\nLongitude: {1}",
                      geocodeResponse.Results[0].Locations[0].Latitude,
                      geocodeResponse.Results[0].Locations[0].Longitude);
                else
                    results = "No Results Found";

                return results;

            }
           
        }
    }


     

    Friday, August 14, 2009 7:48 PM
  • Your problem is actually with the line before:

    VESample.Class1 c1 = new VESample.Class1

    Should be:

    VESample.Class1 c1 = new VESample.Class1(); <--- here.

    You're not putting the parenthesis behind the constructor for VESample.Class1, and you're not terminating the statement with a semicolon, which is something you have to do for every statement in C#.


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiTwitterLinkedInForumsBrowser
    • Marked as answer by rowter Friday, August 14, 2009 8:04 PM
    Friday, August 14, 2009 7:50 PM
  • Silly mistake ...

    Thanks ...
    Friday, August 14, 2009 8:04 PM