.Net C# web service not all code paths return a value

Posted on 2007-07-31
Last Modified: 2013-11-26
I am getting the following error I understand I am missing something but I have no idea what as I am still learning. Any help would be great

error message:

------ Build started: Project: e:\projects\ChromeWebService\, Configuration: Debug .NET ------
Validating Web Site
Building directory '/ChromeWebService/App_WebReferences/'.
Building directory '/ChromeWebService/App_Code/'.

e:\projects\ChromeWebService\App_Code\ChromeWebService.cs(27,19): error CS0161: 'ChromeWebService.getVin()': not all code paths return a value
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Here is the code:

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

/// <summary>
/// Summary description for ChromeWebService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ChromeWebService : System.Web.Services.WebService {

    public ChromeWebService () {

        //Uncomment the following line if using designed components


    public string getVin()

        AutomotiveDescriptionService5 ads = new AutomotiveDescriptionService5();

        AccountInfo accountInfo = new AccountInfo();
        accountInfo.accountNumber = "xxxxxxxx";
        accountInfo.accountSecret = "xxxxxxxxxxxx";
        accountInfo.locale = new Locale();
        accountInfo.locale.language = "en"; = "US";
        String Vin = "";
        String manufactureModelCode = "";
        String trimName = "";
        String manufactoureOptionCodes = "";
        String equipmentDescriptions = "";
        String wheelBase = "";
        String exteriorColorName = "";
        String useSafeStandards = "";
        String excludeFleetOnlyStyles = "";
        String includeAvailableEquipment = "";

        String version = "";
        DataVersionsRequest dataVersionRequest = new DataVersionsRequest();
        dataVersionRequest.accountInfo = accountInfo;
        DataVersion[] dataVersions = ads.getDataVersions(dataVersionRequest);
        for (int i = 0; i < dataVersions.Length; i++)
            if (dataVersions[i].country == "US")
                version = dataVersions[i].country + " " + dataVersions[i].build + " (" +
                    dataVersions[i].date + ")";

        VehicleInformation vehicleInfo = null;
        if (Vin != null && Vin.Length > 0)
            VehicleInformationFromVinRequest vinRequest = new
            vinRequest.accountInfo = accountInfo;

   = Vin;
            vinRequest.manufacturerModelCode = manufactureModelCode;
            vinRequest.trimName = trimName;
            if (manufactoureOptionCodes.Length > 0)
                vinRequest.manufacturerOptionCodes = manufactoureOptionCodes.Split(new char[] { ',' });
            if (equipmentDescriptions.Length > 0)
                vinRequest.equipmentDescriptions = equipmentDescriptions.Split(new char[] { ',' });
            if (wheelBase.Length > 0)
                vinRequest.wheelBase = Double.Parse(wheelBase);
            vinRequest.exteriorColorName = exteriorColorName;
            vinRequest.useSafeStandards = useSafeStandards != null;
            vinRequest.excludeFleetOnlyStyles = excludeFleetOnlyStyles != null;
            vinRequest.includeAvailableEquipment = includeAvailableEquipment != null;

            vinRequest.enableEnrichedVehicleEquipment = false;

            vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);



Thank you for taking the time to look at this.
Question by:jareddraper
    LVL 6

    Accepted Solution

    not all code paths return a value --> If a function return string, then you have to make it return a string when you return from the function.

    perhaps in this function
    public string getVin()
    you need to return a string at the end

    otherwise change it to
    public void getVin()
    LVL 6

    Expert Comment

    Perhaps something like this
            if (Vin != null && Vin.Length > 0)
                //.... your code.....

                vehicleInfo = ads.getVehicleInformationFromVin(vinRequest);

                return vehicleInfo.ToString(); //or any method/property of vehicleInfo that is a string
            {   return "";  }

    Author Comment

    Thank you both I figured it was something like this but didn't know how to complete what it was doing. Thank you both I will try both and see which works better.

    Author Comment

    ha just noticed Hardi you posted both Thank you
    LVL 6

    Expert Comment

    Hahaha no worries, glad to help :-D

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now