Archived
Ice::UnknownException happend when Pass a std::string parameter in a function
I develop a server using VC++ MFC ,and a client using c#,
I define .ice file below
module UIServerInteract
{
//GUI界面需要实现的接口,供后台软件调用
interface IServerEvent
{
//向对话显示区中新增问题
void NewQuestionAdd(string strQuestion);
//向对话显示区中新增问题 void NewAnswerAdd(int iType, string strAnswer); //退出应用 void ExitApp(); //TestInterface void Test(int itype); }; //后台软件需要实现的接口,供UI调用 interface BGServer { bool Login(string strUser,IServerEvent* pSvrEvent); void Logout(string strUser); };
};
when I call NewQuestionAdd(string strQuestion) function like
m_UISvrPrx->NewQuestionAdd("1212");
in server ,it throws a Ice::UnknownException, but the string value has been shown in client.
but I call Test(int itype) function , no exception happens.
when call Login(string strUser,IServerEvent* pSvrEvent) funtion in client , no exception happens.
my question is: is there a special string code page when passing the parameter?
how this exception happen?
I've tried 3.4.2, 3.6.3 &3.70b version,3.4.2 does not work properly at all, but last two throws exception.
i am using win7 & vs2015 community.
Comments
-
Any one got idea?who can help me?
0 -
Hi,
Sounds like the C++ server isn't sending a valid UTF-8 string to the C# client.
Where do you get the
Ice::UnknownException
exception? In the C# client or C++ server? Is it the C++ server which is making the call? The exception has anunknown
data member, you should try printing out this data member to see the cause of the exception.// C# try { ... } catch(Ice.UnknownException ex) { System.Console.WriteLine("unknown exception:\n" + ex.unknown); }
In C++, you should use a string converter if you want to use strings encoded with a native encoding with the Ice APIs. The string converter will convert the native string to UTF-8 before sending it.
See https://doc.zeroc.com/pages/viewpage.action?pageId=16716075 for more information on C++ string converters.
Cheers,
Benoit.0 -
I've been busy at other projecct for several days , sorry for that long time.
my server break to exception.
I called function in c++ server like thisif (NULL != m_UISvrPrx) { try { string utfstr = AnsiToUtf8(strQuestion); m_UISvrPrx->NewQuestionAdd(AnsiToUtf8(strQuestion));//this line will triger exception } catch (Ice::UnknownException* e) { _RPT1(_CRT_WARN,"exception happend : %s\n",e->unknown); } }
but it always break to exception in below code line:__invoke(__og);
void IceProxy::UIServerInteract::IServerEvent::NewQuestionAdd(const ::std::string& __p_strQuestion, const ::Ice::Context* __ctx) { ::IceInternal::Outgoing __og(this, __UIServerInteract__IServerEvent__NewQuestionAdd_name, ::Ice::Normal, __ctx); try { ::IceInternal::BasicStream* __os = __og.startWriteParams(::Ice::DefaultFormat); __os->write(__p_strQuestion); __og.endWriteParams(); } catch(const ::Ice::LocalException& __ex) { __og.abort(__ex); } __invoke(__og);//this line is the last position exception break to }
it never log to output the exception info.
I tried to continue the C++ Server and the c# client can view the string pass to it ,and the server always break to exception.0 -
Hi,
Sorry, but it's still no clear to me what's happening. If I understanding it correct, the
NewQuestionAdd
is dispatched on the C# client but it raises an exception. Can you provide the type and stack of the exception which has been raised?Cheers,
Benoit.0 -
I've solved the problem. The exception does not caused by Ice.The source is c# client function changes UI control value directly,where it is not allowed in c# winform project called thread cross calling.
thank you all the same @ Benoit Foucher .0