Smartkid's binary life

博客园 联系 订阅 管理
  10 Posts :: 1 Stories :: 24 Comments :: 0 Trackbacks


The unit test in Visual Studio has a bug:
AppDomain.CurrentDomain.BaseDirectory always returns the installtion directory of the visual studio 2008 instead of the 'Out' directory.

So if your code have to access data files deployed to the 'Out' directory using relative path, error occurs.

A workaround is:

        public static GetApplicationBaseDirectory {
if (AppDomain.CurrentDomain.FriendlyName.StartsWith("UnitTestAdapterDomain_")) {
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

return AppDomain.CurrentDomain.BaseDirectory;

posted on 2008-06-29 02:53 Smartkid 阅读(...) 评论(...) 编辑 收藏