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 9, 2011

Very old stuff – convert System.Drawing.Color to HTML.

When I was with Delphi, I wrote utility to do this myself (I mean Delphi in its early days) as I wasn’t aware for built-in mechanism to achieve that.

Now with .NET there is utility to do this for you but I often forgot which class has static method to convert System.Drawing.Color to Html string.

Here it is:

System.Drawing.ColorTranslator.ToHtml(color)

I think wouldn’t it be smarter to have an extender attached to System.Drawing.Color to do this for me from now on … :).

May 6, 2011

Have WCF Service hosted on windows service.

This one is quite old, anyway, as I am using my blog for adding notes to myself as well, I will repeat the solution so I can later find it :).

Maybe you will find it useful as well.

To host a WCF service on top of Windows service you need to do the following:

1. Create the windows service that will host the WCF Service.

2. In the windows service add references to the following assemblies:

2.1. System.ServiceModel

2.2. System.ServiceProcess.

3. Declare the following in the Service class:

ServiceHost host = null;

4. In the OnStart method of the service, instantiate the host variable and the WCF Service instance:

protected override void OnStart(string[] args)
{
    if (host != null)
    {
        host.Close();
    }


    SomeService.ServerAgent server = new SomeService.ServerAgent();
    host = new ServiceHost(server);
    host.Open();
}

5. We need to handle Service stop as well, add the following code to the OnStop method of the Windows Service:

protected override void OnStop()
{
    host.Close();
    host = null;
}

6. All we need to do now is to set some bindings / endpoints. NOTE: They should go to the app.config file of the WINDOWS service. Just copy them from the WCF Service web.config.

You are done.

Install and start the windows service and navigate to the Url Address you added as endpoint. You should be able to browse it.

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

Having column display name in RadGrid Column chooser but not in the header of the grid

A little bit of background for this one.

I had a Telerik RadGrid that was having few columns ...

It had the column chooser enabled. Few of the columns were icons (for example “Answered”, “Rating”).

I wanted to have them without header text so I added the Template column and everything was just fine.

Until I right clicked on the header in order to show the column chooser. It was displaying the columns with auto generated names like “GridTemplateColumn7”, “GridTemplateColumn10”.

My goal was to keep the header of the grid clean (e.g. no label) because the icons were 16x16 and that’s all the space I needed to occupy with those columns, having a header “Answered” would extend the entire column. So to solve this case here is what I did:

Solution:

1. Added header text to the column and saw that the header text is appearing in the column chooser.

2. To hide it from the header of the column I added an empty <HeaderTemplae>.

The column should look like this:

<telerik:GridTemplateColumn HeaderText="Bookmark">
    <HeaderTemplate>
    </HeaderTemplate>
    <ItemTemplate>
    </ItemTemplate>
</telerik:GridTemplateColumn>

 

This would solve the problem for Template columns (and all column types that allow you to define HeaderTemplate). This will not work for GridBoundColumn for example as this type doesn’t have HeaderTemplate.

 

Hope this helps someone out there …

Apr 17, 2011

Unable to start debugging on the server.

Lot's of such errors, lots of resolutions.
I had another one, the full message is:

Unable to start debugging on the server. An authentication error occured while communicating with the web server. Please see Help for assistance.

It looks like it is an issue with permissions but the problem is that I disabled the "HTTP Keep-Alive" signals for the web site.

Hope this saves few minutes of research ;).

Feb 2, 2011

Copy XmlNode from one XmlDocument to another

This one is more for the archive, but it is not widelly used so you may not know it.

In case you need to copy XmlNode from one XmlDocument to another, you need to do two things.

1. Import the XmlNode from the source XmlDocument to the target XmlDocument, using Import(XmlNode node, bool deep) method of the target node,
2. Get the result from this method (it is XmlNode) and use AppendChild method of the node that should be parent of the node to be transfered.

In other words:
XmlDocument sourceDocument = new XmlDocument();
XmlDocument targetDocument = new XmlDocument();

sourceDocument.LoadXml("");
targetDocument.LoadXml("");

XmlNode nodeToImport = sourceDocument.SelectSingleNode("//nodes/sourceNode");
XmlNode importedNode = targetDocument.ImportNode(nodeToImport, true);
XmlNode parentTargetNode = targetDocument.SelectSingleNode("/nodes/targetParentNode");
parentTargetNode.AppendChild(importedNode);

is enough to import the sourceNode with all its child nodes under the targetParentNode of the target document.

Jan 21, 2011

Limit Microsoft SQL server memory usage

