首页 文章

在VS 2015和VS 2013上运行相同代码的问题

提问于
浏览
4

在Visual Studio 2013和2015中运行一段代码时,我得到两个不同的结果 . 在Visual Studio 2015上,我获得了NullReference,并且在2013年它的工作方式应该如此 . Visual Studio 2015也在Windows 8.1上的Windows 10和2013上运行 . 这段代码是:

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中找到的希望网格?

Stack Trace

StackTrace“at Microsoft.CSharp.RuntimeBinder.SymbolTable.GetOriginalTypeParameterType(Type t)\ r \ n
在Microsoft.CSharp.RuntimeBinder.SymbolTable.AreTypeParametersEquivalent(类型t1,类型t2)\ r \ n
在Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadMethodTypeParameter(MethodSymbol parent,Type t)\ r \ n
在Microsoft.CSharp.RuntimeBinder.SymbolTable.LoadSymbolsFromType(Type originalType)\ r \ n
在Microsoft.CSharp.RuntimeBinder.SymbolTable.AddMethodToSymbolTable(MemberInfo成员,AggregateSymbol callingAggregate,MethodKindEnum类)\ 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
在Microsoft.CSharp.RuntimeBinder.RuntimeBinder.PopulateSymbolTableWithPayloadInformation(DynamicMetaObjectBinder payload,Type callingType,ArgumentObject [] arguments)\ r \ n
在Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore(DynamicMetaObjectBinder有效负载,IEnumerable 1参数,DynamicMetaObject [] args,DynamicMetaObject和deferredBinding)\ r \ n
在Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind(DynamicMetaObjectBinder有效负载,IEnumerable 1参数,DynamicMetaObject [] args,DynamicMetaObject和deferredBinding)\ r \ n
在Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind(DynamicMetaObjectBinder action,RuntimeBinder binder,IEnumerable 1 args,IEnumerable 1 arginfos,DynamicMetaObject onBindingError)\ r \ n
在Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target,DynamicMetaObject [] args,DynamicMetaObject errorSuggestion)\ r \ n
在System.Dynamic.DynamicMetaObject.BindInvokeMember(InvokeMemberBinder binder,DynamicMetaObject [] args)\ r \ n
在System.Dynamic.InvokeMemberBinder.Bind(DynamicMetaObject target,DynamicMetaObject [] args)\ r \ n
在System.Dynamic.DynamicMetaObjectBinder.Bind(Object [] args,ReadOnlyCollection 1参数,LabelTarget returnLabel)\ r \ n
在System.Runtime.CompilerServices.CallSiteBinder.BindCore [T](CallSite 1 site,Object [] args)\ r \ n
在System.Dynamic.UpdateDelegates.UpdateAndExecute2 [T0,T1,TRet](CallSite站点,T0 arg0,T1 arg1)\ r \ n
在BC_Game.ViewModel.ChampionViewModel.FindParentOfType [T](DependencyObject o)\ r \ n
at BC_Game.ViewModel.ChampionViewModel.ManStart(ManipulationStartedEventArgs e)“string

Update

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

update

从Visual Studio 2013 wp 8.1

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)\参考程序集\ 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:\程序文件(x86)\参考程序集\ 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 Assem blies \ 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 ShieldGearMode l.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

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)\参考程序集\ 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:\程序文件(x86)\参考程序集\ 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 Assem blies \ 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 .

Update

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

2 回答

  • 1

    您可以尝试在此链接后更改.net版本 .

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

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

  • 0

    我只是猜测,因为你没有发布错误信息本身 . 通常,除了注释中提到的默认.NET运行时版本之外,VS2013和VS2015之间应该没有区别 .

    但是看一下静态部分的代码可能是问题

    VisualTreeHelper.GetParent(o);
    

    有时在初始化对象之前需要遵循序列并且可以使用这些序列 .

    查看调用方法的位置也很有帮助 .

    但是我通过搜索VisualTreeHelper.GetParent null在谷歌中找到了这个

    VisualTreeHelper.GetParent returns null

相关问题