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.