Visual Studio 2010: Why can't I resume the application when I made changes to the delegate?

I'm not sure if this is .Net or C # or even Visual Studio 2010/2008, but I noticed that whenever I pause my application to change something in the code and the changes are made to the delegate, I cannot resume the application, but it needs to be restarted.

So my questions are:

1) Does it depend on the programming language? Or framework? Or an editor?

2) Is it only when I change delegates? Or other things?

3) Why is this so?

+4
source share
4 answers

Modify and continue does not support all possible code changes. well documented in the MSDN library, here I recheck the list:

  • Changes the current statement or any other active statement.
  • Change global characters, including the following:
    • Adding new types.
    • Adding methods to a type.
    • Change signature type.
    • Add fields, events, or properties to a type.
  • Editing an anonymous method or any method that contains an anonymous method.
  • Adding a new anonymous method.
  • Add, remove or modify attributes.
  • Add, delete or change using directives.
  • Delete or change local variables. Adding local variables is allowed.
  • Adding foreach, using or blocking an active statement.
  • Modifying a method containing a yield return or yield break statement.
  • Modifying a constructor with a field initialized by an anonymous method.

You use the option "Change signature type".

+4
source

There are certain changes in the code that are significant enough so that the debugger cannot resume without a full restart. As a rule, you can safely change the lines of code inside the method, but if you change the class itself (adding, for example, the method signature parameter), which will require a complete recompilation.

Anonymous delegates and lambda functions are represented in .NET to a large extent as an anonymous class with some variable references. Since there is no name for the debugger to β€œreconnect” this lambda expression to when you resume, changing the delegate function basically turns it into a new class. You will see similar behavior with anonymous types.

+5
source

Answering your questions:

1) Does it depend on the programming language? Or framework? Or an editor?

I don’t know the exact name in .NET terminology, but in Java / Eclipse, code modification during its operation is called Hot Code Replacement. It all depends on whether the runtime can accept such changes while preserving the rest of the program.

2) Is it only when I change delegates? Or other things?

If there are changes in behavior, I would say that it will be accepted soon. Structural changes, such as adding methods, renaming classes, or changing other, possibly more complex constructs that translate to classes or otherwise, rather static structures, will cause problems at the most time.

3) Why is this so?

Well, other answers should make this clear. Some changes cannot be made at runtime. Static type security is another reason that can be circumvented otherwise.

+2
source

1: you can edit your html markup on ASPX pages, but to work with compiled code you need to stop the application and recompile.

2: No, if you change any compiled code or configuration files, you will need to stop debugging and recompile.

3: As I meant in 1-2, the C # and vb code is compiled before debugging, so to see the changes to this code, you have to recompile.

0
source

Source: https://habr.com/ru/post/1342196/


All Articles