Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Jan 18, 2012

Find and open a file in Visual Studio.

I remember that a collegue of mine used that a lot. I forgot it so I will just post it here so anyone (including me can benefit of it).

In order to find a file / class in Visual Studio - use the "Find In Files" toolbar combobox. You will however need to write a magic word before it starts searching, just type "> of" before the file name, like "> of User". VS will help you with some of the files that contain this name:



Hope this raises a bit more of productivity out there.
If you need more - you may want to try Telerik Just Code ;).

Jul 14, 2011

Application suddenly becomes slow

I experienced this while I was developing my application in Visual Studio.
It happened for no apparent reason (I didn't remember to make any signifficant changes in this application).

It was really frustrating. The thought that I may need to rething the whole application was a nightmare.

I was in panic and started to think what the problem for this sudden degradation might be.

And guess what?
It appeared to be because of a conditional breakpoint I have set in one of the complex modules.

The program flow was passing through this line of code hundreds of thousand of times so Visual Studio was kind of slow determining if the condition for the breakpoint is true or not.

So remember this for the rest of your life:
"Conditional breakpoints may slow your application considerably, before doing stupid things in case of sudden performance degradation - be sure to remove your breakpoints first (Debug Menu => Disable All Break Points), then check the performance again.".

Jun 28, 2011

Visual Studio AddIn - never put dots in a command.

I was following an article on how to create a command and add it to the Code Window context menu, it was going really well until some point.

I ran the code and Visual Studio was crying with E_INVALID_ARGS error on the

this._applicationObject.DTE.Commands.AddNamedCommand

This one is widelly used and pretty standard method so I thought the problem is somewhere in my code.

I realized that almost all the parameters I am passing to this method are pretty common as well so the problem must be at ....

Well, the command name I used was containing dots, that's why the error.
If you receive this message, please check the command name for dots (the second parameter you are passing to this method).

Since Visual Studio and other addin types seem to be working with very similar framework (the so called "extensibillity framework"), I suspect this rule is also applicable for other types of addins such as Outlook, Excel, Word, etc.

May 23, 2011

Silverlight 4 - catching uncaught exceptions from external components

I was playing with an external component in Silverlight 4 and got an unhandled exception while debugging.

The problem was that I wasn't able to see what's going on because the debugger won't show anything (it doesn't have the source of the exception) and because the exception was triggered internally in event in the component trying to catch it to see what is the exception had no effect as well.

Then I opened the App.xaml file and found the following:

if (!System.Diagnostics.Debugger.IsAttached)

Pretty neat, huh? :).
The method signature was as following:
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)

All I needed to do now was to put a breakpoint on the if statement and then expect the ApplicationUnhandledExceptionEventArgs.ExceptionObject to see what the exception was.

Thought you may have some hard times debugging problems with Silverlight.

May 19, 2011

Tip : how to identify which dll to reference?



I had a bad experience today.
I was moving a project from one PC to another, it was referencing dlls from my old PC.

I started to remove references one by one and adding them again, this time from a common location.
I missed on of them (deleted it from the project without first remembering which one it was).

So lesson number one - you can create a screenshot before deleting the references so you can restore them later.

But here is how I did I found the reference I needed (in my case I wasn't quite sure in which assembly was the RadWindow for Silverlight):

1. Go to your project and open some of the files the control resides.
2. Open the Toolbox (View => Toolbox).
3. Find the control in the toolbox and drag it to the design surfice.

In most cases Visual Studio will create a reference to the correct dll.

May 10, 2011

Server Explorer is not responding in Visual Studio 2010 (as well?)

 

imagesCAZWHD7Q

 

I think this problem was present in the previous versions of Visual Studio as well, anyway, here is what happens:

1. You have some connections / servers in Visual Studio 2010 Server Explorer.

2. Something changes for example server was renamed / removed, or a connection no longer works, not quite sure what exactly should happen…

3. When you try to select the server or connection in server explorer in order to delete it, you get the Hourglass icon, you can’t do anything and waiting doesn’t help.

 

To resolve this, as I found in Google you may want to try this (Windows 7):

1. Close ALL instances of Visual Studio

2. Go to “C:\Users\your_user\AppData\Roaming\Microsoft\VisualStudio\version\ServerExplorer”

     Where your_user is your user and “version” is the version of Visual Studio, in my case, Donchev and 10.0.

3. Delete the file “DefaultView.SEView”.

Note: You may want to just edit the file, removing or changing problematic connections, I wanted my Server Explorer reset so I deleted the entire file, it is faster and safer.

May 6, 2011

Coding Practice : Always refresh the 2nd Visual Studio Solution :).

