在VS 2015和VS 2013上运行同一段代码时出现问题 [英] Problems running same piece of code on VS 2015 and VS 2013

查看:90
本文介绍了在VS 2015和VS 2013上运行同一段代码时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2013和2015中运行一段代码时,我得到两个不同的结果.在visual Studio 2015上,我得到了一个N​​ullReference,在2013年,它按应有的方式工作.此外,Visual Studio 2015也在Windows 8.1的Windows 10和2013上运行.这段代码是:

When running a piece of code in Visual Studio 2013 and 2015, I get two different outcomes. On visual Studio 2015 I get an NullReference and in 2013 it works the way it should. Also Visual Studio 2015 is running on Windows 10 and 2013 on Windows 8.1. The piece of code is:

private static T FindParentOfType<T>(DependencyObject o)
{
    dynamic parent = VisualTreeHelper.GetParent(o);
    return parent.GetType().IsAssignableFrom(typeof(T)) ? parent : FindParentOfType<T>(parent);
}

该代码的调用方式为:

Grid RiskGrid = FindParentOfType<Grid>(ChampViewModelSel);

在检查IsAssginableFrom时错误是Nullreference,因为在VS2015中它找到了Canvas而不是在VS2013中找到了希望的网格?

The error is a Nullreference when it checks for IsAssginableFrom since in VS2015 it finds a Canvas instead of the wished Grid that is found in VS2013?

堆栈跟踪

  StackTrace  "   at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetOriginalTypeParameterType(Type t)\r\n   
    at Microsoft.CSharp.RuntimeBinder.SymbolTable.AreTypeParametersEquivalent(Type t1, Type t2)\r\n   
    at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadMethodTypeParameter(MethodSymbol parent, Type t)\r\n   
    at Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)\r\n   
    at Microsoft.CSharp.RuntimeBinder.SymbolTable.AddMethodToSymbolTable(MemberInfo member, AggregateSymbol callingAggregate, MethodKindEnum kind)\r\n   
    at Microsoft.CSharp.RuntimeBinder.SymbolTable.AddNamesInInheritanceHierarchy(String name, BindingFlags flags, List 1 inheritance)\r\n   
    at Microsoft.CSharp.RuntimeBinder.SymbolTable.PopulateSymbolTableWithName(String name, IEnumerable 1 typeArguments, Type callingType)\r\n   
    at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.PopulateSymbolTableWithPayloadInformation(DynamicMetaObjectBinder payload, Type callingType, ArgumentObject[] arguments)\r\n  
    at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(DynamicMetaObjectBinder payload, IEnumerable 1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)\r\n
    at Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(DynamicMetaObjectBinder payload, IEnumerable 1 parameters, DynamicMetaObject[] args, DynamicMetaObject& deferredBinding)\r\n 
    at Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action, RuntimeBinder binder, IEnumerable 1 args, IEnumerable 1 arginfos, DynamicMetaObject onBindingError)\r\n 
    at Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)\r\n
    at System.Dynamic.DynamicMetaObject.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)\r\n 
    at System.Dynamic.InvokeMemberBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)\r\n
    at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection 1 parameters, LabelTarget returnLabel)\r\n
    at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite 1 site, Object[] args)\r\n 
    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)\r\n
    at BC_Game.ViewModel.ChampionViewModel.FindParentOfType[T](DependencyObject o)\r\n 
    at BC_Game.ViewModel.ChampionViewModel.ManStart(ManipulationStartedEventArgs e)"    string

更新

在Win10上安装了VS2013,问题仍然存在. VS2013在Win8.1上运行良好

Installed VS2013 on Win10, and the issue persists. VS2013 works fine on Win8.1

更新

从Visual Studio 2013 wp 8.1

From Visual Studio 2013 wp 8.1

C:\ Program Files(x86)\ MSBuild \ 12.0 \ bin \ Csc.exe/noconfig/nowarn:1701,1702,2008/nostdlib +/errorreport:提示/警告:4/define:DEBUG; TRACE/errorendlocation/preferreduilang:zh-CN/参考:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ mscorlib.dll"/参考:"C:\ Program Files(x86 )\参考程序集\ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ Microsoft.CSharp.dll"/引用:" C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ mscorlib.dll"/参考:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Core.dll"/参考:" C :\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.dll"/reference:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Net.dll"/引用:"C:\ Program Files(x86)\ Reference Asse mblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Runtime.Serialization.dll"/reference:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.ServiceModel.dll"/参考:"C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.ServiceModel.Web.dll"/参考:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Windows.dll"/引用:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Xml.dll"/引用:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Xml.Linq.dll"/引用:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Xml.Serialization.dll"/debug +/debug :full/filealign:512/optimize-/out:obj\Debug\LibraryOfModels.dll/target:l库/utf8output BuyMenuClass.cs CastleModel.cs ChampionModel.cs ChatDTO.cs CollectionCombiner.cs Country.cs CurrentUser.cs DecorationListItems.cs GameDTO.cs MapTransform.cs MarketplaceModel.cs MenuFirstPageModel.cs NotifyBase.cs Player.cs PopupColorPickerModel.cs PopupExtraInfoModel. cs PopUpModel.cs属性\ AssemblyInfo.cs RankDTO.cs RankModel.cs ShieldGearModel.cs UnitModel.cs UserDTO.cs WarCalculations.cs"C:\ Users \ Jonas \ AppData \ Local \ Temp.NETPortable,Version = v4.0,Profile = Profile158.AssemblyAttributes.cs"