I had to work with a fairly large database on my PC.
It became very unresponsive so I checked what's going on.
I clicked on the Performance tab in Windows Task Manager and noticed that the RAM was more then 7 GB (too much for a personal computer, don't you think?).

I realized that 4 of those 7 GBs were used by the MSSQL server.
I went to management studio, right clicked the server and choosed options.

Then I clicked on the Memory page and saw that MSSQL Server was allowed to take up to 2048 TB of memory (couldn't even imagine that):

I limited the server to 1 GB and my PC was healthy again (the queries I do may take a bit longer but at least my ALT + TAB key combination is working again :).

Limit MS SQL Server memory usage.


Simple thing that improved my experience a lot.

Nov 5, 2010

The status code returned from the server was: 12031

If you checked anything on your mind about this code, it may be because of StackOverflow exception rised within your code / or in .NET which is less possible.


Just to let you know as it happened to me ;).

Oct 23, 2010

Rad Ajax controls Q3 2010 is now live!

Just a quick post to let you know that you can download and play with the Q3 2010 version of Telerik's Asp.Net AJAX controls.

What's new:
1. RadTreeList, a control that is hybrid, combining treeview and a list view.
2. RadButton - inherits the functionality of LinkButton, Button and ImageButton and ads more such as the abillity to combine text and image, toggle modes and more. Combined with rich client side API.
3. RadCalendar now has long anticipated feature - the range selection will allow you to select date ranges.
4. Multi month view with postback enabled.


And many more.
Visit Stefan Rahnev's blogpost or the Telerik Labs for more details on the beta.

Oct 12, 2010

Internet Explorer 8 difference between CTRL + R / CTRL + F5 / F5 and enter in the address bar.

I see there is some difference.
We are currently having issue under IE in our site and we noticed that using any of the combinations will casue the Facebook Button to disappear.
If you click in the address bar and then click enter you will see the facebook buttons appear.

Very strange behavior.

Sep 14, 2010

A program in Fortran :)

I am blogging from my university :).
In case you need to write a program in Fortran to calculate the length of a line between tow points, there it is:

program otsechka
implicit none

integer::p1x, p1y, p2x, p2y
real:: resultX, resultY
real::finalResult

write(*,*)'P1 x : '
read(*,*)p1x
write(*,*)'P1 y : '
read(*,*)p1y
write(*,*)'P2 x : '
read(*,*)p2x
write(*,*)'P2 x : '
read(*,*)p2y
resultX = p2x - p1x
resultY = p2y - p1y
! ** 2 is to the power of 2.
finalResult = Sqrt((resultX ** 2) + (resultY ** 2))
write(*,*)finalResult
end

Nice, huh ;).

Sep 9, 2010

It's time to vote again!


It is again time to vote for your best tools in the software development.
Don't waste time, showing some love to one vendor or another will help that vendor push harder in the right direction.

So click on the image and show some love to your favorite vendor.

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

Jul 19, 2010

Site is recycled + ThreadPool.QueueUserWorkItem


Just to let you know that you may experience this issue.

If you have an unhandled exception it may be because of a job queued using ThreadPool.QueueUserWorkItem method.

Actually it appears that although the exception is not affecting the main thread (it was in another one) - the .NET will kill the running process (w3wp in our case).

As far as I read this behavior is implemented since .NET Framework 2.0.
It is because you may miss unhandled exceptions in a child thread (if it's in the main thread the process will be terminated in a windows application).

I imagine each request to a web server as a separate thread so I am kind of worried why unhandled exceptions aren't killing the W3WP process as well.
It only seems to be killed if you create another thread in the request thread and this another child thread exits with unhandled exception.

Will need to investigate a bit more about that.

Jul 14, 2010

Q2 2010 is comming!


Telerik RadControls for Asp.Net Ajax and



Telerik Extensions for ASP.NET MVC are released.


See this post for more information on the cool new things included!


Enjoy!

Thread was being aborted. Exception on Response.Redirect()

This is actually an old issue but I try to make sure I have most of the things that stopped me at some point so I can easilly search.

So if you experience the "Thread was being aborted." exception on Response.Redirect(string Url), it is because this method internally calls Response.End().

In order to prevent it to do so, you will need to use the overloaded version that requires another boolean parameter (something like "bool endResponse", don't remember it exactly).

So the thing that should solve it is:

Response.Redirect("http://donchevp.blogspot.com", false);
This way you should avoid "Thread was being aborted.".

Hope I helped a bit ...

Jul 8, 2010

Go download Telerik Ultimate collection trial!

We have the Ultimate collection uploaded @ telerik.com.
You can reach it by using the green "Download"button at the top of the page.



Included in the bundle you will find:

1. RadControls for ASP.NET AJAX
2. Extensions for ASP.NET MVC
3. RadControls for Silverlight
4. RadControls for WPF
5. RadControls for WinForms
6. Telerik Reporting
7. Telerik OpenAccess ORM
8. JustCode
9. JustMock
10. WebUI Test Studio Dev Edition

Direct link to the page: http://www.telerik.com/download.aspx

Hope you like the new download page.