本文介绍了c#中的System.Guid问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当用户登录后用户我复制网址并关闭浏览器。打开相同的浏览器粘贴网址运行应用程序我收到此错误: 无法使用转换 object 类型' System.Guid'键入' System.String' 这是我的代码: DataTable dtMenu = new DataTable(); DataSet ds = new DataSet(); XmlDataSource xmlDataSource = new XmlDataSource(); xmlDataSource.ID = XmlSource1; xmlDataSource.EnableCaching = false ; dtMenu = GetMenuTable(); ds.Tables.Add(dtMenu); ds.DataSetName = 菜单; ds.Tables [ 0 ]。TableName = 菜单; DataRelation relation = new DataRelation( Parentchild,ds.Tables [ 菜单]。列[ ChildId],ds.Tables [ 菜单]。列[ ParentId], true ); relation.Nested = true ; ds.Relations.Add(relation); xmlDataSource.Data = ds.GetXml(); xmlDataSource.TransformFile = Server.MapPath( 〜/ Menu.xslt ); xmlDataSource.XPath = MenuItems / MenuItem; NavigationMenu.DataSource = xmlDataSource; NavigationMenu.DataBind(); linkuaername.Text =( string )会话[ 用户名]; // 这里我收到了错误 Authenticatemenu(linkuaername。文本); 请分享信息解决方案 试试这个: linkuaername.Text =会话[ 用户名]。ToString( ); when user after login the user i copy the url and close the browser.again open same browser paste the url run the application i got this error:Unable to cast object of type 'System.Guid' to type 'System.String'This is my code:DataTable dtMenu = new DataTable(); DataSet ds = new DataSet(); XmlDataSource xmlDataSource = new XmlDataSource(); xmlDataSource.ID = "XmlSource1"; xmlDataSource.EnableCaching = false; dtMenu = GetMenuTable(); ds.Tables.Add(dtMenu); ds.DataSetName = "Menus"; ds.Tables[0].TableName = "Menu"; DataRelation relation = new DataRelation("Parentchild", ds.Tables["Menu"].Columns["ChildId"], ds.Tables["Menu"].Columns["ParentId"], true); relation.Nested = true; ds.Relations.Add(relation); xmlDataSource.Data = ds.GetXml(); xmlDataSource.TransformFile = Server.MapPath("~/Menu.xslt"); xmlDataSource.XPath = "MenuItems/MenuItem"; NavigationMenu.DataSource = xmlDataSource; NavigationMenu.DataBind(); linkuaername.Text =(string)Session["username"]; // here i got an error Authenticatemenu(linkuaername.Text);Please share the information 解决方案 Try this:linkuaername.Text = Session["username"].ToString(); 这篇关于c#中的System.Guid问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-22 17:48