the source file is different from when the module

2019-01-08 07:53发布

问题:

This is driving me crazy.

I have a rather large project that I am trying to modify. I noticed earlier that when I typed DbCommand, visual studio did not do any syntax highlighting on it, and I am using using System.Data.Common.

Even though nothing was highlighted, the project seemed to be running fine in my browser. So I decided to run the debugger to see if things were really working as they should be.

Every time the class that didn't do the highlighting is called I get the "the source file is different from when the module was built" message.

I cleaned the solution and rebuilt it several times, deleted tmp files, followed all the directions here Getting "The source file is different from when the module was built.", restarted the web server and still it tells me the source files are different when they clearly are not.

I cannot test any of the code I have written today because of this.

  • How can the source be different than the binary when I just complied it?
  • Is there any way to knock some sense into visual studio, or am I just missing something?

回答1:

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.)



回答2:

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.



回答3:

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 http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/Tip.NetDevelopmentServerinaMultiprojectS_104C2/image_2.png

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.



回答4:

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.


回答5:

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.



回答6:

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.



回答7:

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.



回答8:

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.



回答9:

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.



回答10:

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.



回答11:

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

Reload the project.

Fixed



回答12:

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



回答13:

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.



回答14:

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



回答15:

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.



回答16:

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.



回答17:

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!



回答18:

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.



回答19:

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.



回答20:

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.



回答21:

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


回答22:

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.


回答23:

Debug-> start without debugging.

This option worked for me. Hope this helps!



回答24:

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


回答25:

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.



回答26:

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..