【发布时间】:2015-09-22 09:34:47
【问题描述】:
为什么我得到一个参数异常,说我将错误数量的参数传递给 string.equals 方法?
我传递了三个参数,这应该是正确的。实际上它应该抛出编译时错误而不是运行时......
你看到错误了吗?
var translations = await (from l in context.Languages
join t in context.Translations on l.ISO639_ISO3166 equals t.ISO639_ISO3166
where string.Equals(l.ApplicationName, applicationName, StringComparison.InvariantCultureIgnoreCase)
select new Translation
{
Key = t.Key,
Text = t.Text
}).ToListAsync();
更新
Test Name: GetTranslations
Test FullName: TaaS.IntegrationTests.Tests.TranslationRepositoryTests.GetTranslations
Test Source: C:\test\TaaS-WebApplication\TaaS.IntegrationTests\Tests\TranslationRepositoryTests.cs : line 17
Test Outcome: Failed
Test Duration: 0:00:00,0473367
Result StackTrace:
at System.Linq.Expressions.Expression.GetMethodBasedBinaryOperator(ExpressionType binaryType, Expression left, Expression right, MethodInfo method, Boolean liftToNull)
at System.Linq.Expressions.Expression.Equal(Expression left, Expression right, Boolean liftToNull, MethodInfo method)
at System.Data.Entity.Core.Objects.ELinq.LinqExpressionNormalizer.VisitMethodCall(MethodCallExpression m)
at System.Linq.Expressions.EntityExpressionVisitor.Visit(Expression exp)
at System.Linq.Expressions.EntityExpressionVisitor.VisitLambda(LambdaExpression lambda)
at System.Linq.Expressions.EntityExpressionVisitor.Visit(Expression exp)
at System.Linq.Expressions.EntityExpressionVisitor.VisitUnary(UnaryExpression u)
at System.Linq.Expressions.EntityExpressionVisitor.Visit(Expression exp)
at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
at System.Data.Entity.Core.Objects.ELinq.LinqExpressionNormalizer.VisitMethodCall(MethodCallExpression m)
at System.Linq.Expressions.EntityExpressionVisitor.Visit(Expression exp)
at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
at System.Data.Entity.Core.Objects.ELinq.LinqExpressionNormalizer.VisitMethodCall(MethodCallExpression m)
at System.Linq.Expressions.EntityExpressionVisitor.Visit(Expression exp)
at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter..ctor(Funcletizer funcletizer, Expression expression)
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.CreateExpressionConverter()
at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassc.<GetResultsAsync>b__a()
at System.Data.Entity.Core.Objects.ObjectContext.<ExecuteInTransactionAsync>d__3d`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<ExecuteAsyncImplementation>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult()
at System.Data.Entity.Core.Objects.ObjectQuery`1.<GetResultsAsync>d__e.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult()
at System.Data.Entity.Internal.LazyAsyncEnumerator`1.<FirstMoveNextAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.<ForEachAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TaaS.Repository.TranslationRepository.<GetTranslationsAsync>d__2.MoveNext() in C:\_REPOSITORIES\taas-application\TaaS-WebApplication\TaaS.Repository\TranslationRepository.cs:line 20
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at TaaS.IntegrationTests.Tests.TranslationRepositoryTests.GetTranslations() in C:\_REPOSITORIES\taas-application\TaaS-WebApplication\TaaS.IntegrationTests\Tests\TranslationRepositoryTests.cs:line 45
Result Message:
Test method TaaS.IntegrationTests.Tests.TranslationRepositoryTests.GetTranslations threw exception:
System.ArgumentException: Incorrect number of arguments supplied for call to method 'Boolean Equals(System.String, System.String, System.StringComparison)'
【问题讨论】:
-
t.ISO639_ISO3166是string吗? -
是
l.ApplicationName一个字符串吗? -
如果它们不是字符串。它们都是编译时错误。 Elisabeth 发现运行时错误。
-
提供完整的错误。
-
Boolean 的错误是像标题所说的那样,还是像问题所说的那样是 string.equals?