加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 22:30:26 所属栏目:百科 来源:网络整理
导读:在Visual Studio 2013和2015中运行一段代码时,我得到两个不同的结果.在Visual Studio 2015上,我获得了NullReference,并且在2013年它的工作方式应该如此. Visual Studio 2015也在 Windows 8.1上的 Windows 10和2013上运行.这段代码是: private static T Find
在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中找到的希望Grid?

堆栈跟踪

06002

更新

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

更新

从Visual Studio 2013 wp 8.1

C:Program Files (x86)MSBuild12.0binCsc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158mscorlib.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158Microsoft.CSharp.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158mscorlib.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Core.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Net.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Runtime.Serialization.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.ServiceModel.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.ServiceModel.Web.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Windows.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Xml.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Xml.Linq.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Xml.Serialization.dll” /debug+ /debug:full /filealign:512 /optimize- /out:objDebugLibraryOfModels.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 PropertiesAssemblyInfo.cs RankingDTO.cs RankingModel.cs ShieldGearModel.cs UnitModel.cs UserDTO.cs WarCalculations.cs “C:UsersJonasAppDataLocalTemp.NETPortable,Version=v4.0,Profile=Profile158.AssemblyAttributes.cs”

来自VS 2015 Win 10

C:Program Files (x86)MSBuild14.0bincsc.exe /noconfig /nowarn:1701,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158mscorlib.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158Microsoft.CSharp.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158mscorlib.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Core.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Net.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Runtime.Serialization.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.ServiceModel.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.ServiceModel.Web.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Windows.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Xml.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Xml.Linq.dll” /reference:”C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile158System.Xml.Serialization.dll” /debug+ /debug:full /filealign:512 /optimize- /out:objDebugLibraryOfModels.dll /ruleset:”C:Program Files (x86)Microsoft Visual Studio 14.0Team ToolsStatic Analysis ToolsRule SetsMinimumRecommendedRules.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 PropertiesAssemblyInfo.cs RankingDTO.cs RankingModel.cs ShieldGearModel.cs UnitModel.cs UserDTO.cs WarCalculations.cs “C:UsersjohannAppDataLocalTemp.NETPortable,Profile=Profile158.AssemblyAttributes.cs”

我们在两者之间可以看到的唯一区别是正在使用的.NetFrameworks.一个版本为4.5.51650,另一个版本为4.6.01038.

更新

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

解决方法

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读