Tuesday, December 30, 2008

Loading Satellite Assemblies From Custom Path

One thing that distracted me in default localization technologies in .NET was that  culture-specific folders are placed on one level with executable file. So if binary files lie in the root of application folder, as a result en-US, ru-RU and other folders are mixed with something like Data, Resources and others. Not good layout of folders.

By default .NET searchs for dependendent assemblies in directory of executable file in and in GAC. But developer can specify additional directories in exe.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="./Lib" />
        </assemblyBinding>
    </runtime>
</configuration>

There are some limitations: no absolute paths and no walking up the directory tree ( ..\Lib will not work). Recently I've tested this for satellite assemblies and I have found that frameowork searchs in provided directories for satellite assemblies. So I can make something like that:

Main.exe
Main.exe.config
I18N\en-US\Main.resources.dll
I18N\ru-RU\Main.resources.dll

However as I've mentioned if I move Main.exe to Bin directory this will not work correctly. I know 2 possible ways to override this:
  1. codeBase element in config file, but it requires absolute path
  2. Adding handler for ApplicationDomain.AssemblyResolve event which will return whatever you want.

Friday, December 26, 2008

WPF Application Doesn't Load Resources in IDE

While working with WPF application I've experienced a problem: library assembly requests resource from System.Windows.Application which is defined in executable assembly in XAML file and this resource isn't loaded while I work in IDE! If I debug application all works fine, but XAML designer doesn't load resource, library method fails and window isn't rendered in designer. Of course I still can work with pure XAML and mostly I do so, but I prefer to have an ability to quickly watch results of my work in designer. So to workaround this problem I changed failed method so he will return not fully correct value which will not depend on application resources.

Wednesday, December 24, 2008

Google Chrome Can Prevent JavaScript From Generating Dialogs

Google Chrome has a wonderful feature: if one element in web page call one JavaScript function multiple times from them second time Chrome adds a checkbox to stop future dialogs to appear.

This is a very handy feature because some pages may generate infinite number of dialogs and because it locks browser you couldn't close tab with it (at least in Firefox). The only way to deal with such a problem in FF is to close the whole application. And if it setted up to load pages from previous session on start you could have some problems! Of course there are still possible ways to prevent browser from loading this page again but it will require an extra effort.

Monday, August 25, 2008

Enum as a ComboBox.ItemSource in WPF

Currently I'm working on my first project with WPF and study it on a practice. In this short article I want to give example how in XAML make ComboBox list values (or names) of enum.

ItemsControl.ItemsSource uses IEnumerable as source of items to list in ItemsControl (which ComboBox is derived from). In C# you can do this very simply:

comboBox.ItemsSource = Enum.GetNames( typeof( Dock ) );

You can do the same using only XAML:

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="ItemsSource test" Height="70" Width="150" WindowStyle="ToolWindow">
<Window.Resources>
<ObjectDataProvider x:Key="DockNames"
MethodName="GetNames" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type Type="{x:Type Dock}" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<ComboBox Margin="5" Width="120" Height="23" Name="comboBox"
HorizontalAlignment="Left" VerticalAlignment="Top"
ItemsSource="{Binding Source={StaticResource DockNames}}"
SelectedIndex="0">
</ComboBox>
</Grid>
</Window>

In this sample ObjectDataProvider is a wrapper for a method call and to assign this data provider to ItemsSource binding is used. As you can see XAML version of requires more lines of code. But it is usefull if development team strictly follows the rule that interface view must be defined in XAML without code on C#.

Wednesday, July 16, 2008

Setting Type of Paper in Docbook

Some months ago I was setting up Fop on my computer and found that Docbook XSL converts files from Docbook to Fop format with setting paper to USLetter while I need A4 paper. I didn't knew how to set type of paper for XSL, spent much time exploring Docbook XSL and as a result changed something in them and get paper format A4. I don't remember what I have done but it worked. However I needed to format disk of that computer so lost this settings.

After some digging I found that setting type of paper is very simple: to XSL transformator send parameter paper.type with value of you paper type. If you use Fop and runs it with docbook file and XSL transformation in commandline arguments specify: -param paper.type A4.

Monday, July 14, 2008

Firefox 3 Instant Crashes

I use Mozilla Firefox as my browser. I started from version 2, when I migrated from Opera because it wasn't supported by some Google web applications. Version 2 frustrated me with periodical freezes - they lasted for about 30 seconds and then FF came back to live. Now I'm using FF 3. There was a lot of buzz about it. I found that it has some new valuable features that still keep me from downgrading to FF 2. But FF 3 on my computer crashes several time per day. At first it was happening at notebook with Vista. So I had some suggestions that this are the problems with OS. But I found that these crashes happen on desktop computer with XP. Moreover recently I reinstalled OS on notebook and firefox crashes on almost "clean" OS also.

I don't use any *not very popular* extensions. Even more - I disabled them all, but FF 3 continue to crash. May be I should disable some plugins? I don't know. And I didn't heard any significant buzz about "FF crashes on my PC every hour!" so I come to conclusion that these are problems with my environment (Russia, ISP, some software on PC, anything else). But Opera works finely. So I have three ways:
  1. With great patience continue to use FF 3
  2. Downgrade to FF 2 (remember the buzz "downgrade to XP from Vista")
  3. Use another browser: Opera, Maxthon, IE, Safari.
But... I've been waiting for FF 3 and wanted to use it. And now I found it to be a big piece of crashes for me.

