Problem with "Copyright ©" symbol in AssemblyInfo.cs RRS feed

  • Question

  • We have a tool to auto update FileAssembly version in AssemblyInfo file. It only supposes to touch this attribute, however, after the text updated and write back into the file, it changse the symbol in Copyright to some Unicode as well.

    For example it change "Copyright ©" into "Copyright �"

    It seems to be simple but I still couldn't figure out a way to avoid this.Can someone have other idea or a better way to update the version?


    Here is a block of my codes:

                                 foreach (string file in files)
                                    //string allText = File.ReadAllText(file);

                                    string allText;
                                    using (StreamReader reader = new StreamReader(file, Encoding.UTF7))
                                        allText = reader.ReadToEnd();
                                        Regex regex = new Regex(attribute + @"\(""\d+\.\d+\.\d+\.\d+");

                                        //Search for the first occurrence of the version attribute
                                        Match match = regex.Match(allText);

                                        //when found
                                        if (match.Success)

                                            string replaceMatchTextWith = "";
                                            if (!replaceMatchTextWith.Equals(match.Value))
                                                string newAllText = regex.Replace(allText, replaceMatchTextWith);
                                                //File.WriteAllText(file, newAllText);
                                                using (StreamWriter writer = new StreamWriter(File.OpenWrite(file)))



    Thursday, June 21, 2012 8:40 PM


All replies

  • Why are you using Encoding.UTF7?  If you use UTF8, it should prevent this from occurring.

    Reed Copsey, Jr. -
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, June 21, 2012 9:00 PM
  • Hi Reed, thanks for replying, i try both but it didn't give the same symbol:

    - Using UTF7:

               "Copyright ©" to "Copyright ©"

    - Using UTF8:

                "Copyright ©" to "Copyright �"

    Any thought?


    Thursday, June 21, 2012 9:06 PM
  • The default code page in VS is Encoding.Unicode.  That should leave your data alone, and preserve the copyright symbol.

    Reed Copsey, Jr. -
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, June 21, 2012 9:17 PM
  • Unbelievable, when i change it back to Encoding.Unicode, and trying to debug, all the text in "allText" variable above set to Chinese characters, lol:

    獵湩⁧祓瑳浥刮晥敬瑣潩㭮਍獵湩⁧祓瑳浥刮湵楴敭䌮浯楰敬卲牥楶散㭳਍獵湩⁧祓瑳浥刮湵楴敭䤮瑮牥灯敓癲捩獥഻ഊ⼊ 敇敮慲湉潦浲瑡潩扡畯⁴湡愠獳浥汢⁹獩挠湯牴汯敬⁤桴潲杵⁨桴⁥潦汬睯湩⁧਍⼯猠瑥漠⁦瑡牴扩瑵獥‮桃湡敧琠敨敳愠瑴楲畢整瘠污敵⁳潴洠摯晩⁹桴⁥湩潦浲瑡潩൮⼊ 獡潳楣瑡摥眠瑩⁨湡愠獳浥汢⹹਍慛獳浥汢㩹䄠獳浥汢呹瑩敬∨牁楴獮景⹴楗摮睯⹳潆浲≳崩਍慛獳浥汢㩹䄠獳浥汢䑹獥牣灩楴湯∨⤢൝嬊獡敳扭祬›獁敳扭祬潃普杩牵瑡潩⡮∢崩਍਍⼯匠瑥楴杮䌠浯楖楳汢⁥潴映污敳洠歡獥琠敨琠灹獥椠桴獩愠獳浥汢⁹潮⁴楶楳汢⁥਍⼯琠佃⁍潣灭湯湥獴‮䤠⁦潹⁵敮摥琠捡散獳愠琠灹⁥湩琠楨⁳獡敳扭祬映潲਍⼯䌠䵏‬敳⁴桴⁥潃噭獩扩敬愠瑴楲畢整琠牴敵漠桴瑡琠灹⹥਍慛獳浥汢㩹䌠浯楖楳汢⡥慦獬⥥൝ഊ⼊ 桔⁥潦汬睯湩⁧啇䑉椠⁳潦⁲桴⁥䑉漠⁦桴⁥祴数楬⁢晩琠楨⁳牰橯捥⁴獩攠灸獯摥琠佃്嬊獡敳扭祬›畇摩∨挹㈵㈵ㅡ㠭㘲ⵦ㐴㈰㠭昰ⴸ㑣㑢户愷ぢ㘱⤢൝ഊ⼊ 敖獲潩湩潦浲瑡潩潦⁲湡愠獳浥汢⁹潣獮獩獴漠⁦桴⁥潦汬睯湩⁧潦牵瘠污敵㩳਍⼯਍⼯†††慍潪⁲敖獲潩൮⼊ ††䴠湩牯嘠牥楳湯ഠ⼊ ††䈠極摬丠浵敢൲⼊ ††删癥獩潩൮⼊യ⼊ 潙⁵慣灳捥晩⁹污桴⁥慶畬獥漠⁲潹⁵慣敤慦汵⁴桴⁥敒楶楳湯愠摮䈠極摬丠浵敢獲ഠ⼊ 祢甠楳杮琠敨✠✪愠⁳桳睯敢潬㩷਍慛獳浥汢㩹䄠獳浥汢䍹浯慰祮∨牁楴卮景≴崩਍慛獳浥汢㩹䄠獳浥汢䍹灯特杩瑨∨潃祰楲桧⁴₩〲㜰㈭㄰‰牁楴卮景⹴䄠汬删杩瑨⁳敒敳癲摥‮潐瑲潩獮䌠灯特杩瑨ꤠ䴠捩潲潳瑦䌠牯潰慲楴湯∮崩਍慛獳浥汢㩹䄠獳浥汢偹潲畤瑣瑁牴扩瑵⡥䄢瑲湩潓瑦₮楖畳污䈠獡捩唠杰慲敤䌠浯慰楮湯⤢൝嬊獡敳扭祬›獁敳扭祬牔摡浥牡⡫∢崩਍慛獳浥汢㩹䄠獳浥汢䍹汵畴敲∨⤢൝嬊獡敳扭祬›獁敳扭祬敖獲潩⡮㐢ㄮㄮ㔰㤱〮⤢൝嬊獡敳扭祬›獁敳扭祬楆敬敖獲潩⡮㐢ㄮㄮ㔰㤱〮⠠牔湵⸴⸱〱ㄵ⸹⤰⤢൝嬊獡敳扭祬›獁敳扭祬湉潦浲瑡潩慮噬牥楳湯∨⸴⸱〱ㄵ⸹∰崩਍

    Thursday, June 21, 2012 9:20 PM
  • You can use the StreamReader's override constructor function with the detectEncodingFromByteOrderMarks parameter to true to detect the encoding first as this page told you:

    Then use this encoding to operate the chars in the file.


    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by garynguyen Friday, June 22, 2012 5:37 PM
    Friday, June 22, 2012 6:28 AM
  • Mike, beautiful, it works as charm.

    I first need to check the encoding of the file (as your provided link), then use StreamReader/Writer with that encoding to read and write in/out of the file.

    Thanks. I'll mark as answer.

    Friday, June 22, 2012 5:37 PM
  • You're welcome, I'm glad to hear that you problem is solved!

    Have a nice day!

    Mike Zhang[MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 25, 2012 3:44 AM