Deserializing a stream..... brings to "Permission denied: cannot call non-public or static methods remotely."Hello to everybody,<br>I'll try to explain my problem before showing you the exeption I receive. Initially I had an application that reads data from a DB and elaborates the information. Each layer of the application was on the same machine the application runs. Now I've been asked to separate the Data Access Layer and to put it into a Windows Service that will run on the DataBase platform.<br> <div style="text-align:left"><br></div>And here the troubles start!<br><br>In the main application I init the DBHelper in that way :<br><br> <div style="text-align:left"> <div style="text-align:left"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p>   public void InitNetRemotingClient(string type)<br>        {<br>            // Setup the configuration parameters through a dictionary<br>            try<br>            {<br>                // Create an instance of the remote object<br>                myDBHelper = (DBHelper)Activator.GetObject(<br>                    typeof(DBHelper),<br>                    &quot;tcp://localhost:8080/DBHelperSVC&quot;);<br><br>              //  myDBHelper = new DBHelper(idCup, idSeason, idMatchCode);<br>            }<br>            catch (Exception ex)<br>            {<br>                //TODO: Add Logging<br>                throw (ex);<br>            }<br><br>        }</p></div></div><br></div>Here's the code inside the DBHelper.cs that generates me troubles ....<br><br></div><br> <div style="text-align:left"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p>         public Stream GetFirstFrameForMatch()<br>        {<br>            using (SqlConnection sqlConn = GetSqlConnection(&quot;TRK&quot;))<br>            {<br>                int frameValue = -1;<br><br>                string strStore = &quot;usp_GetFirstFrameByMatch&quot;;<br>                SqlCommand cmd = new SqlCommand(strStore, sqlConn);<br>                cmd.CommandType = CommandType.StoredProcedure;<br>                cmd.Parameters.AddWithValue(&quot;@CupId&quot;, IdCup);<br>                cmd.Parameters.AddWithValue(&quot;@Season&quot;, IdSeason);<br>                cmd.Parameters.AddWithValue(&quot;@MatchCode&quot;, IdMatchCode);<br><br>                MemoryStream ms = new MemoryStream();<br>                try<br>                {<br>                    frameValue = (int)cmd.ExecuteScalar();<br>                    myBinaryFormatter.Serialize(ms, frameValue);<br>                }<br>                catch (Exception ex)<br>                {<br>                    frameValue = -1;<br>                    //TODO : Add a log event<br>                    throw;<br>                }<br>                finally<br>                {<br>                    cmd.Dispose();<br>                }<br><br>                return ms;<br>            }<br>        }</p></div></div></div><br>... when I call if from the ProxyDataAccess (That stays in the main application):<br><br> <div style="text-align:left"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p>  public int GetFirstFrameForMatch()<br>        {<br>            int value = 0;<br>            Stream s = myDBHelper.GetFirstFrameForMatch();<br>            <br>            if (s != null &amp;&amp; s.CanSeek | s.CanRead)<br>            {<br>                s.Seek(0, 0);<br><br>                try<br>                {<br>                    value = (int)myBinaryFormatter.Deserialize(s);    <br>                }<br>                catch(Exception ex)<br>                {<br>                    int i = 0;<br>                }<br>                <br>            }</p></div></div><br>I get an error on value = (int)myBinaryFormatter.Deserialize(s); , the error is &quot;Permission denied: cannot call non-public or static methods remotely.&quot; and here's the exception stack trace :<br><br>System.Runtime.Remoting.RemotingException occurred<br>  Message=&quot;Permission denied: cannot call non-public or static methods remotely.&quot;<br>  Source=&quot;mscorlib&quot;<br>  StackTrace:<br>    Server stack trace: <br>       at System.Runtime.Remoting.Channels.ChannelServices.DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, IMessage&amp; replyMsg)<br>    Exception rethrown at [0]: <br>       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)<br>       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)<br>       at System.IO.MemoryStream.InternalReadInt32()<br>       at System.IO.BinaryReader.ReadInt32()<br>       at System.Runtime.Serialization.Formatters.Binary.BinaryObjectWithMapTyped.Read(__BinaryParser input)<br>       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)<br>       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()<br>       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br>       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br>       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)<br>       at ETSPlus.PO.ProxyDataAccess.GetFirstFrameForMatch() in C:\Projects\ETSPlus\ETSPlus.PO\ProxyDataAccess.cs:line 138<br><br>Any suggestion?<br>Thanks in advance<br><br>Paolo<br><br></div>© 2009 Microsoft Corporation. All rights reserved.Wed, 29 Apr 2009 08:12:12 Zd8fd1cb7-6c6f-4ef4-b690-804c2147ce8bhttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/d8fd1cb7-6c6f-4ef4-b690-804c2147ce8b#d8fd1cb7-6c6f-4ef4-b690-804c2147ce8bhttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/d8fd1cb7-6c6f-4ef4-b690-804c2147ce8b#d8fd1cb7-6c6f-4ef4-b690-804c2147ce8bPaolo Ponzanohttp://social.msdn.microsoft.com/Profile/en-US/?user=Paolo%20PonzanoDeserializing a stream..... brings to "Permission denied: cannot call non-public or static methods remotely."Hello to everybody,<br>I'll try to explain my problem before showing you the exeption I receive. Initially I had an application that reads data from a DB and elaborates the information. Each layer of the application was on the same machine the application runs. Now I've been asked to separate the Data Access Layer and to put it into a Windows Service that will run on the DataBase platform.<br> <div style="text-align:left"><br></div>And here the troubles start!<br><br>In the main application I init the DBHelper in that way :<br><br> <div style="text-align:left"> <div style="text-align:left"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p>   public void InitNetRemotingClient(string type)<br>        {<br>            // Setup the configuration parameters through a dictionary<br>            try<br>            {<br>                // Create an instance of the remote object<br>                myDBHelper = (DBHelper)Activator.GetObject(<br>                    typeof(DBHelper),<br>                    &quot;tcp://localhost:8080/DBHelperSVC&quot;);<br><br>              //  myDBHelper = new DBHelper(idCup, idSeason, idMatchCode);<br>            }<br>            catch (Exception ex)<br>            {<br>                //TODO: Add Logging<br>                throw (ex);<br>            }<br><br>        }</p></div></div><br></div>Here's the code inside the DBHelper.cs that generates me troubles ....<br><br></div><br> <div style="text-align:left"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p>         public Stream GetFirstFrameForMatch()<br>        {<br>            using (SqlConnection sqlConn = GetSqlConnection(&quot;TRK&quot;))<br>            {<br>                int frameValue = -1;<br><br>                string strStore = &quot;usp_GetFirstFrameByMatch&quot;;<br>                SqlCommand cmd = new SqlCommand(strStore, sqlConn);<br>                cmd.CommandType = CommandType.StoredProcedure;<br>                cmd.Parameters.AddWithValue(&quot;@CupId&quot;, IdCup);<br>                cmd.Parameters.AddWithValue(&quot;@Season&quot;, IdSeason);<br>                cmd.Parameters.AddWithValue(&quot;@MatchCode&quot;, IdMatchCode);<br><br>                MemoryStream ms = new MemoryStream();<br>                try<br>                {<br>                    frameValue = (int)cmd.ExecuteScalar();<br>                    myBinaryFormatter.Serialize(ms, frameValue);<br>                }<br>                catch (Exception ex)<br>                {<br>                    frameValue = -1;<br>                    //TODO : Add a log event<br>                    throw;<br>                }<br>                finally<br>                {<br>                    cmd.Dispose();<br>                }<br><br>                return ms;<br>            }<br>        }</p></div></div></div><br>... when I call if from the ProxyDataAccess (That stays in the main application):<br><br> <div style="text-align:left"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Block</span></div> <p>  public int GetFirstFrameForMatch()<br>        {<br>            int value = 0;<br>            Stream s = myDBHelper.GetFirstFrameForMatch();<br>            <br>            if (s != null &amp;&amp; s.CanSeek | s.CanRead)<br>            {<br>                s.Seek(0, 0);<br><br>                try<br>                {<br>                    value = (int)myBinaryFormatter.Deserialize(s);    <br>                }<br>                catch(Exception ex)<br>                {<br>                    int i = 0;<br>                }<br>                <br>            }</p></div></div><br>I get an error on value = (int)myBinaryFormatter.Deserialize(s); , the error is &quot;Permission denied: cannot call non-public or static methods remotely.&quot; and here's the exception stack trace :<br><br>System.Runtime.Remoting.RemotingException occurred<br>  Message=&quot;Permission denied: cannot call non-public or static methods remotely.&quot;<br>  Source=&quot;mscorlib&quot;<br>  StackTrace:<br>    Server stack trace: <br>       at System.Runtime.Remoting.Channels.ChannelServices.DispatchMessage(IServerChannelSinkStack sinkStack, IMessage msg, IMessage&amp; replyMsg)<br>    Exception rethrown at [0]: <br>       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)<br>       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)<br>       at System.IO.MemoryStream.InternalReadInt32()<br>       at System.IO.BinaryReader.ReadInt32()<br>       at System.Runtime.Serialization.Formatters.Binary.BinaryObjectWithMapTyped.Read(__BinaryParser input)<br>       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)<br>       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()<br>       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br>       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)<br>       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)<br>       at ETSPlus.PO.ProxyDataAccess.GetFirstFrameForMatch() in C:\Projects\ETSPlus\ETSPlus.PO\ProxyDataAccess.cs:line 138<br><br>Any suggestion?<br>Thanks in advance<br><br>Paolo<br><br></div>Thu, 17 Jan 2008 09:53:00 Z2008-02-07T01:10:49Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/d8fd1cb7-6c6f-4ef4-b690-804c2147ce8b#75b4894c-c294-423a-9cd1-55cd54d582b8http://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/d8fd1cb7-6c6f-4ef4-b690-804c2147ce8b#75b4894c-c294-423a-9cd1-55cd54d582b8Utkarsh Shahhttp://social.msdn.microsoft.com/Profile/en-US/?user=Utkarsh%20ShahDeserializing a stream..... brings to "Permission denied: cannot call non-public or static methods remotely."<p>Paolo,</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>Is your code using some static or non public member? <font color="#000000">Static methods and fields accessed via a remoting proxy, are actually executed locally on the client side. So even though a type is configured to go remote static accesses/invokations dont go remote. </font><font color="#000000">If you need to access static data on the server side, you need to wrap the static access with instance methods / properties or fields. For non public, you will need to make them public. Please inspect your code and see if this helps.</font></p></blockquote> <p align=left> </p>Fri, 18 Jan 2008 18:31:29 Z2008-02-07T01:10:49Z