I had a problem with some code in a Visual Studio, the errors were something like when you have a missing file, or a missing method or stuff like that.

They were happening all the time and I was wondering what is going on.

The problem was that I was having 2 Visual Studio instances running with different solutions loaded in them, I was coding in the first solution and touched a shared project (.csproj).

The second Visual Studio asked me to refresh. I answered no and the old code was in the Visual Studio #2.

To overcome this, you may:

1. Always answer “Yes” to the refresh dialog (bad practice) as you may forget sometimes or accidentally click “No”.

2. Click refresh on the solution file in the second visual studio (bad solution, it is a bit slow and you may forget to do this).

3. Go to Options –> Environment –> Documents –> and check the following checkboxes:

   3.1. Detect when file is changed outside the environment (check).

   3.2. Auto-load changes, if saved : (check)

I will go with approach #3 and see if it has some shortcomings as I can’t think any right now.

A screenshot bellow shows the exact settings:

image

Aug 9, 2010

Being more productive with command aliases in Visual Studio 2010

We all know we are trying to cut the mouse usage to the lowest possible rate (are we getting back to DOS)?

I think it is easier to hit few keystrokes instead navigating through 4-5 levels of menus.

So here is a nice article on the Commands window usage in Visual Studio that may help you run faster through this:

Understanding Commands: Aliases

Apr 28, 2010

Nice productivity feature in Visual Studio 2010

I really like this multiline manipulation that comes out of the box with Visual Studio 2010:



I think it will really speed the development. Especially when refactoring old code with lots of lines that need to be manipulated in the same way.

By the way I am sure JustCode team will come out with lots of cool features based on this one ;)

Jan 22, 2010

Working faster with Visual Studio 2008 website

I just wanted to share with you that you can actually start using the page and debug before all the actions that are known as a build are performed by Visual Studio 2008.

You can actually skip the "Validating WebSite" part.
Here is how I do it:

1. Hit Build button
2. View -> Output window
3. Watch the output window, when it says "Validating website", check out your Errors List (View -> Errors List).

Seems that Visual Studio will know the errors in your website / projects in the solution, before it finishes validating the website itself. It simply waits the validation to finish in order to popup this window.

If there are no errors - you can start debugging the site.
If there are - you can press CTRL + Break to stop validating the web site and fix the errors.

Jan 19, 2010

Unexpected fatal error -- Not enough storage is available to process this command. While building a project.

It is very strange error.
Anyway - if you experience it - deleting the events from the Application event log solved it for me should work for you to ...

Jan 7, 2010

The access to the path bin\ is forbidden exception while building - Visual Studio 2008 and TFS

I had this strange error yesterday and it took me some time to understand what is going on.
It appeared that the bin folder of the main project is under source control, so TFS was locking the folder, the subfolders and the files.
In order to resolve it - checkout the bin folder in Visual Studio and then build.
The build should be OK.
Then you can Undo Changes on the folder and everything should work as it was before.

Hope this helps someone ...

May 20, 2009

Some casing problems I experienced.

As far as I understand, the settings for the code format are in the following Visual Studio menu:

Tools -> Options ->Text Editor

There you have the ability to change things.
I was having some problems reguarding the way my markup is formatted (few of the tags are made lowercase when I hit CTRL + K + D (format whole document)).
So I think the settings for this should be under the HTML -> Format, or the whole path for the menu should be :

Tools -> Options ->Text Editor -> HTML -> Format

I then checked the "Server Tag:" dropdown. It says "Assembly definition", the other options are "As entered", "Lowercase", "Uppercase" but I don't like them :).
Now the issue comes when I have a radGrid with <ClientSettings> or <PagerStyle> sections. To me they must be in Pascal notation (as all other sections and properties), but when I hit CTRL + K + D they are re-formatted to be lowercase.
The issues may be in
1. The telerik assembly itself.
2. Some AddIn conflicts.

It is not a big issue, just decided to share with you.
Please share your thoughts if you faced such issues.

May 15, 2009

Visual Studio Tips & Tricks 1- Re-register the controls in the .designer.cs file (recovering .designer.cs file)

Okay, I suppose all of you know what the .designer.cs file is, but I will shortly explain...

When you add a control to the page (via the markup editor), this control is also registered in the .designer.cs file, so you can have a reference to it in the code behind class (.cs).
So if you have a page Test.aspx, you will have a group of 3 files in it:

1. Test.aspx - this is the markup code, containing HTML and ASP markup, defining the control, css and so on.
2. Test.aspx.designer.cs - the designer file, where all controls are registered as a variables so you can reference them,
3. Test.aspx.cs - the code behind where you add your code. There you can use the controls, referencing them by the ID you gave them in the markup.
What happens behind the scene is that each runat="server" control is registered as a variable in the designer class like this:

