I am trying to use a cliext::list<> and am hitting various problems - apologies, its a long one - but stick with me :) . Before I start, I am using Visual Studio 2008 with service pack 1. I am (relatively) new to mixed mode programming - my background is pure C++ / MFC, etc - so it is entirely possible I am misunderstanding something. I have reduced my first problem to the following:
Header file:
#pragma once
#include <cliext/list>
private ref class TestClass
{
cliext::list<int> ^ m_list;
public:
TestClass(void);
};
.cpp file:
#include "StdAfx.h"
#include "TestClass.h"
TestClass::TestClass(void)
: m_list(gcnew cliext::list<int>())
{
}
Produces this little lot... (project name is LNK2022)
1>------ Build started: Project: LNK2022, Configuration: Debug Win32 ------
1>Linking...
1>TestClass.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.list_impl<int,0>; fields: _Myhead): (0x0400000a).
1>TestClass.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.list_impl<int,0>; fields: _Mysize): (0x0400000b).
1>TestClass.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.list_impl<int,0>; fields: _Mygen): (0x0400000c).
1>TestClass.obj : error LNK2022: metadata operation failed (801311D7) : Differing number of fields in duplicated types (cliext.impl.list_impl<int,0>-): (0x02000023).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_impl<int,0>; interfaces: System.Runtime.CompilerServices.CallConvStdcall): (0x09000001).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_impl<int,0>; interfaces: System.IDisposable): (0x09000002).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_base<int,0>; interfaces: System.Runtime.CompilerServices.CallConvFastcall): (0x09000003).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_base<int,0>; interfaces: System.Runtime.CompilerServices.CallConvThiscall): (0x09000004).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (cliext._Dehandle<int>-): (0x02000021).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (cliext.is_handle<int>-): (0x02000022).
1>LINK : fatal error LNK1255: link failed because of metadata errors
1>Build log was saved at "file://i:\dev\ians stuff\LNK2022\LNK2022\Debug\BuildLog.htm"
1>LNK2022 - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Does anyone have any ideas? If I initialise the list in the header, the program compiles and links ok.
Ok, fine, I can live with that unless I want to hide my implementation of the constructor in the .cpp to reduce dependencies (my code is more complicated).
Anyway, next problem...
Header file:
#pragma once
#include <cliext/list>
private ref class TestClass
{
ref struct SInside
{
int mem1;
};
cliext::list<SInside ^> ^ m_list;
public:
TestClass()
: m_list(gcnew cliext::list<SInside ^>())
{}
};
No particular rocket science here, a nested struct being used as the type for the list container. Note initialisation in header - constructor removed from .cpp 'cos of point one above.
As soon as we construct the an object of type TestClass with the following in the form constructor:
TestClass ^ tmp = gcnew TestClass();
I get a message box with the following (my test app compiles to LNK2022.exe):
An unhandled exception of type 'System.TypeLoadException' occurred in LNK2022.exe
Additional information: Access is denied: 'Microsoft.VisualC.StlClr.IList`1[TestClass+SInside]'.
I am really not sure even what this is trying to tell me, but what I do know - after a lot of searching and head scratching (and randomly moving code) - if I move the nested struct outside of the class declaration, everything is fine. Again, in my real example this reduces my encapsulation, and I would rather not do it if possible.
If I move the nested struct to a public section of the class, all is ok too. I have tried the equivalent using std::list, and again all is fine (with a list of objects or pointers).
Question is, am I trying to do something that is not supported, have I done something obviously wrong, or is this a bug in the STL.net library?
<div class="ForumMod">modified on Wednesday, August 27, 2008 9:38 AM</div>