admin管理员组

文章数量:1193314

My C++/CLI assembly has a function that takes an IEnumerable. It calls Enumerable::Count() on it. This code has worked fine for multiple versions of .NET up through .NET 8. But when I updated it to .NET 9, I started getting 2 warnings (shown below). The warnings are about the CountBy and AggregateBy methods which my code does not use but this still concerns me.

What does this mean? Why is the parameter unsupported? And should I worry about this or just silence the warning?

The code is below. (It is a C++ function template designed to convert an IEnumerable of a .NET type into a std::vector of a C++ unmanaged type. NETTYPE is the managed type. SDKTYPE is the unmanaged type. The function ToSdk does the element-conversion)

template<typename NETTYPE, typename SDKTYPE> 
inline std::vector<SDKTYPE> ToSdkVec(IEnumerable<NETTYPE>^ vals)
{
    if (nullptr == vals)
        throw gcnew System::ArgumentNullException(EXCEPTION_NULLPTR);


    std::vector<SDKTYPE> outVec;
    outVec.reserve(Enumerable::Count(vals));  // Generates warning
    
    for each(auto v in vals)
        outVec.push_back(ToSdk(v));

    return outVec;
}

This is the compiler output:

19>C:\Users\jmole\source\repos\Main\Sdk\corecli\marshalcli.h(150,1): error C2220: the following warning is treated as an error
19>(compiling source file 'precompiled.cpp')
19>C:\Users\jmole\source\repos\Main\Sdk\corecli\marshalcli.h(150,1): warning C4564: method 'AggregateBy' of class 'System::Linq::Enumerable' defines unsupported default parameter 'keyComparer'
19>(compiling source file 'precompiled.cpp')
19>    C:\Users\jmole\source\repos\Main\Sdk\corecli\marshalcli.h(150,1):
19>    This diagnostic occurred while importing type 'System::Linq::Enumerable' from assembly 'System.Linq, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
19>    C:\Users\jmole\source\repos\Main\Sdk\corecli\marshalcli.h(150,1):
19>    the template instantiation context (the oldest one first) is
19>        C:\Users\jmole\source\repos\Main\Sdk\corecli\marshalcli.h(222,12):
19>        see reference to function template instantiation 'std::vector<std::string,std::allocator<_Ty>> Sdk::ToSdkVec<String^,std::string>(System::Collections::Generic::IEnumerable<System::String ^> ^)' being compiled
19>        with
19>        [
19>            _Ty=std::string
19>        ]
19>C:\Users\jmole\source\repos\Main\Sdk\corecli\marshalcli.h(150,1): warning C4564: method 'CountBy' of class 'System::Linq::Enumerable' defines unsupported default parameter 'keyComparer'

本文标签: