Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have code that works just fine (visual web part). I had deleted the testing console application, and now I have need for it again. The browser will open up once running the console application, but then nothing happens. My breakpoint is not hit, and yet there are no errors.

1) I am an admin 2) console app is .net 3.5 and x64 3) no errors

        class Program
{
    static void Main(string[] args)
    {
        List<string> displayNames = new List<string>();
        List<string> branch = new List<string>();
        List<string> department = new List<string>();
        string dept;

        using (SPSite site = new SPSite("http://mysite"))
        {
            //using (SPWeb web = site.OpenWeb())
            //{
                // the line below has a breakpoint - never hit
                SPServiceContext context = SPServiceContext.GetContext(site);
                UserProfileManager profileManager = new UserProfileManager(context);

                foreach (UserProfile profile in profileManager)
                {
                    // checks if work phone is empty - this relates to vendors in AD and are not employees
                    if (!string.IsNullOrEmpty(string.Format("{0}", profile["WorkPhone"].Value)))
                    {
                        Console.WriteLine(string.Format("{0}", profile["PreferredName"].Value));
                        displayNames.Add(string.Format("{0} - {1}", profile["PreferredName"].Value, profile["WorkPhone"].Value));
                    }

                    dept = string.Format("{0}", profile["Department"].Value);

                    if (!string.IsNullOrEmpty(dept))
                    {
                        if (dept.StartsWith("Branch -"))
                        {
                            branch.Add(dept);
                        }
                        else
                        {
                            department.Add(dept);
                        }
                    }
                }
            //}

            Console.Read();
            department = department.Distinct().OrderBy(x => x).ToList();
            branch = branch.Distinct().OrderBy(x => x).ToList();

            displayNames.Sort();

        }
    }

thanks

share|improve this question
    
are you in Debug configuration ? Where is your breakpoint ? If you wrap the whole content of Main in a try/catch, do you see any exception ? Which one ? –  Steve B Jun 8 '12 at 13:32
    
yes i am in debug config - breakpoint is under the first using statement. there are no exceptions, it just opens the browser, goes to the home page, and that's it. if i look back to my code when it's running, the breakpoint states "The breakpoint will not currently be hit" –  robScott Jun 8 '12 at 13:42
    
if you have "The breakpoint will not currently be hit", that means you are either missing the pdb file, or the running code is not the code corresponding to the source. This can happen if you have the same DLL in the GAC, which will be used, even if you have a more recent local copy of the file. –  Steve B Jun 8 '12 at 13:50
    
yes that was it thank you –  robScott Jun 8 '12 at 14:13
    
To avoid this types of errors when testing something in console app, simply delete particular dlls from gac –  Kai Jun 8 '12 at 14:28
add comment

3 Answers 3

up vote 1 down vote accepted

According your comment, if you have the message The breakpoint will not currently be hit, that means you are either missing the pdb file, or the running code is not the code corresponding to the source.

This can happen if you have the same DLL in the GAC, which will be used, even if you have a more recent local copy of the file.

share|improve this answer
add comment

HAve you tried setting your build target to Any CPU?

share|improve this answer
    
yes unfortunately i have. whenever i run this console application, the browser pulls up the site (default.aspx) and nothing ever happens. –  robScott Jun 8 '12 at 13:36
add comment

You say the Browser is opening, that sounds as if you have the Console App in a solution togetter with your sandboxed webpart, and the project with the web part is set as start up project, which means that it's the one to start when you debug.

Right click your console app project in solution explorer and select "Set as StartUp project"

If the console app is already the StartUp project then check the debug settings of it:

  • Right click the project in solution explorer
  • Select "Properties"
  • Select the "Debug" Tab
  • Make sure that "Start Action" is set to "Start project"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.