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.

One thought on “Be careful when you are naming the Silverlight Class Library!!

Leave a Reply

Your email address will not be published. Required fields are marked *