Be careful when you are naming the Silverlight Class Library!!

Do you know why? because there are some limitations that you can’t use when you are naming Silverlight Class Library. It happened to us. We named one of our Silverlight Class Libraries with “.Resources” postfix. Then, we got a lot of trouble. I’m not sure whether you guys are aware of this “by-design” issue or not. We got a lot of headaches when we are implementating the localization for WPF and Silverlight project. We have spent around 1 or 2 days just to solve this problem.

Here is the steps to reproduce the issue.

  1. Create Silverlight Application (e.g. SilverlightApplication4 ) with web project attached.  (both Silverlight 2 or Silverlight 3)
  2. Add Silverlight Class Library and named it “ABCDE.Resources”  <Note: This is very important.>
  3. Add the following method in Class1.
    public static string Foo(){
    return "Foo";
    }
    
  4. Add ”ABCDE.Resources” as a reference in SilverlightApplication4.
  5. Go to Page.xaml.cs
  6. Add the following line in constructor.
    Console.WriteLine(ABCDE.Resources.Class1.Foo());
    

Error:

Could not load file or assembly ‘ABCDE.Resources, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.

I got that error and also, I found that “ABCDE.Resources” assembly is not getting generated in Silverlight. So, I reported this issue in WPF/Silverlight Insider List. What I heard from Microsoft is that this is by-design issue. Silverlight’s application activation logic treats this with special meaning – it recognizes such an assembly as a satellite resource assembly. Then, I tried to reproduce the issue  just like the way that we used in our project without using any code but just resx file.

Here is new steps to reproduce the issue.

  1. Create Silverlight Application (e.g. SilverlightApplication4 ) with web project attached.  (both Silverlight 2 or Silverlight 3)
  2. Add Silverlight Class Library and named it “ABCDE.Resources”  <Note: This is very important.>
  3. Add new resx file (Let’s call it “Strings.resx”)
  4. Change “Access Modifier :” to Public
  5. Add new string to that resx file “Strings.resx”
    e.g: (Name: YourMessageStringInResx, Value=YourMessageStringValueInResx)
  6. Go to Code-behind of that resx file “Strings.Designer.cs” and change private constructor to public. (why? yes. this is another issue. )
  7. Go to Page.xaml.cs
  8. Add the following line in constructor.
    Console.WriteLine(Strings.YourMessageStringInResx);
    

Then, run the application. I’m sure that you will get the same error. I’m still waiting the response from Microsoft for that issue and I will update this post as soon as I get one. As of now, the only solution for this issue is that don’t name “.Resources” for your class library and use other name like ABCDE.Languages or ABCDE.Rex or etc.

Hope it helps.

Hpa An, Kayin State

Hello everyone!! I hope you all are doing well. Yes. I’m back!!! I was on long vacation and was very far away from Internet for two weeks so that a lot of mails are waiting for me. anyway, let’s forget about works and mails for now and let me upload some of my cool photos that I have taken.

Here is the first one.

kyauk-kan-latt-mom-me-and-my-wife

This is my mother, me and my wife (yes. I got married. I will post some of our wedding photos in next post. Please wait for a while, okay? ).  The Pagoda at our back-side is called Kyauk Kan Latt Pagoda which is located in Hpa Ann, Kayin State. It was my first time visiting there but I did enjoy a lot. That place is beautiful and so green.  and…. lot and lot of fresh air. :)

Please click on the link below to see more photos ~~

Continue reading