Where is the obj folder of my visual studio 2010 project - c#

I am new to Visual Studio. I am using VS 2010 and I cannot find the main method of my C# application. After browsing a bit, I found out that it is created during the compilation phase and is located in obj/{Debug/Release} folder. However, I am unable to locate the folder on my system.
My solution explorer and properties window look like this:
And the corresponding directory (path from the properties window in the above picture) doesn't have obj folder.
Can somebody help me locate the obj folder? I want to check the flow of my program.
Any help is greatly appreciated.
Thanks!

I cannot find the main method of my C# application
A web site doesn't have a "main" method. It usually has global initialization hooks, but nothing quite like Main.
It also looks like you've created a "Web Site" project rather than a "Web Application" project - I've never fully understood the difference, but I suspect you may find that a web site project isn't built in quite the same way, so you may never see the output folders you were expecting. In particular, I'm not seeing anything that would correspond to where I'd expect those initialization hooks to be. You may wish to create a new project as an ASP.NET web application instead.
(I'd update to a more modern version of Visual Studio at the same time, if you possibly can. There's a "community" edition of VS2013 or the release candidate for VS2015...)

You have created an empty WebSite not WebApplication so by default in WebSite there is no bin folder until and unless you explicitly add bin folder or you Add Reference to dll;
In WebSite your main folder for code is App_Code folder where all your .cs files are placed.And in WebApplication all of your code is converted in a dll that is placed in bin folder.

Related

Copying DLL into additional directory on build ASP.NET

I have a web project created in Visual Studio 2012 that consists of a project as well as a web application. Both share the same solution. I'm basically just trying to get the DLL that's created in the project to be passed to the bin folder of the web application automatically with each build. I know it can be done because it's like that on other web projects I have, but I don't know why it works on some and not on others. I've been searching the internet hours, but have had zero luck. It seems like a very simple setting change so maybe someone on here knows.
I finally found the simple, one line answer I was looking for. I'll post the answer here to help others...
Go to Properties (for project in question), click on Build Events, enter the following into the Post-Build Event Command Line:
Copy /Y "$(ProjectDir)bin\debug*." "$(SolutionDir)bin*."
In this case, ProjectDir is the root directory of the project and SolutionDir is the root directory of the web application.

Can I tell Visual Studio to kindly keep its ugly meta files away from my source directory?

Short version: I want Visual Studio 2010 to save the solution and project files to the default "My Documents" directory, while regarding my actual project directory on Dropbox as the place to put source files.
I know I can "Add Existing Item" from the project menu, but that's hardly an acceptable solution as I have to manually create absolutely every file I'm to work with in VS from explorer. I've tried adding my project folder to the project, but that just resulted in VS lying to my face:
Is it possible to actually separate Visual Studio's fugly meta files from my project directory? If not, what would be the best workaround?
I might have to do my C# in Vim because of this...
NOTE: I know C++ projects has the "Add Filter" function, which appears to do almost exactly what I want, but I'm working with C#.
Workaround
Create a symlink from the actual project folder in Dropbox to Visual Studio's project folder, e.g:
C:\Users\tomas>mklink /J "...\Visual Studio 2010\Projects\Testing\Journal\journal" "...\Dropbox\Projects\cs_testing\journal"
Junction created for ...\Visual Studio 2010\Projects\Testing\Journal\journal > ...\Dropbox\Projects\cs_testing\journal
Then add the symlink to the project as an "External Item". Now Visual Studio thinks it's being devious and adding all new files to its own project directory, but they are actually ending up in my Dropbox.
Drawbacks
Every item added to the project must be put in the symlink subfolder.
Items automatically add themselves to the namespace "<project>.<subfolder>.*", so on my case an added class was automatically called Journal.journal.JournalForm.
It's tedious to do this for every project.
There are probably more, but I just discovered this workaround. I'll edit this answer later if necessary.

Getting C# to recognize a dll outside of Visual Studio

