- Home /
Unity 3.1 Webplayer: access method failed
Hi all,
I'm running a C# script in Unity 3.1.0f4, connecting to a remote server. The web-player build run from a browser generates the following error message -
MethodAccessException: Attempt to access a private/protected method failed.
at System.Security.SecurityManager.ThrowException (System.Exception ex) [0x00000] in <filename unknown>:0 at [Some constructor in my code]
The code looks like this:
Socket.Connect(hostname, port); //works
NetworkStream netStream = Socket.GetStream();//works
BufferedStream bStream = new BufferedStream(netStream);//seems to fail
When I, however, start the same project in the Editor, (with platform switched to web player, of course) it works without problems. It only occurs using the browser-plugin.
Even if I replace the NetworkStream
with a MemoryStream
, it fails when constructing the BufferedStream
:
Socket.Connect(hostname, port); //works
NetworkStream netStream = Socket.GetStream();//works
MemoryStream test = new MemoryStream();//works as well
BufferedStream bStream = new BufferedStream(test);// also fails
As far as I could read from the documentation, both classes MemoryStream
and BufferedStream
are fully supported by the web player. NetworkStream
is accessible as well, just the close(timeout)
method is not - which I'm not using anyway.
Thanks for all hints :)
I'm encountering a similar error
$$anonymous$$ethodAccessException: Attempt to access a private/protected method failed.
at System.Security.Security$$anonymous$$anager.ThrowException (System.Exception ex) [0x00000] in <filename unknown>:0
at System.Xml.Xsl.XslTransform..cctor () [0x00000] in <filename unknown>:0
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Xml.Xsl.XslTransform
at $$anonymous$$ono.Xml.Xsl.XslTemplate.Evaluate ($$anonymous$$ono.Xml.Xsl.XslTransformProcessor p, System.Collections.Hashtable withParams) [0x00000] in <filename unknown>:0
at $$anonymous$$ono.Xml.Xsl.XslTransformProcessor.ApplyTemplates (System.Xml.XPath.XPathNodeIterator nodes, System.Xml.XmlQualifiedName mode, System.Collections.ArrayList withParams) [0x00000] in <filename unknown>:0
at $$anonymous$$ono.Xml.Xsl.XslTransformProcessor.Process (System.Xml.XPath.XPathNavigator root, $$anonymous$$ono.Xml.Xsl.Outputter outputtter, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlResolver resolver) [0x00000] in <filename unknown>:0
at System.Xml.Xsl.XslCompiledTransform.Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output) [0x00000] in <filename unknown>:0
at System.Xml.Xsl.XslCompiledTransform.Transform (IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output) [0x00000] in <filename unknown>:0
at System.Xml.Xsl.XslCompiledTransform.Transform (System.Xml.XmlReader reader, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output) [0x00000] in <filename unknown>:0
It seems to be the same issue with the constructor not being accessible...
Notice the interesting switch in namespace from System.Xml.Xsl to $$anonymous$$ono.Xml.Xsl, then re-switch to System.Xml.Xsl.
It's worth noting that XslTransform is a deprecated class, and is not accessible through the the mono intellisense either. HOWEVER, this error doesn't occur when ran through the editor, just the webplayer...
@martinnstauber: this is not an answer, so use comments. Answers should answer the question.
Had the same issue, see here: http://forum.unity3d.com/threads/190219-Unity3D-WebPlayer-$$anonymous$$ethodAccessException-for-XslTransform
@martinnstauber and @Sephiroth74 any solution?
Answer by coeing · Jun 06, 2011 at 09:48 AM
Hi,
Don't know if you still need help. Today we also had a MethodAccessException in our logs. It only occured on a Windows Vista PC, on all PCs with Windows 7 it just worked fine.
In the end it was a Hashtable deserialization that was made in the web player. It turns out that the Hashtable deserialization constructor
Hashtable(System.Runtime.Serialization.SerializationInfo > info, > System.Runtime.Serialization.StreamingContext > context)
is protected, so it can't be called during deserialization.
Our workaround was to just derive our own class from the Hashtable:
[Serializable]
public class SerializableHashtable : Hashtable
{
public SerializableHashtable()
{
}
public SerializableHashtable(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Strange behaviour, but it works for now.
Your answer
Follow this Question
Related Questions
Web player file access 1 Answer
Webplayer exception when using BufferedStream 0 Answers
Unity 3.0 Webplayer Editor Restrictions vs Webplayer Build Restrictions 0 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Webplayer functionality limitations 2 Answers