源文件与构建模块时不同

这快把我逼疯了。

我有一个相当大的项目,我试图修改。我早些时候注意到,当我输入 DbCommand的时候,Visual Studio 并没有在上面做任何语法突显,我使用的是 System.Data.Common

尽管没有什么被突出显示,这个项目似乎在我的浏览器中运行得很好。所以我决定运行调试器,看看事情是否真的像它们应该的那样工作。

每次没有做突出显示的类被调用时,我都会得到 "the source file is different from when the module was built"消息。

我清理了解决方案并重建了好几次,删除了 tmp 文件,按照 获取“源文件与构建模块时不同”的所有指示,重新启动了 Web 服务器,但它仍然告诉我源文件有所不同,尽管它们明显不是。

因为这个原因,我不能测试我今天编写的任何代码。

  • 如果我只是照做,源代码怎么会和二进制代码不一样 它?
  • 有没有什么方法可以给视觉工作室带来一些感觉 我漏掉了什么吗?
76759 次浏览

Some things for you to check:

Have you double checked your project references?

Do you have a Visual Studio started web server still running? Check the system tray and look for a page with a cog icon (you may have more than one):

alt text
(source: msdn.com)

Right click and close/exit it. You may have more than one. Can you debug your changes now?

Are you running the debug version but have only built the release version (or vice versa)?

Did the compile actually succeed? I know I've clicked through the "there were errors, do you want to continue anyway?" message a couple of times without realising.

I was just having this same problem, my projects were all in the same solution so they were using Project to Project references, so as one changed the others should have been updated. However it was not the case, I tried to build, rebuild, close VS2010, pulled a new copy from our source control. None of this worked, what I finally ended up trying was right clicking on the project and rebuilding each project individually. That updated the .dlls and .pdb files so I could debug through.

The issue here is that your dll and or your pdb files are not in sync.

I got this issue running a console app where the source that was different was the source that had the entry-point (static void Main). Deleting the bin and obj directories and doing a full rebuild seemed to correct this, but every time I made a code change, it would go out-of-date again.

The reason I found for this was:

  1. I had checked "Only build startup projects and dependencies on Run" (Tools -> Options -> Projects and Solutions -> Build and Run)
  2. In Configuration Manager, my start-up project didn't have "Build" checked

(For #2 -> accessible via the toolbar under the 'Debug/Release' drop down list.)

Follow these steps

  1. Just delete the bin directory from the project where the DLL is generated.
  2. Re-build the project.
  3. Remove reference from the project that make reference to the DLL.
  4. Include again the reference.
  5. Enjoy.

solution:- the problem is:- if your some projects in a solution , refer to some other projects, then sometimes the dll of some projects, will not update automatically, whenever you build the solution, some projects will have previous build dlls, not latest dlls

you have to go manually and copy the dll of latest build project into referenced project

With web services, the problem can be caused by using the Visual Studio "View in Browser" command. This places the service's DLL and PDB files in the bin and obj folders. When stepping into the web service from a client, somehow Visual Studio uses the PDB in the bin (or obj) folder, but it uses the DLL in the project's output build folder. There are a couple workarounds:

  1. Try deleting the DLL and PDB files in the web service bin and obj files.
  2. Try clicking "View in Browser" in Visual Studio.

If you previously got the source file mismatch error, Visual Studio might have added the filename to a black list. Check your solution properties. Choose "Common Properties -> Debug Source Files" on the left side of the dialog box. If your web service source files appear in the field "Do not look for these source files", delete them.

I was using Visual Studio 2013 and I had an existing project under source control.
I had downloaded a fresh copy from source control to a new directory.
After making changes to the fresh copy, when building I received the error in question.

My solution:
1) Open Documents\IISExpress\config\applicationhost.config
2) Update virtualDirectory node with directory to the fresh copy and save.

This is how I fixed the problem in Visual Studio 2010:

1) Change the 'Solutions Configurations' option from "Debug" to "Release"

2) Start debugging

3) Stop debugging and switch the 'Solutions Configurations' option back to "Debug"

This worked for me. Step 3 is optional - it was working fine when I changed it to "Release" but I wanted to change it back.

My solution:

I had included an existing project from a different solution in a new solution file.

I did not notice that when the existing project was rebuilt, it was putting the final output into the NEW solution's output directory. I had a linker path defined to look into the OLD solution's output directory.

