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'
本文标签:
版权声明:本文标题:c++ cli - Updating C++CLI assembly to .NET 9 gives new warning about Enumerable.CountBy and AggregateBy - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738483504a2089283.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论