the common language runtime was unable to set the breakpoint
Asked Answered
A

7

32

This is actually another part of this question.

Error settings breakpoints but only on some lines while debugging

I'm remote debugging a CRM 2011 plugin in vs 2010.

I'n one of my source files I can set breakpoint all throughout the code except in a few places.

When I try to set a breakpoint I get this error "The following breakpoint cannot be set:" and "The Common Language Runtime was unable to set the breakpoint."

protected override void ExecutePlugin()
{
    SetStateResponse response = new SetStateResponse(); // Breakpoint works

    // Message switch
    switch (_crmMessage) // Breakpoint error
    {
        case CrmPluginMessageEnum.Create:

        Entity pimage = null; // Breakpoint error
        if (_context.PostEntityImages.ContainsKey("postcreate")) // Breakpoint works
            pimage = _context.PostEntityImages["postcreate"]; // Breakpoint error

        break; // Breakpoint error
        }
} // Breakpoint error

UPDATE Also, in the modules window it shows the dll as Optimized: No User Code: Yes Symbol Status: Symbols Loaded

Aharon answered 20/12, 2011 at 19:13 Comment(10)
Please, add your code! There are plenty of cases (like lambda-expressions, variable declaration without initialization for example) where you cannot set a breakpoint normally.Popcorn
blogs.msdn.com/b/habibh/archive/2009/09/01/…Iulus
@DJKRAZE F9 does the same thing. Check the link in the question to see example code.Aharon
@HansPassant Verified that's not the issue.Aharon
@AlexanderGalkin Check the link in the question to see example code.Aharon
When it says "The following breakpoint cannot be set" you are trying to set a breakpoint to a place that doesn't compile to any actual code e.g. on a variable declaration or just white space. Show the exact line of code where you can't set the breakpoint.Abdicate
If you are doing remote debugging, is it possible that your PDB file is out of sync with the compiled DLL? Have your tried deleting your bin and obj files and recompiling?Flop
Are you 100% sure that the DLL matches the source code, have you correctly deployed the plug in, the fact that some breakpoints work and other don't suggests that the DLL is out of date or perhaps symbols file have not been updated.Abdicate
I have made sure 100% the .pdb matches the .dll I'm debugging.Aharon
I've also used reflector and everything looks fine.Aharon
P
46

Two possibilities, already kind of referenced by the other answers:

  1. Make sure you are using the Debug build of the assembly instead of the Release build, because the Release build will remove or optimize your code.
  2. Make sure you are updating the version each time you deploy the assemblies in Visual Studio (on project properties tab). When you increment the version, CRM will be sure to unload the old assembly version and reload the new one without an IIS reset.
Portis answered 18/7, 2013 at 18:14 Comment(1)
e boy, Thank you a lot, I'm so stupid(( with this shit I had sit about 2 hour... Thank YOU A lotPoundal
V
4

I had this same issue when I had the project open in two instances of Visual Studio. The project which I was not debugging had a lock on the file and notifying me "This file has been modified outside of the source editor." After accepting the changes in my non-debugging solution, I no longer received the error and my breakpoints were hit in my solution I was debugging.

It sounds like there is a lot of possible causes to this error, but this did it for me.

Velvety answered 3/4, 2012 at 15:21 Comment(0)
G
4

I got this problem when I created a breakpoint using the Ctrl+B shortcut (see image attached), and I entered a name of a function which doesn't exist, so the breakpoint was added but caused an error. then each time I started the project it appeared that error.

Solution: I deleted the breakpoint from the breakpoints list (see left bottom in image attached), select the breakpoints section, then select the item and click delete. enter image description here

If you don't see the breakpoints section

You can retrieve it by hitting Ctrl+Alt+B

Geomancy answered 11/7, 2018 at 16:52 Comment(0)
A
0

Further to your update about the DLL being optimised the lines you have indicated where breakpoints don't work will likely be optimised away as your entire switch statement does not do anything other decide whether or not to assign a value to a variable that is never used and does not live beyond the scope of the switch statement. As such the compiler will simply not generate any code for the switch statement as it does not do anything at all or the jit just gets rid of it at run time for the same reason.

Abdicate answered 20/12, 2011 at 22:21 Comment(1)
Correct. Via reflector it shows that it was converted to an if statement.Aharon
K
0

I just had a similar experience and the way I worked through it was to put a breakpoint at the spot where the routine was called and then single-stepped into the routine until I saw exactly what it thought it was doing. In my case, there was a return that was preventing all the code in the routine from running, so the optimizer tossed it all out. Sometimes it's the stupid things, right? Anyway, if you start at a level higher in the call stack and step into the routine where the problem is, the reason for the problem might become more obvious.

Katiakatie answered 18/1, 2013 at 20:56 Comment(0)
H
0

Another cause of this issue I have just found if you are debugging against CRM is not updating the plugin registration points. Even if you copy the new DLLs to the target machine and attach remotely to that process that is not the DLL CRM will use. CRM will try to take a copy of an old version from its database until you rerun the plugin registrations.

An error which wasted a day and a half for me!

Housebroken answered 18/7, 2013 at 9:19 Comment(0)
M
0

I got this error when start run debugging the project, and I solve it by Clean All Project and Rebuild All Project, after rebuild the error disappear.

Morningglory answered 17/11, 2017 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.