the source file is different from when the module was built

C#Visual Studio-2008

C# Problem Overview


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 https://stackoverflow.com/questions/353421/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?

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

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.

Solution 3 - C#

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 4 - C#

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.

Solution 5 - C#

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.

Solution 6 - C#

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.

Solution 7 - C#

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

Reload the project.

Fixed

Solution 8 - C#

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.

Solution 9 - C#

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

Solution 10 - C#

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.

Solution 11 - C#

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.

Solution 12 - C#

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.

Solution 13 - C#

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.

Solution 14 - C#

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.

Solution 15 - C#

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.

Solution 16 - C#

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

Solution 17 - C#

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.

Solution 18 - C#

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.

Solution 19 - C#

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!

Solution 20 - C#

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.

Solution 21 - C#

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.

Solution 22 - C#

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.

Solution 23 - C#

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

Solution 24 - C#

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.

Solution 25 - C#

Debug-> start without debugging.

This option worked for me. Hope this helps!

Solution 26 - C#

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

Solution 27 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfrustratedcoderView Question on Stackoverflow
Solution 1 - C#EliottView Answer on Stackoverflow
Solution 2 - C#Scott DeanView Answer on Stackoverflow
Solution 3 - C#CharlesView Answer on Stackoverflow
Solution 4 - C#ChrisFView Answer on Stackoverflow
Solution 5 - C#utacoView Answer on Stackoverflow
Solution 6 - C#user3233739View Answer on Stackoverflow
Solution 7 - C#MikeView Answer on Stackoverflow
Solution 8 - C#gollumullogView Answer on Stackoverflow
Solution 9 - C#James WestgateView Answer on Stackoverflow
Solution 10 - C#djmcghinView Answer on Stackoverflow
Solution 11 - C#BenView Answer on Stackoverflow
Solution 12 - C#Eliezer MironView Answer on Stackoverflow
Solution 13 - C#jdscardosoView Answer on Stackoverflow
Solution 14 - C#Dalibor BjelichView Answer on Stackoverflow
Solution 15 - C#Obiwan KenobiView Answer on Stackoverflow
Solution 16 - C#user2930560View Answer on Stackoverflow
Solution 17 - C#Th4t GuyView Answer on Stackoverflow
Solution 18 - C#BoanergeView Answer on Stackoverflow
Solution 19 - C#A. MurrayView Answer on Stackoverflow
Solution 20 - C#mslissapView Answer on Stackoverflow
Solution 21 - C#user5912760View Answer on Stackoverflow
Solution 22 - C#Dan BechardView Answer on Stackoverflow
Solution 23 - C#JajaView Answer on Stackoverflow
Solution 24 - C#Pedro ReisView Answer on Stackoverflow
Solution 25 - C#Madhurya GandiView Answer on Stackoverflow
Solution 26 - C#lahmaniaView Answer on Stackoverflow
Solution 27 - C#Chase AndersonView Answer on Stackoverflow