protected global::System.Web.UI.WebControls.DetailsView dvMine

I recently did the following mistake - after added a lot of controls, then a lot of code, and a lot of changes to other files, I accidently got the latest version of the designer file (from the source control) of one of my aspx pages. This way I was having the controls markup, but the control registrations were lost. I wasn't able to CTRL + Z until I got my things back as I had already closed / opened the Visual Studio few times.

As a result When I hit F5 to start in debug mode, I got about 20 compilation errors, stating that I am referencing objects that don't exist.
I didn't want to re-register those controls manually in the .designer.cs, neither to delete them in the markup and re-create them (thus registration in the .designer.cs file will be automatically created).

I was wondering what to do, so I finally got the idea. I hit CTRL + K + D (which should reformat your markup) and the missing controls were auto re-created in the .designer.cs file.

Hope this helps someone out there.

Apr 23, 2009

Operation could not be completed message when trying to open Linq to SQL (dbml) designer

That was really strange.

The annoying Operation could not be completed error message appeared each time I tried to open the dbml designer.

I did some search and found that I need to start the Visual Studio 2008 Command prompt and type the following command:

devenv/resetskippgs

But this didn't helped a lot. The annoying message was still appearing.
Then I found something which made me laugh. It was so unexpected...
If you had the same problem and the devenv/resetskippgs couldn't resolve it, try going to Control Panel -> Administrative Tools -> Event Viewer.
Select the Application node and right click it. Then delete all events.

This would hopefully resolve your problem.

Funny isn't it?

Oct 21, 2008

C# AddIn - Start Debugging and get the running Internet Explorer instance.

I needed to do this (actually I wanted). I was curious if you can obtain an instance of a Internet Explorer which was started in debugging session. Here is a snipet to do this:

        _applicationObject.Debugger.Go(
false);
        SHDocVw.
ShellWindowsClass windows = new ShellWindowsClass();
        
foreach (SHDocVw.InternetExplorer explorer in windows)
        {
          
if (explorer.LocationURL == string.Empty)
           {
            
// this is our guy!
             ie = explorer;
           }
        }


Note : this snipet should be added somewhere where you have access to the _applicationObject.
This is the variable which is declared automatically when you create new instance. I suggest you to put it into the exec method of the AddIn:

     public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
     {
        _applicationObject.Debugger.Go(
false);
        SHDocVw.
ShellWindowsClass windows = new ShellWindowsClass();
        
foreach (SHDocVw.InternetExplorer explorer in windows)
        {
          
if (explorer.LocationURL == string.Empty)
           {
            
// this is our guy!
             ie = explorer;
           }
        }
     }

You also need to add reference to ShDocVw (Microsoft Shell And Automation Library).
Enjoy!

Jul 25, 2008

Nice TFS Query

I needed to find all my tasks I had closed, but I hadn't added time input for.
I was thinking how can I sort all my TFS tasks to achieve this and it appeared to be very strightforward.

Here is what you should do:

TFS Query to get all closed tasks without working hours.

In other words you are saying :

Your new TFS query will look like this.

"Give me all the work where the completed work is 0 hours, the state is closed and it is assigned to me."

After you save and give a name to your TFS query, you will find it under the "My Queries" node in your Team Explorer window:

>

Jul 17, 2008

Code Policies - the first step to get rid of boring code policy violations is made.

As I and Vesko (only!) discussed - it is great to follow code policies, and they are saving time. A lot of time. I agree.
I really like to have so strict policies at work so I can find for example the ObjectDataSource of some dropdown, without knowing its name. For example i will type "objDsSomething" or "odsSomething" or "ODSSomething". It really saves time.

I don't really agree with Vesko's opinion that only in the begining you are violating the code policies. I think even developers who worked on the same project for year will violate its policies (not so often offcourse).

The problem is that we are all human beings and we all make mistakes. I decided to do something to help myself get rid of at least the boring code policies - such
as naming conventions.
Here is what I have so far (I started this thing few days ago and I am working on it for about an hour daily after I was all day at work so it may not look very promising but I think it has potential):



When you click on "Validate Current Document" the document which is currently open will be validated against predefined naming conventions. If you violated something you will have this output:



I have few more problems to solve and will be really glad if someone can point me the direction:

1. I need to find a way to add this menu to the context menu for the document and also I would like to add hot key so you can for example validate the document by pression "CTRL + V + D" or something else (this is low priority).
2. I would also like to be able to check the code itself for inadequate assignments, method calls and so on. The CodeModel approach I think, will not allow me to do so.
3. I would like to change those standard icons with custom ;) (low priority).

Currently this thing can fly only for naming conventions.