Auto generated code breaks
-
I have an application which was originally in VB, but when I came on board, it was on the condition of moving to C#. Everything works well, I've been doing it for months now. There's just one problem. The app uses a lot of user controls, and one control, whenever I edit in the design view, at the top of InitializeComponent method changes. It goes to this: System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailsActions)); which gives me this error: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "DetailsActions.resources" was correctly embedded or linked into assembly "RDC". The resx file is an embedded resource. If I change the code to this: System.Resources.ResourceManager resources = new System.Resources.ResourceManager("RDC.controls.DetailsActions", System.Reflection.Assembly.GetExecutingAssembly()); everyone is happy. But I've accidentally sent a broken build to my employer, within a 40 MB installer, so I'd really like to work out the core problem so it just stops happening. Christian Graus - Microsoft MVP - C++
-
I have an application which was originally in VB, but when I came on board, it was on the condition of moving to C#. Everything works well, I've been doing it for months now. There's just one problem. The app uses a lot of user controls, and one control, whenever I edit in the design view, at the top of InitializeComponent method changes. It goes to this: System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailsActions)); which gives me this error: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "DetailsActions.resources" was correctly embedded or linked into assembly "RDC". The resx file is an embedded resource. If I change the code to this: System.Resources.ResourceManager resources = new System.Resources.ResourceManager("RDC.controls.DetailsActions", System.Reflection.Assembly.GetExecutingAssembly()); everyone is happy. But I've accidentally sent a broken build to my employer, within a 40 MB installer, so I'd really like to work out the core problem so it just stops happening. Christian Graus - Microsoft MVP - C++
There can possibly be three reasons (however, in your problem, reason No. 1 below is more probable) for the problem: 1. The default resource file should be in your main assembly. When you use the following code:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailsActions));
the resources are not found in the assembly in which they are being searched. However, when you are giving the details of the assembly in which the resources are available (as well as when you are giving the full qualified path of the resource by providing “
RDC.controls.DetailsActions
”) by way of the following code:System.Resources.ResourceManager resources = new System.Resources.ResourceManager("RDC.controls.DetailsActions", System.Reflection.Assembly.GetExecutingAssembly());
the search for the resource concerned is conducted in the right assembly whose details are now available in the command
System.Reflection.Assembly.GetExecutingAssembly()
. So, basically it is a question of giving thedefault name and path
vis-à-vis thefully qualified name and path
. When you supply the fully-qualified name and path, the resource can be located, whereas with the default name and path the resource cannot be found. 2. The resource is marked as private. This is what MSDN describes: Resources marked as private are accessible only in the assembly in which they are placed. Because a satellite assembly contains no code, resources private to it become unavailable through any mechanism. Therefore, resources in satellite assemblies should always be public so that they are accessible from your main assembly. Resources embedded in your main assembly are accessible to your main assembly, whether private or public. 3. The third reason could perhaps be when you are using satellite assemblies for different cultures and when you are not providing the correct path for the resource for the particular culture being used. However, apparently this is not your problem, because your problem is getting resolved when you provide the fully qualified name and path. So, apparently the answer to your problem lies in the reason No. 1 above. To ensure that the problem does not occur, be sure to keep the resource at the appropriate place in a conscious manner and give full name and path. Regards, Ashok Dhamija _____________________________ Padam Technologies -
There can possibly be three reasons (however, in your problem, reason No. 1 below is more probable) for the problem: 1. The default resource file should be in your main assembly. When you use the following code:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DetailsActions));
the resources are not found in the assembly in which they are being searched. However, when you are giving the details of the assembly in which the resources are available (as well as when you are giving the full qualified path of the resource by providing “
RDC.controls.DetailsActions
”) by way of the following code:System.Resources.ResourceManager resources = new System.Resources.ResourceManager("RDC.controls.DetailsActions", System.Reflection.Assembly.GetExecutingAssembly());
the search for the resource concerned is conducted in the right assembly whose details are now available in the command
System.Reflection.Assembly.GetExecutingAssembly()
. So, basically it is a question of giving thedefault name and path
vis-à-vis thefully qualified name and path
. When you supply the fully-qualified name and path, the resource can be located, whereas with the default name and path the resource cannot be found. 2. The resource is marked as private. This is what MSDN describes: Resources marked as private are accessible only in the assembly in which they are placed. Because a satellite assembly contains no code, resources private to it become unavailable through any mechanism. Therefore, resources in satellite assemblies should always be public so that they are accessible from your main assembly. Resources embedded in your main assembly are accessible to your main assembly, whether private or public. 3. The third reason could perhaps be when you are using satellite assemblies for different cultures and when you are not providing the correct path for the resource for the particular culture being used. However, apparently this is not your problem, because your problem is getting resolved when you provide the fully qualified name and path. So, apparently the answer to your problem lies in the reason No. 1 above. To ensure that the problem does not occur, be sure to keep the resource at the appropriate place in a conscious manner and give full name and path. Regards, Ashok Dhamija _____________________________ Padam TechnologiesThanks for this detailed answer. There are a couple of problems though 1. This resource is created by Visual Studio, and I've never moved it 2. I do not support more than one language in my application 3. Because it's loaded in the InitializeComponent method, I am powerless to stop the IDE from changing that line of code, every time I edit the form. I'll check if it's been marked private, do you have any other suggestions ? Christian Graus - Microsoft MVP - C++
-
Thanks for this detailed answer. There are a couple of problems though 1. This resource is created by Visual Studio, and I've never moved it 2. I do not support more than one language in my application 3. Because it's loaded in the InitializeComponent method, I am powerless to stop the IDE from changing that line of code, every time I edit the form. I'll check if it's been marked private, do you have any other suggestions ? Christian Graus - Microsoft MVP - C++
What appears to me is that when the default ResourceManager method with one parameter, i.e.,
ResourceManager(typeof(DetailsActions))
is called, it is getting called in the correct assembly (i.e., "RDC") because the error mentioned by you clearly shows the name of the assembly being searched, i.e., "Make sure "DetailsActions.resources" was correctly embedded or linked into assembly "RDC"." So, when you compare the aforesaid single-parameter ResourceManager method with the two-parameters method namelyResourceManager("RDC.controls.DetailsActions", System.Reflection.Assembly.GetExecutingAssembly())
, it appears that the assembly is being identified correctly. The only problem is that the call to typeof(DetailsActions) is resulting into something like "DetailsActions
" instead of resulting into the required fully qualified Namespace / path of "RDC.Controls.DetailsActions
". So, perhaps what is required to be done is that when the InitializeComponent method of the user control is called for the purpose of constructing the embedded resources, it should maketypeof(DetailsActions)
to produce fully qualified Namespace / path of "RDC.Controls.DetailsActions
". So, I wonder whether the Namespace mentioned in the source file containing the user control can be changed to the fully qualified Namespace of "RDC.Controls....
" if it is not so already and whether it helps in solving the problem. If it does not help (unfortunately I cannot visualize your actual code), you may please try to somehow ensure that the typeof operator when run on the class of user control returns the full Namespace path. This problem might perhaps have arisen due to the user control having been initially designed in one environment and then the same being copied to a different solution leading to conflict of namespaces. As an alternative, you may also try changing the default namespace to the fully qualified namespace (if not so already) in the properties of the project containing user control. I can only hope that it works. Regards, Ashok Dhamija _____________________________ Padam Technologies