Search code examples
c#.netresx

How to stop the resx file in my dll(reference) from being used in my main project?


So I have two projects, Tester and Coder. I've added the Coder.dll in my Tester project as reference, the issue is that both these projects have their own 'SetUp.resx' files for setup and for some reason the Tester project is using the 'SetUp.resx' file of Coder instead of its own SetUp.resx file.

 Coder has a string Name "browser" whose values are "Chrome, Firefox"
 Tester has a string Name "browser" whose value is "Chrome"

As shown above, The "Browser" value is used for making the tests, so in Coder there will be two test cases i.e, "Chrome and firefox" And in Tester there should be only one test, i.e, Chrome but it still shows 2 tests (Chrome and Firefox) which shows that its taking the SetUp.resx from Coder.dll

This is how the SetUp.resx file looks like in Tester

    Name    |          Value        |Comments   
    Browser |         Chrome        |Browser to be tested with separated by Comma
 BuildNumber|          v2.1         |aka version
       

This is what I've done for SetUp.Designer.cs in Tester

        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal SetUp() {
        }
        
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestProject3.Configurations.SetUp", typeof(SetUp).Assembly);  //Path of Tester's SetUp.resx
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
        
 internal static string BuildNumber {
            get {
                return ResourceManager.GetString("BuildNumber", resourceCulture);
            }
        }
              
         internal static string Browser { //Gets string value for Browser in SetUp.resx
                    get {
                        return ResourceManager.GetString("Browser", resourceCulture);
                    }
                }
    }

This is the code for the function accessing the resx

internal static IEnumerable Browsers()
    {

        get
        {
            String[] browser = Configurations.SetUp.Browser.Split(",");
            foreach (string b in browser)
           {
                yield return b;
            }
        }
    }

Could someone please tell me where I went wrong and what should be changed in my code?


Solution

  • I tried to find a way that uses the filepath of the resource file so tester doesn't get confused with the coder's resx.

    internal static IEnumerable Browsers()
        {
            var enviroment = System.Environment.CurrentDirectory;
            string resxFile = Directory.GetParent(enviroment).Parent.Parent.FullName + @"\Configurations\SetUp.resx";
            
            String[] browser;
            IDictionaryEnumerator dict;
            string key;
            using (ResXResourceSet resSet = new ResXResourceSet(resxFile))
            {
                dict = resSet.GetEnumerator();
                while (dict.MoveNext())
                {
                    key = (string)dict.Key;
                    // Retrieve resource by name.
                    if (dict.Key is "Browser")
                    {
                        browser = resSet.GetString(key).Split(",");
                        foreach (string b in browser)
                        {
                            yield return b;
                        }
    
                    }
                }
            }
        }