Visual Studio 2015 read commented app. setting value from web config - c#

Visual Studio 2015 read commented app. setting value from web config.
<!--<add key="test" value="1"/>-->
<add key="test" value="2"/>
I get 1 from my code.
Even if I remove <!--<add key="test" value="1"/>-->, I still get 1.
I don't have clean solution option, only build solution and rebuild solution
I rebuild solution, same issue.
I close visual studio then open again, same issue.
The problem go away after a while, I cannot pinpoint what trigger this behavior.

I believe this is because I set my project to use custom server point to http://localhost/myWebsite and it's reading value from there.

Related

Why does Visual Studio 2019 remove watch for new .razor files?

In Visual Studio Professional 2019 v 16.8, in my Blazor client's .csproj file, I have a line inside an ItemGroup:
<Watch Include="**\*.razor;**\appsettings.*" />
That way, whenever I change a .razor file, dotnet watch run will rebuild and restart the web server automatically. Great.
But now, whenever I create a .razor file in the project (such as Foo.razor), Visual Studio quite unhelpfully adds a "remove" line, such as:
<Watch Remove="Components\Widgets\Foo.razor" />
It also adds this, sometimes:
<Content Remove="Components\Widgets\Foo.razor" />
I then have to manually edit the csproj file to remove these lines. Why is it doing this, and how can I turn it off? Or is there something bigger that is wrong here? Some searching found no one else dealing with this; maybe I have something wrong with my setup?
(I saw exactly the same behavior in earlier versions.) Thanks in advance.
I have reported this issue and should be resolved at some point: https://github.com/dotnet/aspnetcore/issues/27718

The operation could not be completed. invalid pointer - Visual Studio 2015 Update 3

Getting this error when opening .cshtml file:
The operation could not be completed. Invalid pointer
Everything starts after installing update 3 and .Net Core. The mvc core app .cshtml files are opening correctly.
Please, clear the Visual Studio component cache, restart Visual Studio and retry. I suspect that you have some version conflict between components after update. The component cache is located at %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
For those who gone mad like me while trying to fix this issue, the solution for me was in web.config I've set the webpages:Version value to 3.0.0.0. Now i can open cshtml files again.
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
</appSettings>

unable to step into my local service that is in my solution

I know this has been asked before but I just cannot figure this out. I believe I have covered everything that has been brought up already but I'll cover those.
I am getting this message when I try to step into a service that is a project that is currently in my solution:
I have 3 projects in my solution:
SuburbanCustPortal <-- my website
SuburbanHub <-- my serice
WebsiteLogging <-- my logging project (no significance here)
I read that I should check the following items:
Make sure that debug is on. I have this in both of my project's web.config:
Make sure they are both using the same .net version. They are both on the .net framework 4.0.
Make sure Enable Just Your Code is unchecked:
The service is pointed to a local url:
I can pull up the service in my browser without error:
This is my settings for iis:
I have restarted visual studio, the computer and removed the service and added it back.
I cannot, for the life of me, figure this out. If I have missed anything I am willing to give it a shot.
It is very important that I get this resolved so I can get this project out this weekend so any help would be greatly appreciated.
IN RESPONSE TO Sanket Shah
I do not have the option w3wp.exe:
SOMETHING I FORGOT TO MENTION
I have set debug=true in both of my projects:
<compilation targetFramework="4.0" debug="true">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
Also, I wanted to add that I have been able to step into my service before but since coming back to the project recently, I am not able too. I have a break point on the line that calls the service and when I try to F11 in to it, I get the above message.
IN RESPONSE TO Pawel
I have tried setting symbols the follow ways and neither allowed me to step in:
I have even tried to use the Microsoft symbols:
IN RESPONSE TO Pawel #2
ADDITION INFO
I just noticed this, I'm not sure if it is related:
ADDITIONAL INFO ABOUT DEBUG MODE
I have all projects set in debug mode:
Your solution/project/settings file(s) might be / seems like it is corrupted. If you create a new solution from scratch, adding new projects which mimic your current structure, you can try and see if debugging works properly.
If that works, gradually move the code over while keeping checking that debug keeps working.
I don't know why this doesn't work.
I have a work-around for you, which you verified in the comments: add System.Diagnostics.Debugger.Break() somewhere in your service after it starts. This should pop up some sort of exception window, with a list of Visual Studio instances open. Pick the one with your solution and click OK, and it should attach correctly to that location.
Annoying? Yes. In my experience with Visual Studio, it can be very finicky sometimes about debugging into Windows services. This is the only reliable way to do it that I know about.
In addition to other answers, you can do two things:
Close your solution, delete [solution-name].suo file, reopen solution. See if your problem still persists.
Open a command prompt as admin, cd %windir%\Microsoft.net\Framework\v4.0.30319, execute this aspnet_regiis.exe -i.
In solution, have you tried to set all assemblies (client and server) to start in debug mode rather than trying to attach it after launch ? (right click on solution in the top of Solution explorer, startup, multiple startup project, choose "start" for every assembly which is an entry point : server, client, etc).
Have you tried to run only the "server" part in debug mode (the one which is not debuggable) and call it for example with soap ui ?
You should try to see if you can run it directly and debug it without the "step in" from another process, or if it also fails to load in debugger even if started directly.
FYI, if you use IIS Express it's normal you don't see "w3wp.exe", which is for IIS. You may have a iisexpress.exe process, or in some cases aspnet_wp.exe.
Don't forget to check "show processes for all users" in Debug->Attach to process window if you choose to hook on existing process rather than doing that I was saying first.
Go to Properties of the solution select Multi statup project and select all projects with start, then debug the solution.

