0

I'm trying to load one of Microsoft's own resource files so that I can use values contained within in an extended SearchBox web part.

My code to load the resource file is as follows:

Assembly searchAssembly = System.Reflection.Assembly.Load(
    "Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");

ResourceManager s_rmLocStrings = new ResourceManager(
    "Microsoft.Office.Server.Search", searchAssembly);

However, I get the following error:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Microsoft.Office.Server.Search.resources" was correctly embedded or linked into assembly "Microsoft.Office.Server.Search" at compile time, or that all the satellite assemblies required are loadable and fully signed.

Microsoft.Office.Server.Search.resx (and it's localised version) are both in the app_globalresources, so I think I'm just referring to the resx in the wrong way.

2

You could use the regular way of using string resources from SharePoint. Try the following :

SPUtility.GetLocalizedString("TheResourceKey", "TheResourceFile", (uint)culture.LCID);

That way, you will be able to get any resource key from any resource file!

  • That approach is one of the others I looked at but ultimately not the one that solved my problem (posted below). – Neil Richards Nov 22 '10 at 21:22
1

So I solved it by using Reflector to see how Microsoft loaded their own assembly and did the following:

Assembly.GetExecutingAssembly();
AssemblyName name = null;
name = Assembly.Load("Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c").GetName();
name.Name = "Microsoft.Office.Server.Search";
AssemblyName assemblyRef = new AssemblyName();
assemblyRef.Name = name.Name + ".Intl";
assemblyRef.Version = name.Version;
assemblyRef.SetPublicKey(name.GetPublicKey());
assemblyRef.CultureInfo = CultureInfo.InvariantCulture;
Assembly assembly = Assembly.Load(assemblyRef);
s_rmLocStrings = new ResourceManager(name.Name, assembly);

The part that stuffed things up I think is the ".Intl" which has got to be assembly-specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.