Why am I getting a different xml file open behaviour depending or where I open the sln file? - asp.net-mvc

Ok, I know that question is not very informative.. Someome feel free to change it after I explain:
My asp.net mvc project is stored in a folder in my desktop. When I double click on the sln or csproj to open the project and then hit the Start Debuggin button it all works fine.
But, when I go to start, programs and open Visual Web developer and from the Recent Projects I open the same project and Start debugging I get a read file error (could not find part of the path in C:\Program files(x86)\Microsoft Visual.......")
Its in this line of code btw.
this.nav = XElement.Load("App_Data/myfile.xml");
It obviously is looking on the wrong directory cause the project folder is in my desktop. Keep in mind that it works just fine if I access the project by just double clicking on the csproj file.
Thanks in advance.

You can't rely on the working folder for the process in ASP.NET applications. You should be resolving a relative path in code:-
this.nav = XElement.Load(HttpContext.Current.Server.MapPath("App_Data/myfile.xml"));
However introducing the HttpContext object can damage the testability of your code, if this in controller code.

Related

Visual Studio 2019 vs 2020 - Debugging container problem

Is anyone able to offer me some advice...
I've got a repository with 2 solutions in it. Each solution is made up of multiple projects. One solution is .NET 4.8 the other is .NET CORE 3.1.
These solutions run locally in docker containers.
In VS2019 I can attach to process and debug both of these containers/solutions. When I look at the modules window I can see "User Code - Yes" and "Symbol Loaded - Server Side Symbol" (or something similar to that).
In VS2022 I can attach and debug the .NET 4.8 solution but when I attach to the .NET CORE 3.1 solution I get an warning message saying:
"The breakpoint will not currently be hit. No symbols have been loaded for this document".
When I look at the modules window in VS2022, I can see my DLLs are all marked as "User Code - N/A" and "Cannot find or open the PDB file".
Additionally, if I right click the DLLs and select Symbol Load Information, I can see something like this:
C:\solution\src\Project\MyStartUpProject\rendering\bin\container\Debug\netcoreapp3.1\MyComponentProject.pdb: Cannot find or open the PDB file.
C:\solution\src\Project\MyStartUpProject\rendering\bin\container\Debug\netcoreapp3.1\MyComponentProject.pdb: Cannot find or open the PDB file.
C:\solution\src\Feature\MyComponentProject\rendering\obj\container\Debug\netcoreapp3.1\MyComponentProject.pdb: Cannot find or open the PDB file.
What's odd about this is that C:\solution\ is the folder location in the Docker Container, not on my local drive. C:\solution\ is a mounted volume in my container and it mounts to C:\source\reponame\ on my computer, so I guess this is why the PDB file can not be found...
So my questions are...
Why is VS2022 looking at C:\solution\ not C:\source\reponame\ (or some how retrieving the DLLs the same way as VS2019)
and
Is there a way to have VS2022 look in the correct location? (I don't really want to add a Symbol Path to VS for each project I work on, especially as these could change).
Cheers,
Dan

Asp.Net MVC Core 3.1. why index.cshtml.g.cs added to the view folder and no error

Recently I started to notice that my project is adding views with xxx.chtml.g.cs. I tired to search for the answers within stackoverflow and other resources, and the answer I am getting that these files are generated due to some error. But for me there neither is no issue nor getting any compile error. This generated files have hardcoded obsolete path to the resources, and this is what my concern is, if I was working in a the team and other team member would pick up the code what if these files are to be used and won't find the resources on the path.
These files are added into the debug folder: MySolution\MyMVCProject\Debug\netcoreapp3.1\Razor\Views\Disenfection
If someone suggest me to delete the folder or tells me it won't effect then my question will be how I can keep my code clean and do not generate this unnecessary files. I am using asp.net MVC and VS 2019 community addition.
[
I figured those files are auto generated files. I used Visual Studio 2019 and when checking codes. I went to each suspicious files, right clicked on it. If it said 'Local file ignore' I clicked on it and it was saved in .gitignore file. This way I was able to not check-in my code.

Linking to an external www-folder - Tools for Apache Cordova (VS 2015)

For a project I'd like to use an existing website as a base for a cordova app. My project setup looks as follows:
One Solution with two projects
A ASP.NET webservice project (with website aka html/js/css)
An tools for apache cordova project
I don't want to copy the html/js/css files from the website on every build. Instead, I thought I could get away with some kind of a link to the www-folder in the ASP.NET project. I tried several approaches:
Creating a filesystem link (tried 'mklink' with parameters /D and /J - /H is not working for directories
Editing the .jsproj file and add a tag to link to the other project's www-folder
The second approach didn't work at all. Just got some weird errors when trying to load the project again (saying something about file duplicates).
The first approach worked a little bit: It is working, when targeting the windows platform. It is NOT working, when targeting iOS.
When targeting iOS, everything is copied just fine to the platforms\ios folder (read, all the content of the linked www folder is copied to the platforms\ios\www folder). But it is not copied correctly to the remote build tool on Mac OS X! It really just copies the directory link as a file. Remotebuild then failes with a 'missing www directory in top level' message.
Any suggestions how to add a link so the content is copied (instead of the actual link)?
Is there a way to take detailed influence on the build process for specific platforms?
Is there a way to create a hardlink to a directory in windows? What are the drawbacks?
I'd really like to avoid copying the files on build (which would be simple enough with a prebuild script), because there's a high risk of loosing changes made while debugging.
I'm aware that setting a link is also not the best solution, since it has to be done per machine and can't be checked in to a version control system. So, if somebody knows of a better aproach to handle my scenario, let me know.
I work on the Tools for Apache Cordova in Visual Studio at Microsoft.
I'm sorry but VS-TAC does not support add as link. To prevent confusion we removed the option in update 3.
The best solution I can give you is to copy files from one project to another. Another user asked this question a week ago and came up with a hacky solution. Please see this for more information:
VS2015 typescript cordova add as a link
Sorry for the trouble and thank you for the feedback!

Using LESS with MVC5 in Visual Studio 2013 with Web Essentials

I have installed Visual Studio 2013 with Update 2 and installed Web Essentials.
I had thought this was going to make adding LESS to my views a piece of cake, but am missing something.
The editor is great, and I imagine that it is compiling to css on save...
But I don't know where the generated css is, and I don't have any clue as to how to get it reference in my view.
I've tried a lot of searching, but can't get through the web of links about installing this and the features of that.
Any help at all will be greatly appreciated.
Thanks!
When you add a .less file and save, the Web Essentials will compile and generate the .css and .min.css files. You will see an arrow in your solution explorer, or you can also confirm in your file system that the files are in the same folder.
Haven't used less with vs2013 but I have used sass and my guess would be the same. By default the generated css gets generated in the same directory as the source (as it seemed to me) but you can check via tools>options>web essentials and there should be a set of options for less compile on save, build and directory to name but a few.
If you right click on the solution there should be an option to create a web essentials settings file for the solution - these create and adds a json file of web essentials settings to the solution which means your settings are local to the solution which could be important if you are changing the output directory.

Unable to copy file, Access to the path is denied again and again and again

I kept having this annoying thing stop me from building my project over and over again even though I searched for years on stackoverflow trying to find solution but none of those I tried works. The problem just kept coming back!
The file having problem is system.web.mvc.xml, wont let me delete even I am the administrator.
Im running MVC 5 projects.
tried to close vs 2012 first then delete files : fine for the next build but then it came back after 1 or 2 builds
tried to un-check read-only option to my entire project folder : fine for the next try but , you know.
tried to close and re-open : same as above
tried to run administrator : same as above
So anyone have really get rid of this? like ever?
Same with me..
Finally I did this trick and work for me:
Close The Solution - Close Visual Studio. And Reopen Visual Studio and solution
Copy System.Web.Mvc.dll from bin folder to new fresh empty folder, I make Lib folder under solution.
Remove read only at the dll
Remove System.Web.Mvc from project reference
Re-add System.Web.Mvc.dll (the dll copied at Lib folder)
__
Hope This Help
Regards

Resources