Thanks for providing the reproduction steps. I've had a look around the source and it seems like the problem is happening somewhere between <a href="https://github.com/IronLanguages/main/blob/master/Runtime/Microsoft.Dynamic/Generation/CompilerHelpers.cs#L368">CompilerHelpers.cs</a> and <a href="https://github.com/IronLanguages/main/blob/master/Languages/IronPython/IronPython/Runtime/Binding/PythonBinder.cs#L85">PythonBinder.cs</a> that calls it. <span class="Apple-style-span" style="font-family: 'Segoe UI', 'Microsoft Sans Serif', Arial, Geneva, sans-serif; color: rgb(48, 51, 45); "> If the interface is not visible, it tries to return it's base type which is null. If I just return the interface out of the GetVisibleType method before it hits null, the message is displayed as intended.</span><div>
<span class="Apple-style-span" style="font-family: 'Segoe UI', 'Microsoft Sans Serif', Arial, Geneva, sans-serif; color: rgb(48, 51, 45); "><br></span></div><div><span class="Apple-style-span" style="font-family: 'Segoe UI', 'Microsoft Sans Serif', Arial, Geneva, sans-serif; color: rgb(48, 51, 45); ">It seems logic is needed to special case interfaces and/or handle the PrivateBindings option but I don't know enough to say.</span><div>
<font class="Apple-style-span" color="#30332D" face="'Segoe UI', 'Microsoft Sans Serif', Arial, Geneva, sans-serif"><br></font></div><div><font class="Apple-style-span" color="#30332D" face="'Segoe UI', 'Microsoft Sans Serif', Arial, Geneva, sans-serif">Richard<br>
</font><br><div class="gmail_quote">On Sun, Jan 9, 2011 at 4:42 AM, Leo Carbajal <span dir="ltr"><<a href="mailto:desleo@gmail.com">desleo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Sorry to spam the list, but I did some more tracking on this and figured something out. I downgraded from 2.7b1 to 2.6.2 and my original example worked just fine in. I thought my woes were over, and then I ran into a similar problem in 2.6.2. It appears that IPy cannot cast an object to a different type, specifically an interface in 2.6.2, when the class is internal and you're working with PrivateBinding = true<div>
<br></div><div>I logged it as <a href="http://ironpython.codeplex.com/workitem/29939" target="_blank">http://ironpython.codeplex.com/workitem/29939</a> with the following example:<br><div><br></div><div><div>internal interface IExample</div>
<div>{</div><div> string Message { get; set; }</div><div>}</div><div><br></div><div>internal class Avatar : IExample</div><div>{</div><div> public string Message { get; set;}</div><div><br></div><div> public Avatar()</div>
<div> {</div><div> Message = "I am an avatar.";</div><div> }</div><div><br></div><div> public void Hello(Avatar avatar)</div><div> {</div><div> Console.WriteLine("From Hello: " + Message);</div>
<div> }</div><div><br></div><div> public void Hi(IExample avatar)</div><div> {</div><div> Console.WriteLine("From Hi: " + Message);</div><div> }</div><div>}</div><div><br></div><div>Using the following python code:</div>
<div><div>avatar = Avatar()</div><div>avatar.Hello(avatar)</div><div>avatar.Hi(avatar)</div></div><div><br></div><div>avatar.Hello prints it's message as expected, but avatar.Hi fails with: <span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">System Error: object reference not set to instance of object.</span></div>
<div><div></div><div class="h5">
<div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><br></span></div><div class="gmail_quote">On Sat, Jan 8, 2011 at 6:07 PM, Leo Carbajal <span dir="ltr"><<a href="mailto:desleo@gmail.com" target="_blank">desleo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, here's a clarification.<br><br>Say you have this class:<br><br><div>internal class ZMPReporter : IReporter</div>
<div> {</div><div> public string Setting { get; set; }</div><div><br></div><div> internal void Trixery(string mes, string mes1, string mes2, bool thing)</div>
<div> {</div><div> Flash(mes, mes1, mes2, thing);</div><div> } </div><div><br></div><div> public void Flash(string sender, string message, string recipient, bool isAuthor)</div><div>
{</div><div> ...</div><div> }</div><div> }</div><div><br></div><div>It's a property of another class. In C# I would use it as follows: caller.Reporter.Flash(..parameters..)<br><br></div><div>
If I call it in a normal IPy engine it fails to even recognize the caller variable, which is fine and totally expected (and desired). In the PrivateBinding scenario described I can call<br><br>caller.Reporter.Setting and get the text data perfectly. When I try to call caller.Reporter.Flash(), though, I get the System Error: object reference not set problem. However, I can call caller.Report._ZMPReporter__Trixery() just fine, which in turn calls Flash for me.<br>
<br>I don't mind using the name mangling overly, but I do mind having to make internal proxies for perfectly good, already existing, functions. I can't just make those methods internal because the IReporter interface demands that they be public. If this was the only class that might give me problems I might even look for a way around that, but the entire project uses Interfaces extensively.</div>
<div><div></div><div>
<div><br><div class="gmail_quote">On Sat, Jan 8, 2011 at 5:36 PM, Leo Carbajal <span dir="ltr"><<a href="mailto:desleo@gmail.com" target="_blank">desleo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello all,<div><br></div><div>Almost I thought I could have my cake and eat it too. I have a large client-server project written in C# that I wanted to be able to script with IronPython. The biggest requirement was that I wanted external admins to be able to provide scripts for the server to augment its functions. However, I don't want them to have full access to the server API so I resigned myself to write the project with everything Internal and then build public facing classes for the functionality I wanted to expose. This, I know, to work fine.</div>
<div><br></div><div>however, I still want to be able to use scripts on the server myself, for other things. I ended up using two engines, one with PrivateBinding on and one without. The one with PrivateBinding set to true can see all private and internal members but whenever I try to call a function from IronPython I get an exception of "System Error: Object reference not set to an instance of an object." It's weird because I can call on properties and get their values, but not functions. If I do a dir() on the class, and the member, IronPython can clearly see what they are and that they exist. If it helps, the class i'm trying to access is internal but has all public members (for interfaces).</div>
<div><br></div><div>I guess my question is whether this behavior is intentional or not. Being able to use my API on one engine for actual server work while providing a different one for plugin\event hook writers, would help tremendously.</div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br></div></div>