使用KendoDynamicLinq的项目VS2017报TargetException,VS2013正常求助
I’ve dealt with similar compatibility headaches when migrating projects between Visual Studio versions, so let’s walk through the most likely fixes and debugging angles for your issue:
Check .NET Framework Target Version
VS2017 often defaults to newer .NET Framework versions (like 4.6+) compared to VS2013’s typical 4.5.x setup. Older builds of KendoDynamicLinq might have subtle reflection behavior breaks across framework versions. Right-click your project → Properties → Application, and set the target framework to exactly match what you used in VS2013. If this resolves the error, you can test upgrading the framework incrementally later once you confirm compatibility.Update KendoDynamicLinq to the Latest Stable Release
The version of KendoDynamicLinq you’ve been using for years was likely built for older tooling (like VS2013’s compiler). Head to NuGet Package Manager, search for KendoDynamicLinq, and install the most recent stable version. Many reflection-related bugs—including this "non-static method requires target" error—have been patched in newer releases to align with VS2017’s Roslyn compiler and runtime environments.Debug the Exact Reflection Failure
ThisTargetExceptionalmost always means a non-static method is being invoked with anulltarget object. To narrow it down:- Enable break-on-exceptions in VS2017 (Debug → Windows → Exception Settings, check "Common Language Runtime Exceptions").
- When the error fires, inspect the call stack to see which part of KendoDynamicLinq is making the faulty reflection call.
- Test if this happens with specific queries (e.g., empty datasets, certain filter/sort parameters)—sometimes the library fails to handle edge cases correctly when parsing Kendo UI’s request data.
Adjust Compiler and Project Settings
VS2017’s Roslyn compiler handles expression trees and code generation differently than VS2013’s older compiler. Try these tweaks:- In project properties → Build → Advanced, set the "Language version" to match what you used in VS2013 (e.g., C# 5.0 if that’s your original setup).
- Disable any new compiler features enabled by default in VS2017 (like nullable reference types, if you’re on a newer framework) to rule out unintended null-handling changes.
Debug with KendoDynamicLinq Source Code
If the above steps don’t work, grab the KendoDynamicLinq source code and add it as a project reference instead of using the NuGet package. This lets you set breakpoints directly in the library’s reflection logic to see exactly when and why the target object is null. For example, I’ve seen cases where the library tries to invoke a method on a null instance when processing emptyIQueryabledatasets.
内容的提问来源于stack exchange,提问作者emadev

