none
Specified value has invalid Control characters RRS feed

  • Question

  • Hello,

    I have a WCF service hosted in Windows Service. When any request fails, I have to send the error message that should be read from a file. 

                    

    OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;

    response.ContentType = request.Accept; response.StatusCode = (HttpStatusCode)httpResponse["statusCode"]; response.StatusDescription = (String)httpResponse["error"]; return null;

    Here, httpResponse["error"] is the text that is read from a file. However, it gives me an error:

    "Specified value has invalid Control characters" . It seems that, response.StatusDescription property is not good for control characters.

    Am I missing something here? 

    Thank you in advance!

    Monday, August 13, 2018 7:08 AM

All replies

  • Maybe a simple (string)httpResponse["error"]).Trim() will help if the string contains some unneeded end-of-line characters, for example. But, you should better investigate the content of this string, and give details.


    Monday, August 13, 2018 7:58 AM
  • Content of the string is:

    -> 05/07/18 15:23:28
    DSLS
    Erreur : ERROR 1A00003A:  No more licenses available on server
    License servers configuration file path:
       C:\ProgramData\DassaultSystemes\Licenses\DSLicSrv.txt (default path)
    List of declared servers:
            [01/01] localhost:4085 OK: License server is running

    Monday, August 13, 2018 8:01 AM
  • Hi NavnathK,

    According to your description, your issue is more related about WCF. And this forum is discussing and asking questions about the Windows Form and ClickOnce, I will move this thread to corresponding forum: Windows Communication Foundation, Serialization, and Networking Forum for dedicated information.

    Thank you for your understanding.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 14, 2018 7:06 AM
  • Hi Navanthk,

    According to your description, I have a question about how do you define the structure of your HttpResponse Dictionary? Could you explicitly convert httpresponse dictionary to string correctly? For example, your value is byte[], any attempt to convert byte[] to UTF-8 text is invalid.

    As mentioned in the error text, this error could also be caused by the string contains some control characters, such as \n, \r, \t.

    Feel free to let me know if you have any questions.

    Best Regards

    Abraham
    Wednesday, August 15, 2018 9:37 AM
    Moderator
  • Hello Abraham,

    No, my value is not byte[]. It is a string as you can see in the below code.

    Here is my code to read the error from file:

            public static string getReqtifyLastError()
            {            
                Encoding e = new StreamReader(ServerConfig.LOG_FILE_PATH, true).CurrentEncoding;
                   
                String content = File.ReadAllText(ServerConfig.LOG_FILE_PATH,e);
                if (content.Length > 0)
                {
                    int index = content.LastIndexOf("->");
                    string lastError = content.Substring(index, (content.Length - (index)));
                    lastError = ".\nException Text:\n" + lastError;                
                    return lastError;
                }
                else {
                    return String.Empty;
                }                                                                                                                     
            }

    And here is the stack trace:

    System.Net.HttpListenerResponse.set_StatusDescription(String value)
    System.ServiceModel.Channels.HttpOutput.ListenerResponseHttpOutput.SetStatusDescription(String statusDescription)
    System.ServiceModel.Channels.HttpOutput.ListenerResponseHttpOutput.PrepareHttpSend(Message message)
    System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
    System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReplyCore(Message message, TimeSpan timeout)
    System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.SendReply(Message message, TimeSpan timeout)
    System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)
    System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
    System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc& rpc)

    Sorry for the late reply. 



    • Edited by NavnathK Thursday, August 30, 2018 7:21 AM
    Thursday, August 30, 2018 7:19 AM
  • Hi NavnathK,

    Sorry for the late response.

    According the content of the string provided by you.

    [quote]

    -> 05/07/18 15:23:28

    DSLS

    Erreur : ERROR 1A00003A:  No more licenses available on server

    License servers configuration file path:

       C:\ProgramData\DassaultSystemes\Licenses\DSLicSrv.txt (default path)

    List of declared servers:

            [01/01] localhost:4085 OK: License server is running

    [/quote]

    [quote]

    lastError = ".\nException Text:\n" + lastError; 

    [/quote]

    Apparently, the string contains control characters, so that it throws the error with “Specified value has invalid Control characters”. I suggest you should manipulate the string before assigning the value to the property.

    Do you try to assign a string with no control characters to this property? It seems that this property should be able to set these control characters.

    Feel free to let me know if the problem still exists.

    Best Regards

    Abraham

    Tuesday, September 18, 2018 2:21 AM
    Moderator