views:

129

answers:

2

I have an existing application that I'm supposed to take and create a "mini" version of. Both are localized apps and we would like to reuse the resources in the main application as is. So, here's the basic structure of my apps:

MainApplication.csproj

/Properties/Resources.resx

/MainUserControl.xaml (uses strings in Properties/Resources.resx)

/MainUserControl.xaml.cs


MiniApplication.csproj

link to MainApplication/Properties/Resources.resx

link to MainApplication/MainUserControl.xaml

link to MainApplication/MainUserControl.xaml.cs

MiniApplication.xaml (tries to use MainUserControl from MainApplication link)

So, in summary, I've added the needed resources and user control from the main application as links in the mini application. However, when I run the mini application, I get the following exception. I'm guessing it's having trouble with the different namespaces, but how do I fix?

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

FYI, I know I could put the user control in a user control library but the problem is that the mini application needs to have a small footprint. So, we only want to include what we need.

A: 

The Resources generated by visual studio are not public, they are only visible to classes within a library. in order to generate resources as public properties you will need to use a custom generator like this: http://www.codeproject.com/kb/dotnet/ResXFileCodeGeneratorEx.aspx

Shrage Smilowitz
Ya, I knew to make the resource public (Custom Tool == PublicResXFileCodeGenerator). But that made me think of something else. There is a CustomToolNamespace property on the resource file. If I set that to "MiniApplication" on the resource link, it generates a Resources1.Designer.cs file and it works. Since the resource file is a link, it also puts the new Designer file in the MainApplication directory tree. But, I guess that's ok.
bsh152s
+1  A: 

You are correct that the different namespaces are the problem. A resource file cannot be given a namespace, it will take the namespace of the folder that contains it. If the namespaces across your two apps are different, the namespace will be different.

I can see three options available to you

  1. Use the same default namespace for both applications
  2. Have an assembly purely for your resource file and reference that in both apps
  3. In the code loading the resource, generate the namespace based on the namespace of the class that's loading it
pdr
Ok, I thought I had it working. I have set the Custom Tool Namespace to the MiniApplication's namespace for 2 different resources. In one instance, the tool creates a separate designer with a "1" appended to it (UserContro1Res1.Designer.cs) so it works because each application has a separate designer with different namespaces. But, in another instance, the original linked designer is overwritten with the MiniApplication namespace. When this happens, the MainApplication fails to build because it doesn't (and shouldn't) know anything about the MiniApplication namespace.
bsh152s
Yeah, option 1 will only work if you use the same default namespace throughout both apps.
pdr