Question

When I have this c++ cli code:

#pragma managed
ref class mcSessions: ConcurrentDictionary <String ^, mcSession^> 
{  //<---- warning here
private:
   static mcSessions ^g_Sessions;
       TimeSpan MaxIdleTime;
   mcSessions (TimeSpan newMaxIdleTime);
public:
    static void Initialize (long MaxIdleMinutes);
        static void Shutdown ();
        static void CreateSession (String ^&SessionId);
        static void RunInSession (String ^SessionId, String ^Command);
        static void RemoveSession (String ^SessionId);
};

I get a warning C4538 on the first {. Does anybody has any clue why this happens and what it warns for, or is this also a compiler bug as it is for the situation in this question: Seemingly inappropriate compilation warning with C++/CLI

Although I see they are somewhat related, I do not have a Group object but a ConcurrentDictionary. I am using Visual Studio 2010 targeting the .NET 4.0 framework and compiling with the /clr compiler flag on.

The exact error message is:

1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=System::Collections::Concurrent::ConcurrentDictionary::Node ^,
1>              dimension=1
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=int,
1>              dimension=1
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=System::Collections::Concurrent::ConcurrentDictionary<TKey,TValue>::Node ^,
1>              dimension=1
1>          ]
1>          d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25) : see reference to class generic instantiation 'System::Collections::Concurrent::ConcurrentDictionary<TKey,TValue>' being compiled
1>          d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25) : see reference to class generic instantiation 'System::Collections::Concurrent::ConcurrentDictionary<TKey,TValue>' being compiled
1>          with
1>          [
1>              TKey=System::String ^,
1>              TValue=IamPowershell::mcSession ^
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary::Node ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=int,
1>              dimension=1
1>          ]
1>          This diagnostic occurred while importing type 'System::Collections::Concurrent::ConcurrentDictionary::Node ' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=System::Collections::Concurrent::ConcurrentDictionary<System::String ^,mcSession ^>::Node ^,
1>              dimension=1
1>          ]
1>d:\t4edevnet2010\umra2\iampowershell\mcIpSessions.h(25): warning C4538: 'cli::array<Type,dimension> ^' : const/volatile qualifiers on this type are not supported
1>          with
1>          [
1>              Type=int,
1>              dimension=1
1>          ]
1>
Was it helpful?

Solution 2

As @HansPassant noted in the comment on the question he is right. The members are indeed volatile (stupid me, could have checked that :S) Anyway that should be the answer. Thankx I consider it solved now.

OTHER TIPS

As noted, the issue is the volatile members in ConcurrentDictionary. However, from the code you've shown, you don't need to inherit from ConcurrentDictionary.

In general, I believe you only need to inherit from collection classes if you're making a generic, reusable collection class. That doesn't appear to be the case here, it appears to be very specific to the mcSession class, and probably has business logic, not simple collection logic.

Would it work if you declared your class like this?

ref class mcSessions
{
private:
    static ConcurrentDictionary<String^, mcSession^>^ g_Sessions;
    TimeSpan MaxIdleTime;
    mcSessions (TimeSpan newMaxIdleTime);
public:
    static void Initialize (long MaxIdleMinutes);
    static void Shutdown ();
    static void CreateSession (String ^&SessionId);
    static void RunInSession (String ^SessionId, String ^Command);
    static void RemoveSession (String ^SessionId);
};

Edit: or like this?

ref class mcSessions
{
private:
    static mcSessions^ g_Sessions;// static session manager
    ConcurrentDictionary<String^, mcSession^>^ SessionList; // instance variable on g_Sessions
    TimeSpan MaxIdleTime;
    mcSessions (TimeSpan newMaxIdleTime);
public:
    static void Initialize (long MaxIdleMinutes);
    static void Shutdown ();
    static void CreateSession (String ^&SessionId);
    static void RunInSession (String ^SessionId, String ^Command);
    static void RemoveSession (String ^SessionId);
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top