Solved

GuiD Conflict

Posted on 2013-11-12
2
397 Views
Last Modified: 2013-11-14
I have a questioon on Guid Whether the same Guid can be used from 1 application to another or will it cause any Build Issues.

Since there are 2 applications(app1 and app2) that almost behave in similar functionality. I have used this code below to create another application but this Guid remains constant which I am afraid if I run app2 it will create a promblem in app1. Is that the case...

OR is it the public class Name that I need to change to avoid any name conflict.. Need advise

namespace MobizSalesApplication
{
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    [Guid("69D98FE7-90D6-4597-9476-8EABC68739E5")]
    [ComVisible(true)]
    public interface INAVClient
    {
        string DealerRetrieve(string User_Cred, string alldet, string Amt);
        string WarehouseRetrieve(string User_Cred, string alldet, string Amt);
    }

    [ComVisible(true)]
    [Guid("160601f8-3b38-4735-b4f8-8fc6bf48a601")]
    [ClassInterface(ClassInterfaceType.None)]
    public class NAVClient : INAVClient
    {
        //List<string> det;
        //List<string> custflddet;
        //string bday;
        //string anvday;
        List<string> line_items = new List<string>();
        string XMLResp;
        public NetworkCredential crytography(string UserName, string Password)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bytedata = System.Text.Encoding.ASCII.GetBytes(Password);
            byte[] hash = md5.ComputeHash(bytedata);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            string pwdmd5 = sb.ToString().ToLower();

            StreamWriter UserStreamWriter = new StreamWriter(@"C:\InTouchAutomationLogFiles\usrDetails.txt", false);
            UserStreamWriter.WriteLine(pwdmd5 + "--" + UserName + "--" + Password);
            UserStreamWriter.Close();

            return new NetworkCredential(UserName, pwdmd5);
        }


        public string WarehouseRetrieve(string User_Cred, string alldet, string Amt)
        {
            try
            {
                string WarehouseUrl = @"http://wildcraft.bizom.in/warehouses/add?calltype=api&username=wildcraftnav&password=wildcraft";
                string[] det = alldet.Split('^');
                string WarehouseData_XML = String.Empty;
                string[] user = User_Cred.Split(',');
                using (StringWriter SW = new StringWriter())
                {
                    using (XmlTextWriter XTW = new XmlTextWriter(SW))
                    {
                        XTW.WriteStartDocument();
                        XTW.WriteStartElement("Warehouses");
                        XTW.WriteStartElement("Warehouse");
        
                        XTW.WriteElementString("erp_id", det[1]);
                        XTW.WriteElementString("zone_id", det[2]);
                        XTW.WriteElementString("name", det[3]);
                        XTW.WriteElementString("address", det[4]);
                        XTW.WriteElementString("state", det[5]);
                        XTW.WriteElementString("city", det[7]);
                        XTW.WriteElementString("state_id", det[6]);
                        XTW.WriteElementString("taxno", det[8]);
                        XTW.WriteElementString("jurisdiction", det[9]);
                        XTW.WriteElementString("tnc", det[10]);
                        XTW.WriteEndElement();//end of Warehouse
                        XTW.WriteEndElement();//end of Warehouses
                        XTW.WriteEndDocument();

                    }
                    WarehouseData_XML = SW.ToString().Replace("utf-16", "utf-8");
                }

                StreamWriter Vouch_writer = new StreamWriter(@"C:\MobizSalesAppLogFiles\" + user[0].Replace(".", "_") + "_WarehouseAdd.txt", true);
                Vouch_writer.WriteLine("----New----");
                Vouch_writer.WriteLine(User_Cred);
                Vouch_writer.WriteLine("-------------");
                Vouch_writer.WriteLine(WarehouseData_XML);
                Vouch_writer.Close();


                XmlDocument resp_XML = new XmlDocument();
                resp_XML.LoadXml(this.ReturnPostUrl(WarehouseUrl, WarehouseData_XML, User_Cred));



                StreamWriter WarehouseIDResponse = new StreamWriter(@"C:\MobizSalesAppLogFiles\" + user[0].Replace(".", "_") + "_ResponseOfPost.txt", true);
                WarehouseIDResponse.WriteLine("-----New----");
                WarehouseIDResponse.WriteLine(User_Cred);
                WarehouseIDResponse.WriteLine(DateTime.Now.ToString());
                WarehouseIDResponse.WriteLine("------------");
                WarehouseIDResponse.WriteLine(resp_XML.InnerXml);
                WarehouseIDResponse.Close();

                if (resp_XML.GetElementsByTagName("is_absolute")[0].InnerText == "true")
                    return resp_XML.GetElementsByTagName("coupon_value")[0].InnerText;
                else
                    return resp_XML.GetElementsByTagName("coupon_value")[0].InnerText + "%";



            }
            catch (Exception ex)
            {
                StreamWriter AddDealer_Exception = new StreamWriter(@"C:\MobizSalesAppLogFiles\Warehouse_Error.txt", true);
                AddDealer_Exception.WriteLine("----New1----");
                AddDealer_Exception.WriteLine(User_Cred);
                AddDealer_Exception.WriteLine("-------------");
                AddDealer_Exception.WriteLine(ex.ToString());
                AddDealer_Exception.WriteLine(ex.Message + "message");
                AddDealer_Exception.WriteLine(ex.StackTrace + "stacktrace");
                AddDealer_Exception.WriteLine(ex.Source + "source");
                AddDealer_Exception.Close();
                return "";
            }
        }

Open in new window

0
Comment
Question by:Moizsaif123
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39646117
If you are applying a GUID to classes that are COM visible, then the GUIDs need to be unique between the classes.  If two assemblies use the same class, then they can have the same GUID.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39646540
GUID is a Global Unique Identifier. It the same thing as a social security number. It's a way to uniquely identify something in order to differentiate 2 things that have the same name. A given GUID should never be reused for something else. You defeat the whole purpose of GUIDs if you do so.

Part of systems that use GUID use it instead of the class name to identify it. If you use it for 2 classes, the system might sometimes use class1 while you are expecting class2, and vice-versa.

With COM, you might have problems registering your 2 classes with the same GUID. I haven't worked with the registry for years, but it used to be that you could not register 2 classes having the same GUID. The second one you registered just override the registration of the first one.

And unless you have a good reason to do so, you usually do not provide the GUID through the GuidAttribute. Look at the documentation: "Only use an explicit GUID when a type must have a specific GUID. If the attribute is omitted, a GUID is assigned automatically."
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question