Simple (and funny in some way) recursy in C#

While recent work with reflections in .NET I found a funny way for recursion:

using System;

namespace ConsoleApplication1 {

class Program {

static void Main(string[] args) {
Program p =
new Program();
Console.WriteLine(p.Property);
}

public String Property {
get {
Console.WriteLine(
"Getting property, counter {0}.", counter++);
return (String)this.GetType().
GetProperty(
"Property").GetValue(this, null);
}
}
int counter = 0;
}

}
Getter of property gets PropertyInfo of itself and calls GetValue method.

Thursday, June 19, 2008

Firefox 3 — am I the only one who is disappointed?

Firefox 3 was released yesterday and there was a great buzz about it. Mozilla announced special "Download day". As I have read there was about 7.5 million downloads of FF yesterday. I've started using it from Beta 6. And I have to say that I couldn't share the joy about FF of others. No, I don't speak new features: they are good and I love new address bar which search not only through addresses but also through titles of pages. I'm speaking about FF bugs. FF crashes regularly on my computer. Most of problems occur on AJAX sites like GMail or Todoist after closing the tab with this site (though it doesn't crash always after closing this site). It seems that this is one error which causes crashes on my computer.

Another issue happened with bookmarks: at one day FF deleted all my bookmarks (I don't remember but may this already happened to me with FF 2). In itself this isn't a dramatic problem: FF creates daily backups of bookmarks and I also have done them in JSON format. But... FF refused to restore backup and said there is an error. Luckily final release of FF 3 was able to import my bookmarks :).

There are also some other issues with Internet (some pictures are not loaded from first few attempts and some pages also) but I'm not sure they are caused by FF because it seems other browsers also suffer from it.

But the bug with GMail really disturbs me. May be it is caused by any specific setting or software on my computer but I've made some new clean installs of FF and this didn't helped. And FF after crash doesn't say something meaningful about the reason of error: if it is caused by any plug-in or extension why not say this me so I'll disable it?

In coclusion I have to say that FF 2 had some really disturbing bug: sometimes it became frozen and doesn't respond to my actions but after about half a minute it came bake to normal work cycle. It seems in FF 3 this bug is fixed. But... it also seems that some new bugs came into it. So now I use Prism to work with GMail and Todoist. But Opera with it's new release 9.50 gets a new chance on my computer :)

Monday, May 26, 2008

NAnt over MSBuild

While working on my C# projects I found it useful for me to start using a build tool. Visual Studio builds assembly files, but many other tasks such as generating documentation are not part of assembly build and can not be just added to "pre-build" and "post-build" actions. So I've decided to use NAnt.

After some working with NAnt I decided to try MSBuild. There were some reasons for that: MSBuild is a part of .NET Framework so there is no extra dependencies; moreover it provides a good integration with project files generated by VS. But after a day of converting my NAnt project to MSBuild I've decided to return back to NAnt. There a plenty of reasons for that, which I found during this day.

The most important (for me) is that almost all settings to MSBuild tasks are set through attributes. The question "What to use: attributes or elements?" is long living and still doesn't have a clear answer (e.g. see this and this articles), but I found it a little inconvenient to set up all parameters of task through attributes. I won't speak here about what as I think should be element or property, but properties with long length data doesn't look good (e.g. lists of files).
In NAnt I feel very comfortable with setting tasks up through elements and attributes and in most cases I think that type of XML node is chosen right for property. And what is more NAnt provides and ability to define in custom tasks to define what property should be: attribute or element, while MSBuild follows it's convention and all properties are set up through attributes. Quite inflexible, though it removes a headache of deciding of type of node.

Secondly writing long lists or properties is a little inconvenient in VS: I prefer to have lines of code not very long and I need to write attributes on several lines. And if I press Enter after a property on a new line VS doesn't suggest me a list of possible items. It is need to start typing on previous line and press Enter only after writing property in editor. Of course I can write all in one line and use Wrap lines ability of text editors, but I prefer not to do so.

All-in-all I've returned to NAnt as a build tool. Sometimes I write additional tasks for it (those that are not in NAnt.Contrib) which gives me an ability to use not only for application builds but for other purposes.

Links:

Wednesday, April 23, 2008

RescueTime

For a month I'm using a web-based application RescueTime. It counts the usage of software and websites on computer so you can find which application you use the most. What is more RescueTime provides ability to assign tags to applications to group them, and to assign efficiency score to each tag. It draws some diagrams shiwing your efficienty so it's much easier to find out whether your are doing something useless to your or perform a productive tasks. And moreover in RescueTime you can create goals on using software, e.g. "Spend less than 1.5 hours per day on games." or whatever can be interpreted as "use something less/greater than..."

I think RescueTime is rather an interseting application that could help better manage time spent with computer.

Saturday, March 29, 2008

MyMiniCity.com

On site www.myminicity.com everyone without registration can start its own minicity. Though there aren't many ways to control your city: the only thing you can do is to post links to the page with your city. Each visit of page increases population of city. As with city growth some new features appear: Industry, Transport network, etc. Each has its own link to invest in development of this city infrastructure. As a result city from small village can grow to the big megapolis.

That's my mini city: http://kaaglecity.myminicity.com/

Thursday, March 20, 2008

I'm in the Internet again!

Hurray! After moving to new flat I've finally connected to the Internet again. I have a lot of work now but hope soon I'll continue to write to my blog.