C# 匿名类型名冲突
返回匿名类型的linq查询在执行时抛出以下错误C# 匿名类型名冲突,c#,linq,anonymous-types,C#,Linq,Anonymous Types,返回匿名类型的linq查询在执行时抛出以下错误 The type '<>f__AnonymousType9<Name,Value>' exists in both 'Customer.CustomerWeb.Presentation.dll' and 'Customer.CustomerContext.dll' Customer.CustomerWeb.Presentation.dll internal sealed class <>f__Anon
The type '<>f__AnonymousType9<Name,Value>' exists in both
'Customer.CustomerWeb.Presentation.dll' and 'Customer.CustomerContext.dll'
Customer.CustomerWeb.Presentation.dll
internal sealed class <>f__AnonymousType9<<PayrollSiteID>j__TPar, <IsActive>j__TPar>
internal sealed class <>f__AnonymousType9<<Name>j__TPar, <Value>j__TPar>
内部密封等级f__匿名类型9
生成的两个类都位于根
命名空间中
。是否有任何方法可以将匿名类型类
定向到每个程序集上的特定命名空间?简单的解决方法是在一个匿名查询中添加第三个变量,不过这更像是一种黑客行为 我认为您需要如下内容,在名称空间中添加using语句,以便在名称解析中为其提供优先权:
using Customer.CustomerContext;
namespace yourNameSpace
{
using Customer.CustomerWeb.Presentation; //Where f__AnonymousType9<Name,Value> exists
}
使用Customer.CustomerContext;
名称空间yourNameSpace
{
使用Customer.CustomerWeb.Presentation;//其中存在f__匿名类型9
}
来自评论
这会导致堆栈溢出。为了获得类型
“f__AnonymousType9”在这两种语言中都存在
“Customer.CustomerWeb.Presentation.dll”和
“Customer.CustomerContext.dll”
我必须在
崩溃检查变量是在我收到该消息时进行的
名称空间冲突不是您的问题,它会导致调试器在尝试计算变量时崩溃,但我不知道它如何可能导致堆栈溢出。您需要a)更仔细地查看linq以找出意外递归的位置,或b)发布堆栈跟踪的一部分,以便我们可以帮助您跟踪它。您还没有显示查询,但另一个简单的修复方法肯定是创建一个命名的,非匿名类型。这是编译时错误吗?@Damien_不相信匿名类型的目的。加载程序集的方式有什么不寻常的地方吗?因为两个类都标记为内部类,它们的名称不应该冲突-可能您的一个程序集使用InternalsVisibleTo属性向另一个程序集显示其内部。。。