Am I right in thinking this will only work with offline silverlight apps, not ones running in a web page?

Asked by Chris Rae on 2011-06-02

I'm hitting a MethodAccessException running this on a Silverlight web app, and it occurred to me that perhaps it's not going to work. Am I right? :)

Question information

English Edit question
IRC.NET Edit question
Alexander Regueiro Edit question
Last query:
Last reply:
Alexander Regueiro (alexreg) said : #1

This is curious. I've had reports of others using the library fine from Silverlight. Is it WP7-Silverlight perhaps? Could you provide some more information about the error please?

Chris Rae (clr) said : #2

It's a Silverlight project (not WP7) - File/New Project/C#/Silverlight/Silverlight Application. I made a reference to the Silverlight build of your fine library, then when I run it I get this error:

System.MethodAccessException was unhandled by user code
  Message=Attempt by method 'IrcDotNet.ReflectionUtilities+<GetAttributedMethods>d__0`2<System.__Canon,System.__Canon>.MoveNext()' to access method 'IrcDotNet.IrcClient.ProcessMessageReplyWhoIsServer(IrcMessage)' failed.
       at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags)
       at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method, Boolean throwOnBindFailure)
       at System.Delegate.CreateDelegate(Type type, Object firstArgument, MethodInfo method)
       at IrcDotNet.ReflectionUtilities.<GetAttributedMethods>d__0`2.MoveNext()
       at IrcDotNet.Common.Collections.CollectionsUtilities.ForEach[T](IEnumerable`1 source, Action`1 action)
       at IrcDotNet.IrcClient.InitializeMessageProcessors()
       at IrcDotNet.IrcClient..ctor()
       at Web_Client.MainPage..ctor()
       at Web_Client.App.Application_Startup(Object sender, StartupEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

On the line:

      var client = new IrcClient();

It's entirely possible this is something I've done, but I have gotten the library working okay in a desktop C# app so if it's something bone-headed on my part it's not something that obvious.

Andrew Simpson (weatherwax) said : #3

I'm having the same issue. Normal Silverlight app, compiles and runs fine but dies as soon as I try to instantiate an IrcClient with the same message as above.

Launchpad Janitor (janitor) said : #4

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Alexander Regueiro (alexreg) said : #5


Andrew Simpson (weatherwax) said : #6

So I had a play around with things and I've managed to get it working with Silverlight (at least the basics, I'm still in the process of writing the client). I'm not very familiar with the specifics but it looks like methods have to be flagged as public to be accessible through reflection in Silverlight. In particular the issue seems to be that the message handler methods in IrcClientMessageProcessing.cs are not accessible through reflection because they are marked as protected. I altered all the classes inside that file to be public and also modified the ReflectionUtilities.GetAttributeMethods() method to find methods that are public:

            var messageProcessorsMethods = obj.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public );

As I say, still testing but so far it connects and processes messages and seems to be doing all the right things.

Alexander Regueiro (alexreg) said : #7

Just a quick update on this issue: I'm currently creating a Silverlight testing framework for the library, which will verify or reject this issue. I'll see exactly what's happening soon and report back.

Alexander Regueiro (alexreg) said : #8

Okay, so I've resolved this issue by changing all the access modifiers of methods in the IrcClientMessageProcessing and CtcpClientMessageProcessing files ro 'protected internal'. I've also added Silverlight unit tests to verify that the sl40 version of the library is working in the future.

Thanks for your feedback.

Andrew Simpson (weatherwax) said : #9

I've been working on a Silverlight IRC client for a little while for use in conjunction with a web site I frequent. It's fairly basic at the moment but you can access it at

Some things I've found with IRC.NET for Silverlight so far (other than the above):

* I haven't been able to get it to connect to hostnames (only IP addresses); in theory it seems to connect the socket but the IrcClient does not function and dies with a ping timeout after a few seconds.
* Trying to retrieve/change user modes in a channel does it work. It dies with a message about not being able to access a particular method.
* Whenever you leave a channel, the list of channel users does not seem to clear itself. Thus, when you rejoin that same channel, the user list has everybody listed twice. Leave and rejoin again you get them three times, etc.
* There is no facility to switch between Silverlight policy authentication via a policy server on port 943 vs HTTP authentication on port 80 (ie. SocketClientAccessPolicyProtocol.Http vs SocketClientAccessPolicyProtocol.Tcp). I edited the source code where appropriate to facilitate this.
* Probably some others that I can't immediately think of off the top of my head

Alexander Regueiro (alexreg) said : #10

Thanks for your feedback. Regarding the specific issues:

1. I haven't yet experienced this. It may be something to do with the way Silverlight uses DNS end points. I have reports that it is working, however. Please file a separate bug report.

2. This should be fixed in the latest revision of the 0.4 branch.

3. This could well be a bug, but would appreciate if you could (briefly) file a separate bug report here.

4. Good point. I'll add an option on IrcClient for that and commit shortly.

Feel free to leave any more feedback/bug reports - always appreciated!

Can you help with this problem?

Provide an answer of your own, or ask Chris Rae for more information if necessary.

To post a message you must log in.