Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Registering RawProxyEncoder Causes Stack Overflow #1427

Closed
@richard-gemmell-42

Description

@richard-gemmell-42

Environment

  • Pythonnet version: installed from master branch on 30th March 2021
  • Python version: 3.9.2
  • Operating System: Windows 10
  • .NET Runtime: Microsoft.NETCore.App 5.0.4, Microsoft.WindowsDesktop.App 3.1.13

Summary

Registering aRawProxyEncoder withPyObjectConversions.RegisterEncoder() causes the script to fail with a stack overflow.

Thanks

First of all, I'd like to say thanks to everyone who's contributed to this project. It's incredibly useful for us to write one set of code to serve both .NET and Python developers. We've had very few problems with Pythonnet. Thanks very much.

Details

I ran into a problem with Pythonnet converting System.Collections.Generic.List into a native python list as described inissue 1153.

lostmsu recommended using a RawProxyEncoder to disable the automatic conversion. Unfortunately, if I register an encoder and then call a .NET method the system crashes with a stack overflow.

importsysfrompathlibimportPathfromclr_loaderimportget_coreclrfrompythonnetimportset_runtimeapi_path=Path('..\\PythonStubs\\bin\\Debug\\netcoreapp3.1')sys.path.append(str(api_path))rt=get_coreclr(runtime_config=str(api_path/f'PythonStubs.runtimeconfig.json'))set_runtime(rt)importclrimportSystemfromPython.RuntimeimportPyObjectConversionsfromPython.Runtime.CodecsimportRawProxyEncoderclassListAsRawEncoder(RawProxyEncoder):__namespace__='Dummy'defCanEncode(self,clr_type):returnclr_type.Name=='IList`1'andclr_type.Namespace=='System.Collections.Generic'if__name__=='__main__':list_encoder=ListAsRawEncoder()PyObjectConversions.RegisterEncoder(list_encoder)domain=System.AppDomain.CurrentDomainprint("Found",domain.GetAssemblies().Length,"assemblies in domain")

The output is:

    Stack overflow

Commenting out the call to RegisterEncoder prevents the crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp