首页 新闻 会员 周边

CoreCLR: Managed object size does not match unmanaged object size

0
悬赏园豆:30 [已解决问题] 解决于 2015-02-21 16:26

在Windows中签出coreclr的代码库,通过build unixmscorlib命令编译出mscorlib.dll。

然后在Mac OS X中使用这个mscorlib.dll运行.NET程序时,出现如下的错误:

Assert failure (unable to format)
/git/dotnet/coreclr/src/vm/binder.cpp
Consistency check failed: Managed object size does not match unmanaged object size
man: 0x18, unman: 0x20, Name: System.Runtime.InteropServices.CriticalHandle
FAILED: size == expectedsize
**** MessageBox invoked, title 'Assert failure (unable to format)' ****
  Consistency check failed: Managed object size does not match unmanaged object size
man: 0x18, unman: 0x20, Name: System.Runtime.InteropServices.CriticalHandle
FAILED: size == expectedsize
********

Assert failure (unable to format)
/git/dotnet/coreclr/src/vm/binder.cpp
pFD != NULL
**** MessageBox invoked, title 'Assert failure (unable to format)' ****
  pFD != NULL
********

ExecuteAssembly failed - status: 0x80004005

请问如何解决这个问题?

dudu的主页 dudu | 高人七级 | 园豆:31003
提问于:2015-02-16 14:43
< >
分享
最佳答案
0

当时用的是release版的mscorlib.dll,后来改用debug版的mscorlib.dll,问题就消失了。

dudu | 高人七级 |园豆:31003 | 2015-02-21 16:26
其他回答(1)
0

字节对齐?

IntPtr.Size == 4?

收获园豆:30
Launcher | 园豆:45045 (高人七级) | 2015-02-16 14:58

问题的确与字节对齐有关

支持(0) 反对(0) dudu | 园豆:31003 (高人七级) | 2015-02-16 15:10

在Mac OS X上,IntPtr.Size的值是8。

支持(0) 反对(0) dudu | 园豆:31003 (高人七级) | 2015-02-17 15:54

@dudu: x64 的。 man: 0x18, unman: 0x20,前者是 24(3),后者是 32(4),所以不知道这 size 是表示的指针类型,还是结构体大小。

支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2015-02-17 15:58

@Launcher: 出现错误的代码位置:

pMT = ClassLoader::LoadTypeByNameThrowing(GetModule()->GetAssembly(), p->classNameSpace, p->className).AsMethodTable();

if (p->expectedClassSize == sizeof(NoClass))
    continue;

// hidden size of the type that participates in the alignment calculation
DWORD hiddenSize = pMT->IsValueType() ? sizeof(MethodTable*) : 0;

DWORD size = pMT->GetBaseSize() - (sizeof(ObjHeader)+hiddenSize);

DWORD expectedsize = (DWORD)ALIGN_UP(p->expectedClassSize + (sizeof(ObjHeader) + hiddenSize),
    DATA_ALIGNMENT) - (sizeof(ObjHeader) + hiddenSize);

CONSISTENCY_CHECK_MSGF(size == expectedsize,
    ("Managed object size does not match unmanaged object size\n"
    "man: 0x%x, unman: 0x%x, Name: %s\n", size, expectedsize, pMT->GetDebugClassName()));

代码文件:https://github.com/dotnet/coreclr/blob/master/src/vm/binder.cpp

支持(0) 反对(0) dudu | 园豆:31003 (高人七级) | 2015-02-17 16:13

@dudu: 比较下 release 和 deubg 的 DATA_ALIGNMENT 值是否一致。

支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2015-02-25 09:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册