我可以重现你的情况:
Reasons for this situation: the decompiled code does not match the original code, or the pdb file does not match the source file version.个
机制:
因为对于C#,PDB主要记录行号等信息(如果它是CPP,则在PDB中会有源代码信息,这是不同的),并且因为您一侧的源文件与它应该是不同的,所以当您按f11时,它将"步入"一个您"认为"完全错误的位置,但实际上它已经转到了正确的位置(我的意思是,如果您按f11,如果源文件匹配,它真的应该转到该行).
解决问题的关键是确保三个文件的一致性:源文件、DLL和PDB.
您可以使用像dotpeek这样的工具将C#DLL文件反编译成一个项目(您可以使用该工具将DLL导出为一个全新的项目/解决方案),然后您就可以构建这个新项目了.在这种情况下,您可以确保这个新项目中的源文件、DLL和PDB是一致的.让您的测试项目引用这个反编译项目中的DLL,这样您就不会遇到问题.
应该指出的是,the decompilation operation cannot guarantee that the decompilation code is 100% the same as the source code. It is inevitable that the code obtained in this way will be somewhat different from the source code.
顺便说一句,正如Hans提到的,有一个名为‘需要与原始版本完全匹配的源文件’的功能:
这是官方文件:
Require source files that exactly match the original version个
您需要打开此功能(这是我这边的默认打开设置.)