question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

str() failure when C# ToString() return unicode character

See original GitHub issue

Environment

  • Pythonnet version: 2.4.0.dev0 (master; #19d854c)
  • Python version: 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
  • Operating System: Windows 10 Pro 64 Bit (1803; 17134.5)

Details

  • Describe what you were trying to get done.
  1. Just call str python built-in function with C# class
  2. Raise UnicodeDecodeError if value is 안녕
  3. Return 안녕PADD if value is `안녕PADDINGX"

It seems like failure str convert with ToString() function only. (Another method, nor read value does not problem)

namespace Hello
{
    public class World
    {
        public string value = "안녕";

        public string GetString()
        {
            return value;
        }

        public override string ToString()
        {
            return value;
        }
    }
}
import clr
clr.AddReference("hello")
from Hello import World
world = World()
print(1, str(world.value))
print(2, str(world.GetString()))
print(3, str(world))
  • If there was a crash, please include the traceback here.
1 안녕
2 안녕
Traceback (most recent call last):
  File "main.py", line 7, in <module>
    str(hello)
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: unexpected end of data

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
denfromufacommented, May 10, 2018

@EcmaXp have a look at wiki about building pythonnet and @yagweb pull request, feel free to add a unit test for it:

https://github.com/pythonnet/pythonnet/wiki https://github.com/pythonnet/pythonnet/pull/670

1reaction
denfromufacommented, May 10, 2018

@EcmaXp pull requests are welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Contains Unicode Character checking fail
This code used to check unicode exist or not on input char array. I got error message : " ContainsUnicodeCharacter(char[])': not all code...
Read more >
[Solved] Contains Unicode Character checking fail
This code used to check unicode exist or not on input char array. I got error message : " ContainsUnicodeCharacter(char[])': not all code...
Read more >
Unicode HOWTO — Python 3.11.4 documentation
decode() is str.encode() , which returns a bytes representation of the Unicode string, encoded in the requested encoding. The errors parameter is ...
Read more >
Introduction to character encoding in .NET
This article provides an introduction to character encoding systems that are used by .NET. The article explains how the String, Char, Rune, ...
Read more >
How to use character encoding classes in .NET
This article explains how to use the classes that .NET provides for encoding and decoding text by using various encoding schemes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found