locked
Remoting and Serial port. RRS feed

  • Question

  • Hi

      i have a remoting application.i created Server and Client in separate exe.i created remoting object in class librabry and created another class library for my application which is used by client project.but if i create an object of serialport in one class which is to be instantiated in remoting class, i am getting security error.

    i am calling remoting object from client:

    TcpChannel chan = new TcpChannel();
    ChannelServices.RegisterChannel(chan,true);
    obj = (Remoting.
    Remoting)Activator.GetObject(typeof(Remoting.Remoting), "tcp://localhost:8085/Text");

    Helper.Caption Caption =new Helper.Caption();
    Caption.Text = textBox1.Text;
    Caption.TextColor =
    Color.Blue;
    obj.SetCaption(Caption);       //Here  it is giving error



    my remoting class:
    public class Remoting:MarshalByRefObject
    {
    Helper.
    Caption _caption;
    public Remoting()
    {
    _caption =
    new Helper.Caption();
    }
    public void SetCaption(Helper.Caption Cap)
    {
    _caption.Text = Cap.Text;
    _caption.TextColor = Cap.TextColor;

    }

    public Helper.Caption GetCaption()
    {
    return _caption;

    }


    and class to be instantiated in remoting class:
    [Serializable]
    public class Caption
    {
    private string _text;
    private Color _color;
    SerialPort sp;
    public Caption()
    {
    sp =
    new SerialPort();

    }
    public string Text
    {
    get
    {
    return _text;
    }
    set
    {
    _text =
    value;

    }

    }


    if i am trying to instantiate Caption class i am getting an error:

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Runtime.Serialization.SerializationException: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed. ---> System.Security.SecurityException: Request failed.
       at System.Runtime.Serialization.FormatterServices.nativeGetSafeUninitializedObject(RuntimeType type)
       at System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.Permissions.SecurityPermission
    The first permission that failed was:
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="Infrastructure"/>

    The demand was for:
    <PermissionSet class="System.Security.PermissionSet"
    version="1">
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="Infrastructure"/>
    </PermissionSet>

    The only permitted permissions were:
    <PermissionSet class="System.Security.PermissionSet"
    version="1">
    <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Flags="SerializationFormatter"/>
    </PermissionSet>

    The method that caused the failure was:
    System.Runtime.Remoting.Channels.ServerProcessing ProcessMessage(System.Runtime.Remoting.Channels.IServerChannelSinkStack, System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Channels.ITransportHeaders, System.IO.Stream, System.Runtime.Remoting.Messaging.IMessage ByRef, System.Runtime.Remoting.Channels.ITransportHeaders ByRef, System.IO.Stream ByRef)
       --- End of inner exception stack trace ---

    Server stack trace:
       at System.Runtime.Serialization.FormatterServices.GetSafeUninitializedObject(Type type)
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObject(ParseRecord pr)
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel)
       at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Remoting.Remoting.SetCaption(Caption Cap)
       at Client.FormClient.button1_Click(Object sender, EventArgs e) in D:\users\501524718\My Documents\Visual Studio 2005\Projects\ClientServerAplication\Client\FormClient.cs:line 47
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    Client
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///D:/users/501524718/My%20Documents/Visual%20Studio%202005/Projects/ClientServerAplication/Client/bin/Debug/Client.exe
    ----------------------------------------
    System.Windows.Forms
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Drawing
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Runtime.Remoting
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    Remoting
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///D:/users/501524718/My%20Documents/Visual%20Studio%202005/Projects/ClientServerAplication/Client/bin/Debug/Remoting.DLL
    ----------------------------------------
    Helper
        Assembly Version: 1.0.0.0
        Win32 Version: 1.0.0.0
        CodeBase: file:///D:/users/501524718/My%20Documents/Visual%20Studio%202005/Projects/ClientServerAplication/Client/bin/Debug/Helper.DLL
    ----------------------------------------
    System.Configuration
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.832 (QFE.050727-8300)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.








    how can i solve this error?

    if i remove serial port object it is working fine?is there any issue between remoting and serial port in .net frame work?

    regards
    laby
     



     


    regards
    • Moved by jack 321 Thursday, June 19, 2008 8:06 AM off topic
    Tuesday, June 17, 2008 1:14 PM

Answers

All replies