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>
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);
};
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.
Related
There is an error if class inherits from Polyhedron_3 and used in stitch_borders, but if I use the Polyhedron_3 directly in stitch_borders there is no error.
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
class StitchPolyhedron : public CGAL::Polyhedron_3<K>
{
public:
StitchPolyhedron() {}
virtual ~StitchPolyhedron() {}
};
StitchPolyhedron mesh;
CGAL::Polygon_mesh_processing::stitch_borders(mesh);
Code above gives an error
vertex_descriptor': is not a member of 'StitchPolyhedron'
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K> StitchPolyhedron;
StitchPolyhedron mesh;
CGAL::Polygon_mesh_processing::stitch_borders(mesh);
Code above compiles fine.
Can anyone point me what is the issue here.
Your inherited class must be a model of FaceListGraph. Usually adding in a boost namespace the following partial specialization should be sufficient:
namespace boost {
struct boost::graph_traits<POLYHEDRON_TYPE>:
public boost::graph_traits<BASE_POLYHEDRON_TYPE>
{};
} // namespace boost
You might need to forward properties as well. Add in a boost namespace the following partial specialization:
namespace boost{
template <class Tag>
struct property_map<POLYHEDRON_TYPE, Tag> :
public property_map<BASE_POLYHEDRON_TYPE, Tag>
{};
} //namespace boost
whenever I use RazorEngine in my application I get the following error:
{"FailedAt":"2014-11-12T02:51:59.9765953Z","ExceptionType":"RazorEngine.Templating.TemplateCompilationException","ExceptionMessage":"Unable to compile template. Assuming assembly reference 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy\n\nOther compilation errors may have occurred. Check the Errors property for more information.","ExceptionDetails":"RazorEngine.Templating.TemplateCompilationException: Unable to compile template. Assuming assembly reference 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy\n\nOther compilation errors may have occurred. Check the Errors property for more information.\r\n at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in c:\Users\abbottm\Documents\GitHub\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 106\r\n at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in c:\Users\abbottm\Documents\GitHub\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 256\r\n at RazorEngine.Templating.TemplateService.GetTemplate[T](String razorTemplate, Object model, String cacheName) in c:\Users\abbottm\Documents\GitHub\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 374\r\n at RazorEngine.Templating.TemplateService.GetTemplate(String razorTemplate, Object model, String cacheName) in c:\Users\abbottm\Documents\GitHub\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 352\r\n at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName) in c:\Users\abbottm\Documents\GitHub\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 437\r\n at RazorEngine.Razor.Parse(String razorTemplate, Object model, String cacheName) in c:\Users\abbottm\Documents\GitHub\RazorEngine\src\Core\RazorEngine.Core\Razor.cs:line 302\r\n at Postal.FileSystemRazorView.Render(ViewContext viewContext, TextWriter writer)\r\n at Postal.EmailViewRenderer.RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext, ImageEmbedder imageEmbedder)\r\n at Postal.EmailViewRenderer.Render(Email email, String viewName)\r\n at Postal.EmailService.CreateMailMessage(Email email)\r\n at NumediaTechCore.UI.Controllers.Admin.EmailsController.SendEmail(Int32 EmailTemplateID) in c:\NumediaTech\NumediaTechPortal\NumediaTechCore\UI\Controllers\Admin\EmailsController.cs:line 105"}
I am trying to add a custom converter (Boolean to Visibility). The code for the converter is just fine. It seems to map ok. However, when I try and add it as a resource for a User Control I get an Invalid Markup which says "BooleanToVisibilityConverter was not found. Verify you are not missing an assembly and that all referenced assemblies have been built". Even with this Invalid Markup showing the project compiles and runs with no errors or crashes.
I am using Visual Studio 2013 on Windows 8.1
converter .h file:
#pragma once
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Interop;
namespace BooleanConverter{
public ref class BooleanToVisibilityConverter sealed : IValueConverter
{
public:
virtual Platform::Object^ Convert(
Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName targetType,
Platform::Object^ parameter,
Platform::String^ language);
virtual Platform::Object^ ConvertBack(
Platform::Object^ value,
Windows::UI::Xaml::Interop::TypeName targetType,
Platform::Object^ parameter,
Platform::String^ language);
};
}
converter .cpp file:
#include "pch.h"
#include "BooleanToVisibilityConverter.h"
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Data;
Object^ BooleanConverter::BooleanToVisibilityConverter::Convert(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
auto boxedBool = dynamic_cast<Box<bool>^>(value);
auto boolValue = (boxedBool != nullptr && boxedBool->Value);
return (boolValue ? Visibility::Visible : Visibility::Collapsed);
}
Object^ BooleanConverter::BooleanToVisibilityConverter::ConvertBack(Object^ value, TypeName targetType, Object^ parameter, String^ language)
{
throw ref new Platform::NotImplementedException();
}
the xaml code:
<UserControl
x:Class="SimpleShop.JobItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SimpleShop"
xmlns:converters="using:BooleanConverter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="1030" Height="Auto" Background="Black">
<UserControl.Resources>
<ResourceDictionary>
<converters:BooleanToVisibilityConverter x:Key="BooleanToCollapesdConverter"/>
</ResourceDictionary>
</UserControl.Resources>
I've tried changing the xmlns statement to:
xmlns:converters="clr-namespace:BooleanConverter"
but that throws up errors saying the BooleanConverter namespace can not be found
The really odd part is that if I delete the xmlns statement and re-type it in, intellisense says that the namespace can not be found. However if I simply copy and paste that line back over its self the error on the xmlns statement goes away.
How do I get rid of this Invalid Markup which doesn't seem to be invalid at all since it compiles and runs. Or have I missed something in implementing this converter? I am using MSDN as a reference (http://msdn.microsoft.com/en-us/library/ms747086(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1) and, to me, it doesn't look like I've implemented this wrong.
Please let me know if I need to supply more code but I believe this is everything that is relevant.
WinRT namespace lookup rules require that all namespaces published by a winmd live in a winmd with the same name (or a root namespace name). That is, a class named "MyNamespace.MySubNamespace.MyClass" must live in either MyNamespace.winmd or MyNamespace.MySubNamespace.winmd, otherwise it cannot be reliably found by all type loaders.
I think your issue is that your namespace is ::Converters, but your boolean converter class is probably hiding inside SimpleShop.winmd. I would try changing the namespace (and references) to SimpleShop::Converters and see if this resolves your issue.
I am able to call a COM interface method using SAFEARRAY(BSTR) as input. If I define instead a simple (containing only some BSTR-s fields) STRUCT to pass into the COM I get
"[System.ArgumentException] = {"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
The call to my COM server is not made because as it seems the arguments from client does not match the expected arguments on server: E_INVALIDARG
Here is my declaration in IDL:
typedef enum UserEntityType
{
User,
Group,
IPAddress
} UserEntityType;
[
uuid(4786F77E-BA5F-4806-B224-12AA8601A5B1)
]
typedef struct UserEntity
{
UserEntityType EntityType;
BSTR Value;
} UserEntity;
[id(9)] HRESULT SetUsers([in] SAFEARRAY(UserEntity) input);
The exception is thrown at run-time when a C# 4 client calls SetUsers().
The problem was in the C# client that was using the exe COM server where
SetUsers([in] SAFEARRAY(UserEntity) input)
was defined.
In order to fix this (at least for .NET 4.0) one has to change the following property of the imported COM server: Embed Interop Types = False
I'm new to C++ CLI coming from unmanaged C++ world.
I'm getting this error:
candidate function(s) not accessible
when I pass a std::string as part of the method argument.
Here's the exact code:
Lib Project (compiled as .dll project)
//Lib.h
#pragma once
public ref class Lib
{
public:
Lib(void);
public:
void Extract( std::string& data_ );
};
//Lib.cpp
#include "Lib.h"
Lib::Lib(void)
{
}
void Lib::Extract( std::string& data_ )
{
data_.empty();
}
LibTest Project (compiled as application.exe)
// LibTest.h
#pragma once
ref class LibTest
{
public:
LibTest(void);
};
// LibTest.cpp
#include "LibTest.h"
LibTest::LibTest(void)
{
Lib^ lib = gcnew Lib;
lib->Extract( std::string("test") );
}
int main()
{
return 0;
}
Compiler Error:
1>------ Build started: Project: LibTest, Configuration: Debug Win32 ------
1>Compiling...
1>LibTest.cpp
1>.\LibTest.cpp(7) : error C3767: 'Lib::Extract': candidate function(s) not accessible
The problem is that std::string will compile as a internal (non public) type. This is actually a change in VS 2005+:
http://msdn.microsoft.com/en-us/library/ms177253(VS.80).aspx:
Native types are private by default outside the assembly
Native types now will not be visible outside the assembly by default. For more information on type visibility outside the assembly, see Type Visibility. This change was primarily driven by the needs of developers using other, case-insensitive languages, when referencing metadata authored in Visual C++.
You can confirm this using Ildasm or reflector, you will see that your extract method is compiled as:
public unsafe void Extract(basic_string<char,std::char_traits<char>,std::allocator<char> >* modopt(IsImplicitlyDereferenced) data_)
with basic_string being compiled as:
[StructLayout(LayoutKind.Sequential, Size=0x20), NativeCppClass, MiscellaneousBits(0x40), DebugInfoInPDB, UnsafeValueType]
internal struct basic_string<char,std::char_traits<char>,std::allocator<char> >
Note the internal.
Unfortunately you are then unable to call a such a method from a different assembly.
There is a workaround available in some cases: You can force the native type to be compiled as public using the make_public pragma.
e.g. if you have a method Extract2 such as:
void Extract2( std::exception& data_ );
you can force std::exception to be compiled as public by including this pragma statement beforehand:
#pragma make_public(std::exception)
this method is now callable across assemblies.
Unfortunately make_public does not work for templated types (std::string just being a typedef for basic_string<>)
I don't think there is anything you can do to make it work. I recommend using the managed type System::String^ instead in all your public API. This also ensures that your library is easily callable from other CLR languages such as c#
if you simply must access the internal methods another work around would be making the projects as Friend Assemblies like that:
//Lib Project
#pragma once
//define LibTest as friend assembly which will allow access to internal members
using namespace System;
using namespace System::Runtime::CompilerServices;
[assembly:InternalsVisibleTo("LibTest")];
public ref class Lib
{
public:
Lib(void);
public:
void Extract( std::string& data_ );
};
//LibTest Project
#pragma once
#using <Lib.dll> as_friend
ref class LibTest
{
public:
LibTest(void);
};
In addition to the solutions described above, one can subclass the templated type to obtain a non-templated type, and include its definition in both projects, thus overcoming some of the problems mentioned above.