Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to cast object of type 'Int32' to type 'Dictionary`2'. #771

Open
hui1993 opened this issue May 21, 2024 · 2 comments
Open

Unable to cast object of type 'Int32' to type 'Dictionary`2'. #771

hui1993 opened this issue May 21, 2024 · 2 comments

Comments

@hui1993
Copy link

hui1993 commented May 21, 2024

偶现的类型转换错误

代码如下:
public bool TryGetItem(Hex hex, out T item)
{
var key = GetHexkey(hex);
if(_map.ContainsKey(key))
{
item = _map[key];
return true;
}
item = default;
return false;
}

_map是dictionary

可能跟范型有关,准备去掉试试

@hui1993
Copy link
Author

hui1993 commented Jun 19, 2024

简化了代码,去掉范型约束之后,线上无报错。猜测跟范型约束有关,其他小伙伴可以参考

@lixu19950414
Copy link

ILMethod中设置def.Body = null,结合泛型类型使用就会有小概率造成这个问题。具体原理不明。2.1.0版本,不开启jit
#if !DEBUG || DISABLE_ILRUNTIME_DEBUG
//Release Method body to save memory
if(!noRelease)
def.Body = null;
#endif

注释掉def.Body = null 可以解决,但是会增加很多堆内存

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants