Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!

Michael Sync is currently working as a Senior Software Engineer in Singapore. He like to explore new things and always wanna work with cool technologies. He is currently focusing on Microsoft Silverlight and Astoria (ADO.NET Data Service). He used to spend his free time for learning the latest technologies and helping others in Silverlight forum and Codeproject forum. Michael has posted 18 posts at DZone. You can read more from them at their website. View Full User Profile

Did you know? - Silverlight Class Library can’t be named with “.Resources”

05.04.2009
Email
Views: 3706
  • submit to reddit

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. view plaincopy to clipboardprint?
    public static string Foo()
    {
    return "Foo";
    }
    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. view plaincopy to clipboardprint?
    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. view plaincopy to clipboardprint?
    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.

References
Published at DZone with permission of its author, Michael Sync. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

lucas hal replied on Tue, 2009/06/09 - 1:22pm

My name is lucas, I have started my edveture with bookmakers 2 years ago.Since this time I have won around 100 000 usd. Would You like do same?? Think about Sports betting and change Your life. Nice post Regards

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.