Several years before I started working at this job another developer who is no longer here wrote an application in classic ASP using HTML, vbscript and javascript. This is fine but the problem is that 2 pages were written in C# with an HTML file and a code behind file. There was no solution files for these two pages. They may have been originally created in Visual Studio but they don't exist in it now.
That is important because there is a lot of things that Visual Studio just does for you without even thinking.
My problem is that in these two C# pages I need to get them to reference a DLL. This is a simple task when using Visual Studio. You just add a reference to the project and life is good. But outside of VS nothing seems to work.
I tried putting the dll in the same folder as the pages and then I tried the following:
Using myDLL;
myDLL dll = new myDLL();
myDLL dll = myDLL();
I found some code online that said to create an internal static class and use [DLLImport()] but that didn't work either. It couldn't find the dll or the Entry Point for the dll. I am currently researching how to create an entry point, just in case this is the method to make everything work.
Outside of having to rewrite these pages in vbscript (which I don't have the time to do) I am at a loss.
Has anyone ran into this problem before? Is there something that I can put in the web.Config? Or is this just impossible and I am hosed.
BTW this is all running under the 2.0 .net framework.
If you drop the DLL you want the code to reference into the bin folder of the website, then open the web.config and locate the following section configuration -> system.web -> compilation -> assemblies.
You need to add the display name of the assembly to that list - so that the compiler will reference that assembly during it's late-bound build process.
Now you should be able to use the stuff that's in it on those pages.
If you don't the know the display name of the assembly (typically yourassembly, version=*.*.*.*, Culture=neutral, PublicKeyToken=null for culture-invariant, non-strong-named assemblies) you can open it in a tool like ILSpy (there are others, it's just become my favourite) and it tells you when you select it in it's UI:
sorry for the poor highlighting - jerky hand following far too much coffee
If all the code in that assembly is in a single namespace, also, you can also add a default using to all the .cs or .aspx code in the project by adding that namespace to configuration -> system.web -> pages -> namespaces - making it simpler to use that code in the pages.
I created a VS Solution/Project for my app. I compiled and published it to the web server. When I published it I had it copy all project files.
I ran it and it crashed because it could not find my dll.
I tried adding the lines that Andras mentioned above and it seemed like it was getting me closer but it only changed the errors I was getting.
Then I went into IIS on the web server. I expanded the folder listing under Web Site. I right clicked on the folder that contained my app and made that folder into an application folder.
After I did that everything just worked. So then I thought I would see what happened if I backed out all of the additional code I added to my C# app and the Web.Config file. It still worked. All I needed to do was to make the folder an application folder in IIS and put a Using statement in my C# app and life is wonderful again.
Thanks for all the comments and suggestion. Andras thanks for the link to ILSpy. That is a cool little tool.
Take care,
Robert
I agree with Jon, it sounds like you should try creating a new project for these files. It's always better to leave code better off than you found it. If a new project is not an option for some reason, you should indicate this in your question.

VS 2008 - Star Team and multi project solution?

I have a project which is under source control via Star Team in VS 2008. I added another project to my solution for an installer, configured it, tested it, etc. Now, when I go to check in my solution with the new installer, I get the following warning:
The project that you are attempting to add to source control may cause other source control users to have difficulty opening this solution or getting newer versions of it. To avoid this problem, add the project from a location below the binding root of the other source controlled projects in the solution.
There are with options to Continue or Cancel.
My project directory looks like this:
/Proj1/
Proj1.sln
/Proj1/
.cs files
.csproj
/bin/, etc
/Proj1_Installer/
Proj1_Installer.vdproj
/Debug/
/Release/
Is there something fundamental I'm missing?
The files for the new solution should be in the same location as the projects you already have from source control. For example if you have existing code from source control
Source\
Project1\
program.cs
Proejct2\
program.cs
then you need to put your new project in the same folder and project1 and project2
Source\
Project1\
program.cs
Proejct2\
program.cs
NewProject\
"add the project from a location below the binding root of the other source controlled projects in the solution" If you decide to add it to the "MyProjects" folder on your drive, then others won't be able to get it from source control.
I suggest if this is how your physical folder structure actually is, verify the solution file using notepad and check the paths. Maybe it's referencing it using
..\..\Path1\Path2
instead of
.\Path2
My problem was that my debug and resource folders were being put into source control. Visual studio wants to generate these every time the project runs, so they shouldn't be placed in SC.

the source file is different from when the module was built

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?
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:
I had checked "Only build startup projects and dependencies on Run" (Tools -> Options -> Projects and Solutions -> Build and Run)
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.)
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.
Follow these steps
Just delete the bin directory from the project where the DLL is generated.
Re-build the project.
Remove reference from the project that make reference to the DLL.
Include again the reference.
Enjoy.
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.
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):
(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.
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:
Try deleting the DLL and PDB files in the web service bin and obj files.
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.
Unload the project that has the file that is causing the error.
Reload the project.
Fixed
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.
In Visual Studio 2017 deleting the hidden .vs folder in the resolved this issue for me.
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 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.
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.
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
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.
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 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.
Delete all breakpoints.
Rebuild.
Done
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.
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 :
properties -> Config properties -> General -> Config type -> static library
properties -> Config properties -> General -> Target extension=.lib (instead of exe)
Make sure the output and intermediate directories match the Matlab directory in
properties -> Config properties -> General -> Output directory
properties -> Config properties -> General -> Intermediate directory
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 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.
Debug-> start without debugging.
This option worked for me. Hope this helps!

Categories

Resources