- Notifications
You must be signed in to change notification settings - Fork749
Description
Environment
- Pythonnet version: 3.0.1
- Python version: 3.8
- Operating System: win11
- .NET Runtime: 4.6.1
Details
Describe what you were trying to get done.
my python code listed as following:
importdatetimeimportcsvimportclrclr.AddReference('CyberStone.Atp.Storage')fromCyberStone.Atp.Storage.QueryimportQueryConditionfromCyberStone.Atp.Modules.Analysis.ModelsimportSearchResModelfromSystem.Collections.GenericimportListfromSystemimportString,DateTime#define query conditioncondition=QueryCondition()condition.QueryValueVariables=List[String]()condition.QueryValueVariables.Add('Decoder/projectValue')condition.RowMax=100condition.StartTime=DateTime(2018,8,2)condition.EndTime=DateTime(2018,8,3)#start query databaseresult=dataAnalysis.GetSearchDataSet(condition)print(result.Count)
when I execute PythonEngine.Shutdown(), there is exception. do you know how to resolve it?
System.Runtime.Serialization.SerializationException
HResult=0x8013150C
Message=程序集“CyberStone.Atp.Modules.Analysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中的类型“CyberStone.Atp.Modules.Analysis.Models.SearchResModel”未标记为可序列化。
Source=mscorlib
StackTrace:
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func
2 valueFactory)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at Python.Runtime.RuntimeData.Stash()
at Python.Runtime.Runtime.Shutdown()
at Python.Runtime.PythonEngine.Shutdown()
at CyberStone.Atp.Infrastructure.Python.PythonNetScriptRunner.Run(String scripttext, PythonNetScope userscope) in D:\repo\ATP56\CSharp\Base\CyberStone.Atp.Infrastructure\PythonNet\PythonNetScriptRunner.cs:line 211
at CyberStone.Atp.Modules.TestScript.PythonNet.ViewModels.PythonNetDocument.<>c__DisplayClass25_0.b__0() in D:\repo\ATP56\CSharp\Modules\CyberStone.Atp.Modules.TestScript\PythonNet\ViewModels\PythonNetDocument.cs:line 220
at System.Threading.Tasks.Task.Execute()
PythonEngine.Initialize(); try { using (PythonRuntime.Py.GIL()) { // Capture the output in a StringWriter using (var outputWriter = new StringWriter()) { // Redirect Python's sys.stdout to the custom StringWriter var originalOutput = Console.Out; Console.SetOut(outputWriter); dynamic sys = Py.Import("sys"); dynamic pythonIO = Py.Import("io"); // Redirect Python's sys.stdout to a custom StringIO object dynamic originalStdout = sys.stdout; dynamic captureStream = pythonIO.StringIO(); sys.stdout = captureStream; try { PyObject p = PythonEngine.Compile(_scripttext); _scope.CreatePythonNetScope(); _scope.Scope.Exec(_scripttext); //PythonRuntime.PythonEngine.Exec(_scripttext); } catch (Exception ex) { capturedOutput += $"{ex.Message};"; } finally { // Reset sys.stdout to the original value sys.stdout = originalStdout; } // Get the captured output from the StringIO object capturedOutput += captureStream.getvalue().ToString(); } } } catch(Exception ex) { } finally { PythonEngine.Shutdown(); }
- What commands did you run to trigger this issue? If you can provide a
Minimal, Complete, and Verifiable example
this will help us understand the issue.
print('TODO')
- If there was a crash, please include the traceback here.
print('TODO')