[Python.NET] Re: Binary file passed to .Net object

Victor “LOST” Milovanov <[email protected]> Wed, 27 Jan 2021 17:26:59 -0800
Newsgroups gmane.comp.python.dotnet
Message-ID <[email protected]>
--===============1955097099879969564==
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta ht=
tp-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta name=
=3DGenerator content=3D"Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style></head><body lang=3DEN-US link=3Dblue vlink=3D"#954F72" style=3D=
'word-wrap:break-word'><div class=3DWordSection1><p class=3DMsoNormal>Can y=
ou try this from C# interactive (or plain C#)?</p><p class=3DMsoNormal><o:p=
>&nbsp;</o:p></p><p class=3DMsoNormal>#r &quot;C:\Test_MW\Tools\GuiTest\Exa=
mRecordHelper.dll&quot;</p><p class=3DMsoNormal>using ExamRecordHelper;</p>=
<p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>var record =
=3D new ExamRecordLoader(&quot;C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT&qu=
ot;);</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>Wit=
hout having ExamRecordHelper.dll, it is hard to guess otherwise, but I agre=
e with Manu, this looks like a mistake in the code (different files and/or =
different versions of the DLL being loaded).</p><p class=3DMsoNormal><o:p>&=
nbsp;</o:p></p><p class=3DMsoNormal>Regards,</p><p class=3DMsoNormal>Victor=
</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><div style=3D'mso-element:par=
a-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0=
in 0in'><p class=3DMsoNormal style=3D'border:none;padding:0in'><b>From: </b=
><a href=3D"mailto:[email protected]">AlexM</a><br><b>Sent: </b>Wednesday=
, January 27, 2021 5:16 PM<br><b>To: </b><a href=3D"mailto:pythonnet@python=
.org">A list for users and developers of Python.NET</a><br><b>Subject: </b>=
[Python.NET] Re: Binary file passed to .Net object</p></div><p class=3DMsoN=
ormal><o:p>&nbsp;</o:p></p><div><p class=3DMsoNormal>Manu, thank you very m=
uch for your suggestions...</p><div><p class=3DMsoNormal>So, far I have .dl=
l and these are not the solutions.</p></div><div><p class=3DMsoNormal>Also,=
 the exact same code works in IronPython, b.t.w.....</p></div><div><p class=
=3DMsoNormal><o:p>&nbsp;</o:p></p><div><p class=3DMsoNormal>Well, the error=
 does come from the &quot;ExamRecordLoader&quot;, here is the output:</p></=
div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMs=
oNormal>c:\Test_MW\Tools\GuiTest&gt;python getExamRecord.py<br>Load Exam Re=
cord<br>Could not load Exam Record: &nbsp;Error loading ExamRecord binary f=
ile: C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT Column requires a valid Data=
Type.<br>&nbsp; &nbsp;at ExamRecordHelper.ExamRecordLoader.LoadExamRecord(S=
tring filename)<br>&nbsp; &nbsp;at ExamRecordHelper.ExamRecordLoader..ctor(=
String filename)</p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></=
div><div><p class=3DMsoNormal>And this is the source:</p></div><div><p clas=
s=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>import c=
lr<br>try:<br>&nbsp; &nbsp; ExRHelperAsseblyRef =3D clr.AddReference(&quot;=
C:\\Test_MW\\Tools\\GuiTest\\ExamRecordHelper.dll&quot;)<br>&nbsp; &nbsp; f=
rom ExamRecordHelper import *<br><br>except Exception, e:<br>&nbsp; &nbsp; =
print(&quot;Exception : &quot; + str(e))</p></div><div><p class=3DMsoNormal=
><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal># path to binary file=
:<br>examRecordFile =3D r'C:\\Test_MW\\Tools\\ExamRecords\\Resp4DCT'<br><br=
>try:<br>&nbsp; &nbsp; print &quot;Load Exam Record&quot;<br>&nbsp; &nbsp; =
exrec =3D ExamRecordLoader(examRecordFile) # &lt;&lt;&lt;&lt;&lt;&lt;&lt;&l=
t;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; Exception line <br>&=
nbsp; &nbsp; stepList=3Dexrec.GetStepList()<br>&nbsp; &nbsp; print &quot;st=
epList=3D&quot;+str(stepList)<br>except Exception as e:<br>&nbsp; &nbsp; pr=
int &quot;Could not load Exam Record: &quot;, str(e)</p></div></div><div><p=
 class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3DMsoNormal>Ale=
x.</p></div></div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><div><div><p cl=
ass=3DMsoNormal>On Wed, Jan 27, 2021 at 3:54 PM Emmanuel Rutovic &lt;manu@a=
esim.tech&gt; wrote:</p></div><blockquote style=3D'border:none;border-left:=
solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-righ=
t:0in'><div><div><div><div><div><div><div><p class=3DMsoNormal>Hi Alex,</p>=
</div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=3D=
MsoNormal>It seems that the&nbsp;exception is thrown inside your method &qu=
ot;ExamRecordLoader&quot; so it is hard to debug.&nbsp;</p></div><div><p cl=
ass=3DMsoNormal>Is it possible that the error is thrown because of differen=
t working directories? Can you try to use the full path to 'MyBinaryFile.bi=
n' ?</p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div><div><p =
class=3DMsoNormal>Also, I always use the file name including the extension =
( clr.AddReference(&quot;C:\ExamRecordHelper<b>.dll</b>&quot;) ) but I doub=
t it will change anything</p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o=
:p></p></div><div><p class=3DMsoNormal>I hope it helps,</p></div><div><p cl=
ass=3DMsoNormal>Manu.&nbsp;</p></div><div><p class=3DMsoNormal><o:p>&nbsp;<=
/o:p></p></div><div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></div></div><=
/div></div></div></div></div><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><div=
><div><p class=3DMsoNormal>On Wed, Jan 27, 2021 at 2:47 PM Alexander Masis =
&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">alexmasis@gmai=
l.com</a>&gt; wrote:</p></div><blockquote style=3D'border:none;border-left:=
solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-righ=
t:0in'><p class=3DMsoNormal>The code in the original post works in IronPyth=
on ( i.e. loaderObj =3D ExamRecordLoader( 'MyBinaryFile.bin') this line has=
 no exceptions in IronPython )<br>_________________________________________=
______<br>PythonNet mailing list -- <a href=3D"mailto:[email protected]"=
 target=3D"_blank">[email protected]</a><br>To unsubscribe send an email=
 to <a href=3D"mailto:[email protected]" target=3D"_blank">pythonn=
[email protected]</a><br><a href=3D"https://mail.python.org/mailman3/list=
s/pythonnet.python.org/" target=3D"_blank">https://mail.python.org/mailman3=
/lists/pythonnet.python.org/</a><br>Member address: [email protected]</p></bl=
ockquote></div></blockquote></div><p class=3DMsoNormal style=3D'margin-left=
:4.8pt'>_______________________________________________<br>PythonNet mailin=
g list -- <a href=3D"mailto:[email protected]" target=3D"_blank">pythonn=
[email protected]</a><br>To unsubscribe send an email to <a href=3D"mailto:pyth=
[email protected]" target=3D"_blank">[email protected]</a><br=
><a href=3D"https://mail.python.org/mailman3/lists/pythonnet.python.org/" t=
arget=3D"_blank">https://mail.python.org/mailman3/lists/pythonnet.python.or=
g/</a><br>Member address: <a href=3D"mailto:[email protected]" target=3D"=
_blank">[email protected]</a></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></=
p></div></body></html>=

--===============1955097099879969564==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]

--===============1955097099879969564==--