Receiving access denied error from Visual Studio when trying to change target framework

The error reads,
TargetFrameworkMoniker: An error occurred saving the project file
'yadayada.csproj'. Access is denied.
I'm trying to switch from .net 3.5 to .net 4.0 or higher.
The project is hooked into TFS in Visual Studio 2010 (also tried VS 2013, same error). I'm in a VM environment.
Any clues about this error? Google returns very little information. It seems like I have proper access to the file, but how is VS accessing it?
It sounds like either:
1)The file has been marked read only. Check this by viewing the properties of the csproj.
Or
2)Your user does not has sufficient permissions to change the file - check security on the csproj.
I have found that if you get the error, hit save, close visual studio and reopen the project you will find that 86.5% of the time the setting was changed.
Try running the Visual Studio in administrator mode and also check if your project folder is set to read only.
Deleting everything in bin file of the starting project did it for me.
I got this error in my environment, which is straight VS 2013 Pro: no TFS and no VM. Unsetting the read-only box only changed the dialog display because reinvoking the dialog still showed read-only. I thought I changed the ownership of the project file to me by virtue of changing the ownership in a higher level directory and checking "Replace all child object permission entries with inheritable permission entries from this object." Of course the project file and everything else had inheritance turned off. Once that was corrected I was able to save things without being Administrator.
I was getting this error and it ended up being the app.config file, as well, that was write-protected. Changing the target framework not only changed
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
in the .csproj file but also changed the project's app.config:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
(I wanted to add this as a comment to pixelmeow's Jun 27 answer, but StackOverflow policy prevents me from doing so until I have enough reputation points. I did vote for him/her, though!)
I was getting this error and it ended up being the app.config file that was write-protected. Once I cleared the read-only property, everything worked fine.
I was getting this error in visual studio 2010 because of my start action setting. Each time I would hit debug, I think the browser window was trying to launch too fast (this is an ASP.NET MVC 4 with intranet settings project).. and I would randomly, sometimes consistently get access denied. So I changed the start action to: "Don't open a page. Wait for a request from external application."
And this seemed to fix the issue. You will just have to access the web application manually rather than VS launching the browser for you. You can click on the running server icon (bottom right of taskbar) and access the link from there if you don't remember it or your browser didn't store it as a history url for whatever reason.
I just encountered this error message in my Visual Studio 2022 Solution after updating to Version 17.1.5. I managed it to run again by closing VS and deleting/renaming the bin and obj folder. Restarting VS and the debug session ran without trouble.

Execute code only on localhost (when developing)

I do MVC app, I have few lines of code I would like to exucute only when I'm developing, and another, similar part of code when the application is deployed.
for example I have controller action that sends mail to some address, but I would like that adress is different when I am deploying and testing.
It is hard to change it always, and I often forget to do that.
Visual Studio provides a number of ways to do this, and which method you want to use depends on what exactly you want to do.
For example, you can use build targets to specify which type of build you want, Release and Debug are common, but you can also create others. You can then add #if pre-processor statements in your code to do things depending on which build is selected.
Another method, which sounds like what you want, is to use App Settings in your app or web.config. Then use the build transforms to transform your config based on the type of build (you will see a Web.Debug.config or Web.Release.config for instance. When you publish your site, Visual Studio will automatically apply these tranforms to your config files and change the app settings to whatever you want for that build type.
So, using your example, you would have this in your Web.config:
<appSettings>
<add key="notifyAddress" value="debug#foo.com" />
</appSettings>
Then, in your Web.Release.config you have this transform:
<appSettings>
<add key="notifyAddress" value="release#foo.com"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</appSettings>
In your code you have:
string emailAddress = ConfigurationManager.AppSettings["notifyAddress"];
Now, when you publish your site, emailAddress will automatically have release#foo.com.
see if this helps: https://stackoverflow.com/a/4597270/1043824. The recommended way will still be the config file approach.
In Visual Studio 2010, Request.ServerVariables("SERVER_SOFTWARE") will return Nothing (null) for the Development Server, and "Microsoft-IIS/7.5" for my Win7 Pro IIS/VS2010 installation.

Categories