当前上下文中不存在名称XXX的解决方法

本文解决了在使用Visual Studio 2005时遇到的上下文名称错误问题,通过删除重复文件成功修复错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天用visual studio 2005打开网站,重新生成的时候,发现 当前上下文中不存在名称txtVerifyCoce,

很奇怪,直接运行网站又可以,把名称改掉还是不行.查了网上,也有相似的出错,找到了原因:是我改login.aspx时,怕改错了,COPY了一份,把 复件login.aspx 删除就OK了.

不知道这是不是visual的BUG. 

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Windows.Forms; namespace BeamAnnotationPlugin { public class BeamProcessor { // 图层配置 private static string _beamLayer = ""; private static string _dimLayer = ""; // 标注设置 private static double _textHeight = 2.5; private static double _elevationOffset = 0.05; } } public class BeamMark { public string Name { get; set; } = ""; public string Section { get; set; } = ""; public double Elevation { get; set; } = 0; public Point3d Position { get; set; } public bool IsCentralMark { get; set; } = true; } [CommandMethod("BR", CommandFlags.Modal)] public void BeamRecognition() { // 识别集中标注和原位标注 PromptSelectionResult selRes = _ed.GetSelection(); if (selRes.Status != PromptStatus.OK) return; using (Transaction tr = _db.TransactionManager.StartTransaction()) { List<BeamMark> beamMarks = new List<BeamMark>(); foreach (ObjectId id in selRes.Value.GetObjectIds()) { Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity; if (ent is DBText text && ent.Layer == _beamLayer) { BeamMark mark = ParseBeamText(text.TextString); mark.Position = text.Position; beamMarks.Add(mark); } } // 存储识别结果 StoreBeamData(beamMarks); tr.Commit(); } } private BeamMark ParseBeamText(string text) { // 使用正则表达式解析梁标注 BeamMark mark = new BeamMark(); // 匹配格式: KL1(2) 300x700 (-0.050) Regex regex = new Regex(@"(\w+)\s*$(\d+)$\s*(\d+)x(\d+)\s*(?:$([-]?\d+\.\d+)$)?"); Match match = regex.Match(text); if (match.Success) { mark.Name = match.Groups[1].Value + "(" + match.Groups[2].Value + ")"; mark.Section = $"{match.Groups[3].Value}×{match.Groups[4].Value}"; if (match.Groups.Count > 5 && !string.IsNullOrEmpty(match.Groups[5].Value)) { mark.Elevation = double.Parse(match.Groups[5].Value); } } return mark; } [CommandMethod("AG", CommandFlags.Modal)] public void AutoGenerateMarks() { PromptPointResult ptRes = _ed.GetPoint("\n选择标注插入点: "); if (ptRes.Status != PromptStatus.OK) return; using (Transaction tr = _db.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject( _db.CurrentSpaceId, OpenMode.ForWrite); // 生成集中标注 DBText centralMark = new DBText { Position = ptRes.Value, TextString = FormatBeamText(_currentBeam, true), Height = _textHeight, Layer = _dimLayer }; btr.AppendEntity(centralMark); tr.AddNewlyCreatedDBObject(centralMark, true); // 生成原位标注 Point3d locPos = new Point3d( ptRes.Value.X + 20, ptRes.Value.Y, ptRes.Value.Z); DBText localMark = new DBText { Position = locPos, TextString = FormatBeamText(_currentBeam, false), Height = _textHeight * 0.8, Layer = _dimLayer }; btr.AppendEntity(localMark); tr.AddNewlyCreatedDBObject(localMark, true); tr.Commit(); } } private string FormatBeamText(BeamMark beam, bool isCentral) { // 集中标注格式: KL1(2) 300x700 // 原位标注格式: 300x700 (-0.050) if (isCentral) { return $"{beam.Name} {beam.Section}"; } else { return beam.Elevation != 0 ? $"{beam.Section} ({beam.Elevation:F3})" : beam.Section; } } [CommandMethod("BST", CommandFlags.Modal)] public void BeamStatistics() { List<BeamStatItem> stats = CalculateBeamStatistics(); // 按荷载排序: $ q = \frac{w \times h}{10^6} \times 25 $ stats.Sort((a, b) => b.Load.CompareTo(a.Load)); CreateStatisticsTable(stats); } private List<BeamStatItem> CalculateBeamStatistics() { List<BeamStatItem> stats = new List<BeamStatItem>(); foreach (BeamMark beam in _recognizedBeams) { // 解析截面尺寸 string[] dims = beam.Section.Split('×'); if (dims.Length != 2) continue; if (double.TryParse(dims[0], out double width) && double.TryParse(dims[1], out double height)) { // 计算荷载: $ q = A \times \gamma $ double area = (width * height) / 1_000_000.0; double load = area * 25; // γ=25kN/m³ stats.Add(new BeamStatItem { Name = beam.Name, Section = beam.Section, Elevation = beam.Elevation, Load = load }); } } return stats; } [CommandMethod("DR", CommandFlags.Modal)] public void DeleteReinforcement() { using (Transaction tr = _db.TransactionManager.StartTransaction()) { // 创建钢筋标注特征过滤器 TypedValue[] filterList = { new TypedValue((int)DxfCode.Start, "TEXT"), new TypedValue((int)DxfCode.LayerName, _dimLayer), new TypedValue((int)DxfCode.Text, "*Φ*") // 匹配钢筋符号 }; SelectionFilter filter = new SelectionFilter(filterList); PromptSelectionResult selRes = _ed.SelectAll(filter); if (selRes.Status == PromptStatus.OK) { foreach (ObjectId id in selRes.Value.GetObjectIds()) { Entity ent = tr.GetObject(id, OpenMode.ForWrite) as Entity; ent.Erase(); } } tr.Commit(); } } [CommandMethod("SE", CommandFlags.Modal)] public void SetElevationOffset() { PromptDoubleOptions opts = new PromptDoubleOptions("\n输入标高偏移值(m): "); opts.DefaultValue = _elevationOffset; opts.AllowNegative = true; PromptDoubleResult res = _ed.GetDouble(opts); if (res.Status == PromptStatus.OK) { _elevationOffset = res.Value; _ed.WriteMessage($"\n标高偏移已设置为: {_elevationOffset:F3}m"); } } private double CalculateAdjustedElevation(double original) { // 应用标高偏移: $ E_{adj} = E_{orig} + \Delta $ return original + _elevationOffset; } [CommandMethod("FS", CommandFlags.Modal)] public void AdjustTextSize() { PromptDoubleOptions opts = new PromptDoubleOptions("\n输入标注文字高度: "); opts.DefaultValue = _textHeight; opts.AllowNegative = false; PromptDoubleResult res = _ed.GetDouble(opts); if (res.Status == PromptStatus.OK) { _textHeight = res.Value; _ed.WriteMessage($"\n文字高度已设置为: {_textHeight}"); } } 以上代码出现的问题 CS0234命名空间“System.Windows”中存在类型或命名空间名“Forms”(是否缺少程序集引用?) CS8803顶级语句必须位于命名空间和类型声明之前。 CS8370功能”顶级语句”在C#7.3中可用。请使用9.0或更高的语言版本。 CS8370功能”本地函数特性”在C#7.3中可用。请使用9.0或更高的语言版本。 CS0106修饰符public”对该项无效 CS0103当前上下文存在名称_ed” CS0103当前上下文存在名称_db" CS0103当前上下文存在名称_beamLayer CS0103当前上下文存在名称StoreBeamData” CS0106修饰符private”对该项无效 CS8370功能”本地函数特性”在C#7.3中可用。请使用9.0或更高的语言版本。 CS0106修饰符“public"对该项无效 CS0103当前上下文存在名称ed CS0103当前上下文存在名称_db” CS0103当前上下文存在名称_db” CS0103当前上下文存在名称_currentBeam” CS0103当前上下文存在名称textHeight CS0103当前上下文存在名称_dimLayer” CS0103当前上下文存在名称_currentBeam” CS0103当前上下文存在名称textHeight CS0103当前上下文存在名称_dimLayer CS0106修饰符private"对该项无效 CS8370功能”本地函数特性”在C#7.3中可用。请使用9.0或更高的语言版本。 CS0106修饰符public对该项无效 CS0246未能找到类型或命名空间名“BeamStatltem”(是否缺少using指令或程序集引用?) CS0103当前上下文存在名称“CreateStatisticsTable” CS0106修饰符private"对该项无效 CS0246未能找到类型或命名空间名“BeamStatltem”(是否缺少using 指令或程序集引用?) CS0246未能找到类型或命名空间名“BeamStatltem”(是否缺少using 指令或程序集引用?) CS0246未能找到类型或命名空间名“BeamStatltem”(是否缺少using 指令或程序集引用?) CS0103当前上下文存在名称_recognizedBeams CS0103当前上下文存在名称“area” CS0246未能找到类型或命名空间名“BeamStatltem”(是否缺少using 指令或程序集引用?) CS0246未能找到类型或命名空间名“BeamStatltem”(是否缺少using指令或程序集引用?) CS8370功能”本地函数特性”在C#7.3中可用。请使用9.0或更高的语言版本。 CS0106修饰符public对该项无效 CS0103当前上下文存在名称_db CS0103当前上下文存在名称dimLayer" CS0103当前上下文存在名称_ed” CS8370功能”本地函数特性”在C#7.3中可用。请使用9.0或更高的语言版本。 CS0106修饰符public"对该项无效 CS0103当前上下文存在名称_elevationOffset CS0103当前上下文存在名称_ed” CS0103当前上下文存在名称_elevationOffset CS0103当前上下文存在名称_ed” CS0103当前上下文存在名称elevationOffset CS0106修饰符“private”对该项无效 CS0161“CalculateAdjustedElevation(double)”:并非所有的代码路径都返回值 CS8370功能”本地函数特性”在C#7.3中可用。请使用9.0或更高的语言版本。 CS0106修饰符“public对该项无效 CS0103当前上下文存在名称_textHeight CS0103当前上下文存在名称_ed” CS0103当前上下文存在名称_textHeight CS0103当前上下文存在名称ed CS0103当前上下文存在名称textHeight CS8321声明了本地函数BeamRecognition”,但从未使用过 CS8321声明了本地函数AutoGenerateMarks”,但从未使用过 CS8321声明了本地函数BeamStatistics”,但从未使用过 CS8321声明了本地函数DeleteReinforcement”,但从未使用过 CS8321声明了本地函数SetElevationOffset”,但从未使用过 CS8321声明了本地函数“CalculateAdjustedElevation”,但从未使用过 CS8321声明了本地函数AdjustTextSize”,但从未使用过
07-04
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值