简体   繁体   English

升级到VS 2010和.NET 4.0后LINQ停止工作

[英]LINQ stopped working after upgrade to VS 2010 and .NET 4.0

I have started using Visual Studio 2010 recently. 我最近开始使用Visual Studio 2010。 I have upgraded my solution from old 2008. After this I have tried to run my project, which is very simple database search engine using linq commands and it worked. 我从2008年的旧版本升级了解决方案。此后,我尝试运行我的项目,该项目是使用linq命令的非常简单的数据库搜索引擎,并且可以正常运行。 Then I have switched to .NET 4 and since then I am dead in the water. 然后我切换到.NET 4,从那以后我就死定了。 Any linq query does not execute, nor any exception is thrown. 任何linq查询都不会执行,也不会引发任何异常。 When I pause while the linq command is being executed, it freezes on DataContext.GetTable() method. 当我在执行linq命令时暂停时,它冻结在DataContext.GetTable()方法上。 All I could come up with were some compatibility issues, but I could not figure out what exactly the problem is. 我所能想到的只是一些兼容性问题,但我无法弄清楚到底是什么问题。

My Linq command is typical "select *": 我的Linq命令是典型的“选择*”:

var query = from mateInfo in context.TableMateInfos
                        select mateInfo;

I am using SQL Server 2008. I do not have any clue, why command execution should stop working after upgrade to .NET 4, especially because I am still able to connect to database. 我正在使用SQL Server2008。我没有任何线索,为什么升级到.NET 4后命令执行应该停止工作,尤其是因为我仍然能够连接到数据库。 When I open DB in Management studio, SQL command (select * from TableMateInfo) works just fine and returns data I want. 当我在Management Studio中打开数据库时,SQL命令(从TableMateInfo中选择*)可以正常工作并返回我想要的数据。 Does anybody have any ideas, where the burried dog might be please? 有没有人有想法,请问埋狗在哪里?

EDIT: 编辑:

I have run my application by its' exe file, following exception has been thrown: 我已经通过其exe文件运行了我的应用程序,引发了以下异常:

System.IO.FileLoadException: Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
   at System.Signature.GetSignature(SignatureStruct& signature, Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Signature..ctor(IRuntimeFieldInfo fieldHandle, RuntimeType declaringType)
   at System.Reflection.RtFieldInfo.get_FieldType()
   at System.Data.Linq.SqlClient.TypeSystem.GetMemberType(MemberInfo mi)
   at System.Data.Linq.Mapping.AttributedMetaDataMember..ctor(AttributedMetaType metaType, MemberInfo mi, Int32 ordinal)
   at System.Data.Linq.Mapping.AttributedMetaType.InitDataMembers()
   at System.Data.Linq.Mapping.AttributedMetaType..ctor(MetaModel model, MetaTable table, Type type, MetaType inheritanceRoot)
   at System.Data.Linq.Mapping.AttributedRootType..ctor(AttributedMetaModel model, AttributedMetaTable table, Type type)
   at System.Data.Linq.Mapping.AttributedMetaTable..ctor(AttributedMetaModel model, TableAttribute attr, Type rowType)
   at System.Data.Linq.Mapping.AttributedMetaModel.GetTableNoLocks(Type rowType)
   at System.Data.Linq.Mapping.AttributedMetaModel.GetTable(Type rowType)
   at System.Data.Linq.DataContext.GetTable[TEntity]()

I have added app.config file with following content to the same exact location where exe file and all libraries are located. 我已将具有以下内容的app.config文件添加到exe文件和所有库所在的相同确切位置。 Still I got the error above. 仍然我得到上面的错误。

<?xml version="1.0"?>
<configuration>
    <configSections>
    </configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>

I think you have Linq namespace problem, Just do one thing 我认为您有Linq名称空间问题,只需做一件事

Go to [project name] -> References -> Add reference -> System.Data.Linq 

Add System.Data.Linq namespace by Add references . 通过Add references添加System.Data.Linq命名空间。

Hope it solves your problem 希望它能解决您的问题

Problem was in different versions of .NET used to build single projects after all. 毕竟问题出在用于构建单个项目的.NET的不同版本中。 The app.config file above would work if there already weren't one without useLegacyV2RuntimeActivationPolicy="true" attribute. 如果没有useLegacyV2RuntimeActivationPolicy="true"属性,那么上面的app.config文件将可以工作。 I had to add it manually, now it works perfectly. 我必须手动添加它,现在它可以完美运行了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在升级到VS 2010 / .NET 4.0后,Membership.ValidateUser始终返回false - Membership.ValidateUser always returns false after upgrade to VS 2010 / .NET 4.0 升级到VS 2012后,PInvoke停止工作 - PInvoke stopped working after upgrade to VS 2012 将.net更改为4.0后ValidateRequest停止工作 - ValidateRequest stopped working after changing .net to 4.0 升级到.Net 4.0后的AccessViolationException - AccessViolationException after upgrade to .Net 4.0 VS 2010 &amp; .NET 4.0 能支持这个功能吗? - VS 2010 & .NET 4.0 can support this feature? ASP.NET Core MVC应用程序洞察在升级到.NET Core 1.1.1后停止工作 - ASP.NET Core MVC application insights stopped working after upgrade to .NET Core 1.1.1 Asp.Net Core - Model 绑定通用 Model 在升级到核心 3.0 后停止工作 - Asp.Net Core - Model Binding For Generic Model Stopped Working After Upgrade To Core 3.0 将 .NET 核心从 2 升级到 3 后 Program.cs 中的 DI 停止工作 - DI in Program.cs stopped working after upgrade .NET Core from 2 to 3 从vs2010迁移到vs2012后,Linq包含不起作用 - Linq Contains not working after migrate from vs2010 to vs2012 vs2010 .net 4.0到.net 3.x - vs2010 .net 4.0 to .net 3.x
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM