- Notifications
You must be signed in to change notification settings - Fork750
Closed
Description
Environment
- Pythonnet version: 2.5.1
- Python version: 3.6.5
- Operating System: Windows 10
- .NET Runtime: 4.8.4250.0
Details
- When I try to invoke a .NET event that takes a
ref
parameter, the python process crashes. I provided the code to reproduce the issue below.
Note: I cannot change the code to not useref
as theref
delegate is coming from a 3rd party library. I can wrap around it with a lightweight C# piece of code but would rather avoid it if possible.
Note: This may be related to the following issue:#965
Windows Event Viewer Error 1: Source - .NET Runtime
Application: python.exeFramework Version: v4.0.30319Description: The process was terminated due to an internal error in the .NET Runtime at IP 00007FF81CEA3D2E (00007FF81CEA0000) with exit code 80131506.
Windows Event Viewer Error 2: Source - Application Error
Faulting application name: python.exe, version: 3.6.5150.1013, time stamp: 0x5abbcb08Faulting module name: clr.dll, version: 4.8.4250.0, time stamp: 0x5f2a059cException code: 0xc0000005Fault offset: 0x0000000000003d2eFaulting process id: 0x4348Faulting application start time: 0x01d6eaa4a034a863Faulting application path: C:\Users\noam.bonnie\dev\hp-bluetooth-service\.tox\py36\Scripts\python.exeFaulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dllReport Id: c2031029-3b2f-4e61-aa84-5e5502e904d2Faulting package full name: Faulting package-relative application ID:
The C# class withref
parameter for the delegate. Removing theref
resolves the problem
usingSystem;namespaceTestEvent{publicdelegatevoidMyEvent(refstringdata);publicclassMyTest{publiceventMyEventmyEvent;publicvirtualvoidtriggerEvent(){Console.WriteLine("Invoking Event!");stringmyStr="This is the event data";myEvent?.Invoke(refmyStr);}}}
Python program to invoke the event. Crashes.
importclrimportosimportsysdefhandleEventData(data):print("=== event invoked. data: {} ===".format(data))try:# load the library of the C# class above from a 'lib' local directory.# not necessary if the library of the C# dll is in the pathlib_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'lib')sys.path.append(lib_path)clr.AddReference("TestEvent")clr.AddReference("System")# Print the .NET versionimportSystemprint(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription)# Create object, subscribe to event and trigger the eventimportTestEventt=TestEvent.MyTest()t.myEvent+=handleEventDatat.triggerEvent()exceptExceptionase:print(e)
Metadata
Metadata
Assignees
Labels
No labels