The C# code formatting in Xamarin Studio (i.e. when hitting Ctrl-I to format the document) puts end of line comments onto a new line. I can't find any way to change this in the C# code formatting policy settings. How to change this to preserve end of line comments on the same line?
For example, take this code:
public class Foo
{
int bar; // comment
}
If I hit Ctrl-I (or alternately click Edit > Format > Format Document from the menu, or select the code and click Edit > Format > Format Selection from the menu), the code is reformatted as:
public class Foo
{
int bar;
// comment
}
I'm using v4.2.2 build 2 v4.3 build 52 on OS X.
Note: it seems this is a bug. So my question really is -- has anyone who has also encountered this come up with a fix or workaround and if so what is it?
I don't think there is a real answer to this question, as you have said its a bug in the version you are using.
UPDATE: We have discovered that this is not a bug in the software. As it affects all versions the OP updates to, most likely there is some setting or extension affecting the outcome.
A work around although you may not be to happy with it would be to place you comments above the line in question. This is a perfectly acceptable way of code-commenting.
public class Foo
{
// comment
int bar;
}
Using version 4.3
Pre Ctrl + I
Post Ctrl + I
As a final note you may want to view your code formatting preferences found here:
UPDATE 1
You could try resetting all your preferences by deleting everything in the following folders, see here.
I will add that I haven't tried this so could break your installation.
Just tested and this doesn't break Xamarin Studio and does reset all preferences.
~/Library/Preferences/XamarinStudio-4.0/
~/Library/XamarinStudio-4.0/
UPDATE 2
The only last thing you can try as we have found out this isn't a bug in the software but something on your computer. Is to do a full removal of Xamarin Studio. I recommend using AppCleaner as it will search for any related files and remove them.
Onces it has fully uninstalled, then reinstall Xamarin Studio.
UPDATE 3
Last solution, try creating a new user account. Run Xamarin Studio under that account to see if the problem persist. If it does the only thing left to do is a fresh install of OS X and reinstall Xamarin Studio first. The problem should be gone now... reinstall all other applications checking that nothing has broken Xamarin Studio after each install.
This has been acknowledged as a bug by Xamarin. See this bug report. In that report, Xamarin says it's replacing its entire formatting engine as of mid-2014, with the hope of having it in place by "next year." Xamarin further suggests avoiding the problem by turning off auto-formatting on save, suggesting there is no official fix or workaround at this time other than avoiding the issue.
Related
In my C# course, I noticed I received docked points for my project not having code change history. After looking around, I couldn't figure out what it was about. I'm using Visual Studio 2019 Enterprise with no external plug-ins. My professor has also not mentioned anywhere on our course site about installing extra features, so I assumed this change history for code would have been a build in feature to reduce students from being required extra setup.
All I've actually found in VS itself is a window called "History" under View > Other Windows, however, that is empty and shows no indication of allowing me to use it. Hopefully this isn't considered a duplicate post considering the few other "change history" questions that only resulted in 3rd party or extra installation features; I don't think those are what I need here. My professor lists the need for code change history, yet I can't seem to figure out how to do that with the IDE itself, which is the only software we're expected to work with.
Am I just at a loss of assignment points on this one?
If you are using a version control system then each check in / commit should have a description of the change.
Before we used version control systems (over 20 years ago) we had a section at the end of the source file with comments for each change made, which version and date.
If I was a professor I would not expect the students to send me their code, I would ask them to put their code in a repo such as git and then send me a link to the repo.
I often get blue question marks on files in my VS2012 Solution Explorer when opening a solution bound to Perforce through P4VS.
Looks like something is having trouble to "synchronize" with the depot/workspace/whatnot. Hitting "Refresh View" always solves the issue but I'm growing tired on doing this everyday:
This is my VS version:
Microsoft Visual Studio Professional 2012
Version 11.0.61030.00 Update 4
And P4VS:
2014.1.85.4506
This is persistent across P4VS versions for a few months now, and seems to be affecting sometimes individual files, sometimes entire projects, with no apparent pattern.
How can I diagnose what's going wrong, be it a server issue, a VS issue, a workspace issue?... The Perforce Source Control output shows nothing special.
Actually it's not entire folders, it's entire projects. It appears that even if refreshing a project "fixes" the issue for one run, re-opening the solution brings it back. Whereas I think that for individual files, refreshing them solves the issue once and for all. I'll play with it a bit more to confirm that.
To help diagnose what is going wrong you should probably turn on logging, and check the preferences that will show everything in the output window. For the P4VS log, go to:
Tools- > Options -> Source Control -> Perforce - Logging
(This is not the same thing as the Visual Studio Activity log.)
There could be a possibility that you are getting disconnected and refresh reconnects you. I am not sure if you have your connection set to use solution-specific settings, since you did not mention the connection dialog coming up.
This "solved" the issue for me, at least for the entire projects that went blue-question-marked:
1) Tools > Options
2) Source Control
3) Perforce - General
4) Tick the option "Treat Solution/Project as directory when
selected"
Not sure why but that's one less annoyance for me every day. Thanks to Perforce support for suggesting that.
The file is probably not marked for version control. I noticed this icon in one file and opened Perforce to check. For whatever reason, this file was not marked for add in Perforce. After marking the file for add and submitting, the blue question mark went away.
When typing multi-line comments Visual studio used to add an automatic asterisk to each new line of the comment as I press enter(apparently 2015 does not do this anymore). I really liked this. As of right now though, if I type "/*" and enter, Visual studio does not try to autocomplete it at all. In fact, it even lets me end the comment with "*/", too, instead of doing it for me. So my question is: is anyone else experiencing this? How do I get the original functionality back, so each new line is automatically prefixed with an asterisk, and closed for me by "*/"?
I already checked and yes, my environment settings are set to C# and yes the option "Generate XML documentation comments for ///" is indeed checked in my settings.
This is a well-known problem, the feature fell by the way-side in the Roslyn refactoring of the C# Editor Features. Nothing to do with config or a change of preferences, it simply was not implemented.
It is currently being tracked by this Github issue. Status is "Up for grabs" right now with nobody having shown an interest in grabbing it yet as of today. Afaict, best to not hold your breath for it, I think they have several bigger fires to put out. It will surely be delivered in an update sooner or later.
Just wanted to update and say that this problem was apparently fixed(sort of) in one of the newer updates of Visual Studio. The editor still does not complete the comment for you, but it does at least keep the formatting consistent, and adds an asterisk to the next line for you.
Additional info: I thought it might be helpful to say that my forms and classes are in the same solution as the already updated forms.
In our company we have this project which 3 people are working on it. One works on the database part, me and another colleague of mine are working on making the UI ready and relating it to database which is MS SQL Server 2012 and we are programming in C# in VS 2012.
The problem is that I made this one form ready, but the server version is ahead of me. That is, if I check in the whole program, I will damage the project as some forms has changed and the version I have is older. I tried right clicking and checking in only the forms and classes which I, myself made and I have their latest version. They check in without any error or anything, but the problem is, when my colleagues or myself(after deleting my source project) try to get latest version, my forms or classes doesn't show up.
We also tried to check in the whole program but only accept those pending changes which are made by me, still no success.
The problem is, we are kinda afraid to play with the server version as a lot of effort has gone into it.
Any help will be really appreciated as I'm stuck with this problem and the manager won't give me more parts of the program to make until we can come up with some way to deal with this.
You haven't mentioned merging at all but I think this is the answer to your question.
When you work on an older version of the code (because your local code is older, or maybe the whole branch of the code is older), you need to merge the code into the newer version. When you merge, any potential conflicts are detected and you can resolve all of them manually. There's obviously tools to help you - one is built into Visual Studio but you can replace it with an external tool which may work better for you. Either way, you need to decide how to merge the code. You have a few options:
take the whole code from the source (old code in this case),
take the whole code from the target (new code in this case),
merge the changes and take bits from each version based on your knowledge of the changes and how the code should look like.
As for why the forms don't show up, you probably didn't check in the changes to the project file so the new files are not part of the project as it exists in Team Services.
I have the following code in a view model:
public Point Location
{
get
{
var rangePixels = Range * PixelsPerMile;
var xCoordinate = OwnLocation.X * MapScale + rangePixels * Math.Cos(Theta);
var yCoordinate = OwnLocation.Y * MapScale - rangePixels * Math.Sin(Theta);
return new Point(xCoordinate, yCoordinate);
}
}
One of the usings at the top of the code file is System, which contains Math.
If I view Math.Sin(Theta) in the Watch window (by selecting the code, right clicking, and choosing "Add Watch"), I get the following error:
The name 'Math' does not exist in the current context
What I want to know is:
Is this expected/default behavior for Visual Studio 2010? I could swear this never used to be a problem, but maybe it's always worked that way and I somehow never noticed.
If it's not normal to get this error, any thoughts on what the problem could be? There are a million settings in Visual Studio, and I wouldn't know where to begin.
I should note this question is vaguely similar to this, but I'm not having any issues mousing over my local variables, and I'm not using PostSharp.
Edit
I just tried resetting all my Visual Studio settings backs to default, and I'm still getting the same error. If someone wants to try a simple test in Visual Studio, I just want to know if you get an error if you add a watch for Math.Sin(1).
Edit 2
Here are a couple screen captures to show what I'm experiencing:
Edit 3
Interestingly, intellisense works if I type Math. into the Watch window, but if I complete the expression, I still get the error:
Edit 4
To address BACON's questions:
I get the same behavior with QuickWatch and Immediate.
Closing and reopening all the windows does not solve the problem.
I'm using Visual Studio 2010 Professional (version 10.0.40219.1 SP1Rel)
I tried targeting .NET 4.0 Client Profile and full .NET 4.0. Made no difference. I created a Console App (rather than a WPF app) targeting .NET 4.0 Client Profile, and finally, the error did not occur. So, WPF may be an issue (or WPF with some third-party libraries). (Will check on that next.)
It appears that the culprit is a third-party library that performs IL weaving (Fody.PropertyChanged).
If I create a new WPF project without this library, I'm able to use Math.Sin() in the Watch window. Once I install PropertyChanged, I start getting the "not available in this context" error.
Thanks to #BACON for leading me down the right path to figuring this out.
Here's a link to an issue I posted on the PropertyChanged site:
http://code.google.com/p/propertychanged/issues/detail?id=6&thanks=6&ts=1330494634
Edit
And subsequently, it turns out this is probably a bug in Mono-Cecil, which PropertyChanged uses:
https://github.com/jbevain/cecil/issues/90
I did this in a litte test app, in the constructor..
Trying to put a watch on Math lets me see the values of E and PI.
You cannot put one on Sin.
Putting one on val works just fine.
So, no, I don't think that it's quite normal, unless you clicked on the wrong name. I.e., not the variable, but the "Sin" portion...
Here is where I highlighted the entire thing...