C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Net.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Runtime.Serialization.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.ServiceModel.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.ServiceModel.Web.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Windows.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Xml.Linq.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Xml.Serialization.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\LibraryOfModels.dll /target:library /utf8output BuyMenuClass.cs CastleModel.cs ChampionModel.cs ChatDTO.cs CollectionCombiner.cs Country.cs CurrentUser.cs DecorationListItems.cs GameDTO.cs MapTransform.cs MarketplaceModel.cs MenuFirstPageModel.cs NotifyBase.cs Player.cs PopupColorPickerModel.cs PopupExtraInfoModel.cs PopUpModel.cs Properties\AssemblyInfo.cs RankingDTO.cs RankingModel.cs ShieldGearModel.cs UnitModel.cs UserDTO.cs WarCalculations.cs "C:\Users\Jonas\AppData\Local\Temp.NETPortable,Version=v4.0,Profile=Profile158.AssemblyAttributes.cs"

从VS 2015 Win 10起

From VS 2015 Win 10

C:\ Program Files(x86)\ MSBuild \ 14.0 \ bin \ csc.exe/noconfig/nowarn:1701,1702,2008/nostdlib +/errorreport:提示/警告:4/define:DEBUG; TRACE/errorendlocation/preferreduilang:zh-CN/参考:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ mscorlib.dll"/参考:"C:\ Program Files(x86 )\参考程序集\ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ Microsoft.CSharp.dll"/引用:" C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ mscorlib.dll"/参考:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Core.dll"/参考:" C :\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.dll"/reference:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Net.dll"/引用:"C:\ Program Files(x86)\ Reference Asse mblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Runtime.Serialization.dll"/reference:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.ServiceModel.dll"/参考:"C:\ Program Files(x86)\参考程序集\ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.ServiceModel.Web.dll"/参考:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Windows.dll"/引用:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Xml.dll"/引用:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Xml.Linq.dll"/引用:"C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETPortable \ v4.0 \ Profile \ Profile158 \ System.Xml.Serialization.dll"/debug +/debug :full/filealign:512/optimize-/out:obj\Debug\LibraryOfModels.dll/ruleset: "C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Team Tools \ Static Analysis Tools \ Rule Sets \ MinimumRecommendedRules.ruleset"/target:library/utf8output BuyMenuClass.cs CastleModel.cs ChampionModel.cs ChatDTO.cs CollectionCombiner.cs Country.cs CurrentUser.cs DecorationListItems.cs GameDTO.cs MapTransform.cs MarketplaceModel.cs MenuFirstPageModel.cs NotifyBase.cs Player.cs PopupColorPickerModel.cs PopupExtraInfoModel.cs PopUpModel.cs Properties \ AssemblyInfo.cs RankDTO.cs RankModel.cs ShieldGearModel.cs UnitModel.cs UserDTO.cs WarCalculations.cs"C:\ Users \ johann \ AppData \ Local \ Temp.NETPortable,Version = v4.0,Profile = Profile158.AssemblyAttributes.cs"

C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Net.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Runtime.Serialization.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.ServiceModel.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.ServiceModel.Web.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Windows.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Xml.Linq.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Xml.Serialization.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\LibraryOfModels.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets\MinimumRecommendedRules.ruleset" /target:library /utf8output BuyMenuClass.cs CastleModel.cs ChampionModel.cs ChatDTO.cs CollectionCombiner.cs Country.cs CurrentUser.cs DecorationListItems.cs GameDTO.cs MapTransform.cs MarketplaceModel.cs MenuFirstPageModel.cs NotifyBase.cs Player.cs PopupColorPickerModel.cs PopupExtraInfoModel.cs PopUpModel.cs Properties\AssemblyInfo.cs RankingDTO.cs RankingModel.cs ShieldGearModel.cs UnitModel.cs UserDTO.cs WarCalculations.cs "C:\Users\johann\AppData\Local\Temp.NETPortable,Version=v4.0,Profile=Profile158.AssemblyAttributes.cs"

我们只能看到两者之间的唯一区别是所使用的.NetFrameworks.一个使用版本4.5.51650,另一个使用4.6.01038.

The only difference we can see between the two is the .NetFrameworks being used. One has Version 4.5.51650 and the other uses 4.6.01038.

更新

似乎PC的最新win 10更新已经解决了这个问题.

It seems like the newest win 10 update for the pc has solved this issue.

推荐答案

您可以尝试通过此链接更改.net版本.

You can try change your .net version following this link.

https://msdn.microsoft.com/en-us/library/gg597391(v=vs.110).aspx

我相信这可能是.net版本问题,但是我不确定它会对您的应用产生影响.

I believe it can be a .net version issue however, I'm not sure the impact it will have in your app.

这篇关于在VS 2015和VS 2013上运行同一段代码时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