Problems with localizing source code

Hello,

I'm now trying the Add-In in Visual studio .net on a sample application and I am having a similar problem to the one I had with my own application (difference is that sample program is in c# and my own in c++). When I try to translate messages in the source code, I get errors.

In the sample app, when I select and translate a message in the Add-In and it changes the code, I get the error:
"The type or namespace 'Resources' does not exist in the namespace 'Microsoft.VisualStudio.Samples.TextEncoding.EncodingApplication' (are you missing an assembly reference?)"

In my original code ML_STRING (in the MlString.cpp added by the Add-In) wasn't recognized and caused an error.

So how could I get the source code localization working?

Thank you in advance.

Helena Paakkola

And I included the .cs file, in which I have tried to translate. The MessageBox row now looks like:
MessageBox.Show(EncodingApplication.Resources.File_does_not_exist_Please_try);

Germany

I think the code is in principle correct, but unfortunately ambiguous.

The code is

MessageBox.Show(EncodingApplication.Resources.File_does_not_exist_Please_try);
If you look in the resource code file Resources.Designer.cs, you can find the following code:
namespace EncodingApp {
...
    internal class Resources {
...
        internal static string File_does_not_exist_Please_try {
            get {
                return ResourceManager.GetString("File_does_not_exist_Please_try", resourceCulture);
            }
        }
    }
}
The identifier EncodingApplication.Resources.File_does_not_exist_Please_try is equivalent to (namespace).(class).(property).


However, the namespace in the C# code file is
Microsoft.VisualStudio.Samples.TextEncoding.EncodingApplication

The compiler seems to interpret EncodingApplication as a short version of Microsoft.VisualStudio.Samples.TextEncoding.EncodingApplication, which is incorrect. There may be some way to remove this ambiguity, but I don't know it. (In C++ you could prefix it with ::, but I don't think that works in C#.)

The namespace used in the file Resources.Designer.cs is taken from the Default namespace defined in the project settings.

Image

You can fix the problem by:

  • Changing the default namespace to something non-ambiguous, for example EncodingApp.
  • Changing the default namespace to Microsoft.VisualStudio.Samples.TextEncoding.EncodingApplication.


In either case, you will probably have to edit the code already added by the Add-In, e.g.

MessageBox.Show(EncodingApp.Resources.File_does_not_exist_Please_try);
but after restarting the Add-In it should use the modified namespace correctly.


Best regards
Phil


Yes, that was the problem.

Thank you! :-)