Tag: 编译器错误

无法通过连接编译c#linq查询

下面是一些c#代码的示例,我在执行一些linq连接时无法编译。 有谁知道为什么这不编译? 错误是 无法从查询中推断出类型参数 (在我的实际代码中, Fetch()返回一个IQueryable ) using System.Collections.Generic; using System.Linq; namespace LinqJoin { public class DataRepository { public IList Fetch() { return new List(); } } internal class SSOUser { public int Id { get; set; } } internal class UserRole { public int SSOUserId { get; set; } public int RoleId { get; […]

未定义条件编译符号

我无法让Visual Studio按照我的预期行事。 我创建了2个配置文件。 一个定义了符号FOO,另一个定义了符号BAR。 我有这个代码: static class MyClass{ #if FOO public static string const MyData=”foo defined”; #endif #if BAR /*yes, I know #elif would work here too.. just trying to be simple*/ public static string const MyData=”bar defined”; #endif } 然后在我的另一个文件中 if(MyClass.MyData==”foo defined”)….. 好吧,在我的应用程序中,我收到一个错误,即没有定义MyClass.MyData。 另外,如果我在FOO配置文件中有它并在#if FOO之后键入#error test类的东西那么它会有一个构建错误,但如果我删除它会构建得很好并且当我去运行它时我会’ ll得到一个编译错误,MyClass不包含MyData的定义。 此外,这是一个ASP.Net Web应用程序。 有人可以帮我弄清楚如何使用条件编译吗? 它就好像Visual Studio使用编译符号正确编译它一样,但是每当ASP.Net网络服务器执行它时,它都会重新编译它而没有任何符号……但这只是没有任何意义,为什么它会这样做.. 编辑:如果我使用FOO或BAR配置文件并不重要,它们似乎都没有像它们那样定义MyData符号。 EDIT2: […]

为什么C#编译器不调用隐式转换运算符?

假设我们有以下类型: struct MyNullable where T : struct { T Value; public bool HasValue; public MyNullable(T value) { this.Value = value; this.HasValue = true; } public static implicit operator T(MyNullable value) { return value.HasValue ? value.Value : default(T); } } 并尝试编译以下代码片段: MyNullable i1 = new MyNullable(1); MyNullable i2 = new MyNullable(2); int i = i1 + […]

编译器错误:“错误CS0307:变量’int’不能与类型参数一起使用”

如果我有以下代码: private void Check(bool a, bool b) { } private void Check(int a, int b, int c, bool flag) { Check(a (flag ? c : b – 10)); } 我在调用Check(int, int)时遇到编译时错误: 错误CS0307:变量’int’不能与类型参数一起使用 我也得到这些错误: 错误CS0118:’b’是变量但是像类型一样使用 错误CS0118:’a’是变量但是像类型一样使用 为什么会出现这些错误? 代码有什么问题?

‘名称空间使用类似’错误

编码器,我试图使用我在这里找到的库将XAML字符串转换为HTML,但我在创建一个允许我使用该库的对象的新实例时遇到问题。 我已经在我的Asp.net项目中添加了对库的引用,我想在WCF文件中使用它。 问题是每当我尝试使用new关键字实例化一个新对象时,我会收到一条错误消息: ‘MarkupConverter’是’命名空间’,但用作’类型’。 这是我的代码,请注意我正在创建一个新对象,就像上面库链接中显示的示例一样,请帮助: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.Web.Services; using System.Net.Mail; using System.ServiceModel.Activation; using System.Data.SqlClient; using MarkupConverter; namespace AspPersonalWebsite { [ServiceContract(Namespace = “”)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Service1 //: IService1 { private string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[“ApplicationServices”].ConnectionString; private IMarkupConverter markupConverter; [OperationContract] public string convertXAMLToHTML(string XAMLtext) […]

是什么让ValueType类特别?

当我尝试定义一个inheritance自System.ValueType或System.Enum类的类时,我收到一个错误: Cannot derive from special class System.ValueType 我理解错误,但我无法理解的是什么使ValueType类特殊 ? 我的意思是没有关键字(如sealed )或属性来指定不能inheritance此类。 ValueType有两个属性, Serializable和ComVisible但它们都与这种情况无关。 文档说: 尽管ValueType是值类型的隐式基类,但您无法创建直接从ValueTypeinheritance的类。 相反,单个编译器提供语言关键字或构造(例如C#中的struct和Visual Basic中的Structure … End Structure)以支持值类型的创建。 但它没有回答我的问题。所以我的问题是在这种情况下如何通知编译器? 当我尝试创建一个从类inheritance的类时,编译器是否直接检查该类是ValueType还是Enum ? 编辑:所有结构都implicitlyinheritance自ValueType ,但Enum类显式inheritance自ValueType ,那么它是如何工作的呢? 编译器如何找出这种情况,所有这些都是由编译器硬编码的?

从对象类型WebMatrix.Data.DynamicRecord到已知的托管提供程序本机类型不存在映射

我对SQL服务器返回的错误感到很困惑 – 这会导致什么? 我正在运行的C#代码是: List events = new List(); var db = Database.Open(“myDatabase”); string username = HttpContext.Current.Request.Cookies.Get(“username”).Value; var listOfGroups = db.Query(“SELECT GroupID FROM Membership WHERE UserID = (SELECT UserID from Users WHERE Username = @0 )”, username); foreach(var groupID in listOfGroups) { var result = db.Query( @”SELECT e.event_id, e.title, e.description, e.event_start, e.event_end, e.group_id, e.recurring FROM […]

为什么会导致CS0695?

public interface PipelineElement { IEnumerable Run(IEnumerable input, Action errorReporter); } public interface Stage { } public abstract class PipelineElementBase : PipelineElement, PipelineElement where TIn : Stage where TOut : Stage { IEnumerable PipelineElement.Run(IEnumerable input, Action errorReporter) { return this.Run(input.Cast(), errorReporter).Cast(); } public abstract IEnumerable Run(IEnumerable input, Action errorReporter); } object没有实现Stage ,因此TIn和TOut都不能成为object ,对吧? 那么为什么编译器认为PipelineElement和PipelineElement可以变得相同? 编辑:是的,完全可以多次实现相同的通用接口: public […]

切换到任何CPU配置后,Win Service项目将不会生成

我正试图找到解决问题的方法。 将我的.net 4.0 C#Win服务项目更改为任何CPU /发布版本配置后,我收到此编译时错误: Cannot specify /main if building a module or library 它将违规文件标识为“CSC”,生成它的项目是我的服务项目(不是我在解决方案中附带的代码库)。 我查看了项目文件和配置编辑器设置但尚未能确定问题的根源。 有没有其他人经历过这个节目停止问题?

“不包含定义……并且没有扩展方法..”错误

我有以下错误消息: ‘System.Collections.Generic.Dictionary’ does not contain a definition for ‘biff’ and no extension method ‘biff’ accepting a first argument of type ‘System.Collections.Generic.Dictionary’ could be found (are you missing a using directive or an assembly reference?) 我检查了SO,我发现这个问题似乎与我有类似(如果不是完全相同)的问题。 但是,我尝试了接受的答案中提供的解决方案,但仍然没有提出任何建议。 它表现得像我错过了一个使用声明,但我几乎是积极的,我有我需要的所有使用。 以下是产生错误的一些代码: using locationOfSpoofClass; … Dictionary cart = new Dictionary(); foreach (var item in dbContext.DBView) { cart.biff = item.biff; […]