Switching my project to search in the new solution's output directory fixed this issue for me.

I just had this issue.

I tried all the above, but only this worked:

  • delete the .pdb file for the solution.
  • delete the offending .obj files (for the file being reported out of sync)

build the solution.

This fixed the issue for all builds moving forward for me.

My problem was that I had a webservice in the project and I changed the build path.

Restoring the default build path solved my issue.

I had this same problem and I followed the majority of the guidance in the other answers posted here, nothing seemed to work for me.

I eventually opened IIS and recycled the application pool for my web application. I have IIS version 8.5.9600, I right-clicked my web application, then: Deploy > Recycle > Recycle application pool > OK.

That seems to have fixed it, breakpoints now being hit as expected. I think that doing this along with deleting the bin and obj folders helped my situation.

Good luck!

I had this problem, and it turns out I was running my console application as a windows application. Switching the output type back to console fixed the issue.

I had the same problem. To fix it I used the "Release Mode" to debug in VS2013. Which is sufficient for me, because I'm working in a node js\c++ addon.

I know this is an old question but I just had the same problem and wanted to post here in case it helps someone else. I got a new computer and the IT dept merged my old computer with the new one. When I set up TFS, I mapped a different local path than what I was previously using, to an additional internal drive. The old path still existed from the merged data on my hard drive so I could still build and run. My IIS paths were also pointing to the old directory. Once I updated IIS to the correct path, I was able to debug just fine. I also deleted the old directory for good measure.

I also experienced that. I just open the obj folder on the project and then open the debug folder delete the .pdb file and that's all.

This error also happens if you try to make changes to a source file that is not part of the project.

I was debugging a method from a .dll of another one of my projects, where Visual Studio had quite helpfully loaded the source because the .dll had been built on the same machine and it knew the path to the source. Obviously, changing such a file isn't going to do anything unless you rebuild the referenced project.

  1. Delete all breakpoints.
  2. Rebuild.
  3. Done

Unload the project that has the file that is causing the error.

Reload the project.

Fixed

At Visual Studio 2015, using C++, what fixed for me the the source file is different from when the module was built problem was

  • restart Visual Studio.

Debug-> start without debugging.

This option worked for me. Hope this helps!

In Visual Studio 2017 deleting the hidden .vs folder in the resolved this issue for me.

Check if the location you pointed to using mex() in Matlab is correct (contains lib and obj files which are modified to the last date you compiled the library in Visual studio).

If this is not the case:

Make sure you are compiling Visual studio in a mode that saves .lib files :

  1. properties -> Config properties -> General -> Config type -> static library

  2. properties -> Config properties -> General -> Target extension=.lib (instead of exe)

Make sure the output and intermediate directories match the Matlab directory in

  1. properties -> Config properties -> General -> Output directory
  2. properties -> Config properties -> General -> Intermediate directory

My problem was that I had two projects in my solution. The second one was a test project used to call the first one. I had picked the path to the references from the bin folder's release folder.

So whenever I made a change to the first project's code and rebuilt it, it would update the dlls in the debug folder but the calling project was pointing to the release folder, giving me the error, "the source file is different from when the module was built."

Once I deleted the reference to the main project's dll in the release folder and set it to the dll in the debug folder, the issue went away.

In my case, the @Eliott's answer doesn't work. To solve this problem I had Exclude/Include From Project my deficient file, andalso Clean and Rebuild the solution.

After these actions, my file with my last modifications and the debugger are restored.

I hope this help.

I get this issue when debugging sometimes w/ Visual Studio but when the application is served by IIS. (we have to develop in this form for some complicated reasons that have to do with how the original developer setup this project.)

When I change the file and rebuild, that fixes it a lot of the time. I know that sounds silly, but I was just trying to debug some code to see why it's doing something weird when I haven't changed it in a while, and I tried a dozen things from this page, but it was fixed just by changing the file..

In addition to these answers I had the same issue while replacing new DLLs with old ones because of the wrong path. If you are still getting this error you may not refer the wrong path for the DLLs. Go to IIS manager and click the website which uses your DLLs. On the right window click Advanced Settings and go to path of the Physical Path folder on File Explorer and be sure that you are using this folder to replace your DLLs.

In my case, the problem was that the debugger exe path was pointing to a net5.0 bin folder. I am using net6.0, so I should've updated the exe path back when I updated the target framework. Works fine now.