找不到类型或命名空间名称“LogMsgType”(您是否缺少using指令或程序集引用?) [英] The type or namespace name 'LogMsgType' could not be found (are you missing a using directive or an assembly reference?)
问题描述
大家好,
i正在使用c#开发Windows应用程序项目。
在我的申请中得到两个错误,实际上我已经尝试了很多方法,但我在下面的代码中找到了它发生的事情。
我的错误是:
无法找到类型或命名空间名称''LogMsgType''(您是否缺少using指令或汇编引用?)
找不到类型或命名空间名称''DataMode''(您是否缺少using指令或汇编引用?)
我的代码是:
hi all,
i am developing windows application project using c#.
in my application am getting two errors, actually i had tried many ways but i coudnt find what it as happen in my code below.
my errors are:
The type or namespace name ''LogMsgType'' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name ''DataMode'' could not be found (are you missing a using directive or an assembly reference?)
my code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using CSOCR.Properties;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace CSOCR
{
public partial class Form1 : Form
{
// The main control for communicating through the RS-232 port
private SerialPort comport = new SerialPort();
// Various colors for logging info
private Color[] LogMsgTypeColor = { Color.Blue, Color.Green, Color.Black, Color.Orange, Color.Red };
// Temp holder for whether a key was pressed
private bool KeyHandled = false;
private Settings settings = Settings.Default;
public Form1()
{
// Load user settings
settings.Reload();
// Build the form
InitializeComponent();
// Restore the users settings
InitializeControlValues();
// Enable/disable controls based on the current state
EnableControls();
// When data is recieved through the port, call this method
comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
comport.PinChanged += new SerialPinChangedEventHandler(comport_PinChanged);
}
private void Log(LogMsgType msgtype, string msg) // this is my first error
{
rtfTerminal.Invoke(new EventHandler(delegate
{
rtfTerminal.SelectedText = string.Empty;
rtfTerminal.SelectionFont = new Font(rtfTerminal.SelectionFont, FontStyle.Bold);
rtfTerminal.SelectionColor = LogMsgTypeColor[(int)msgtype];
rtfTerminal.AppendText(msg);
rtfTerminal.ScrollToCaret();
}));
}
private DataMode CurrentDataMode // this is my second error
{
get
{
if (rbHex.Checked) return DataMode.Hex;
else return DataMode.Text;
}
set
{
if (value == DataMode.Text) rbText.Checked = true;
else rbHex.Checked = true;
}
}
}
}
请查看上面的代码,让我知道我错误的地方我的代码,以便我可以纠正我的错误。
提前感谢。
添加了代码块 - OriginalGriff [/ edit]
please find out my code above and let me know where i did mistake in my code,so that i can rectify my mistakes.
thanks in advance.
[edit]Code block added - OriginalGriff[/edit]
推荐答案
具体如何解决这个问题取决于定义两个类LogMsgType和DataMode的位置:
如果它们在同一个项目中,但在不同的命名空间中,则需要使用语句添加。
如果它们在不同的项目或外部DLL中,您需要对项目/ DLL的引用和使用
语句。
将光标放在两个类名之一中,开头会出现一条蓝线。将鼠标悬停在蓝线上,会出现一个下拉列表。打开下拉菜单。
如果它包含两个解决方案(使用解决方案和完全限定名称),那么您可能需要使用
语句,所以选择那个。如果包含两个解决方案(为''xxx''生成类和生成新类型...),那么您还需要添加引用。
Exactly how you fix this depends on where the two classes "LogMsgType" and "DataMode" are defined:
If they are within the same project, but in a different namespace then you need to add ausing
statement.
If they are in a different project, or in an external DLL, then you need both a reference to the project/DLL and ausing
statement.
Put your cursor in one of the two class names, and a blue line will appear at the beginning. Hover the mouse over the blue line and a drop down will appear. Open the drop down.
If it contains two solutions (a "using" solution and a fully qualified name) then you probably need ausing
statement, so select that. If is contains two solutions ("Generate class for ''xxx''" and "Generate new type...") then you need to add a reference as well.
这篇关于找不到类型或命名空间名称“LogMsgType”(您是否缺少using指令或程序集引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!