Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

.net - Permission denied: cannot call non-public or static methods remotely

Ok I've found a solution to this particular error message on here already. But my case is slightly different. There are no "non-public" or "static" methods in my code. All are public. What I'm trying to do is pass a FrameworkElement (more specifically a web browser control) that was created in one process over to another process for display and use. Also I'm not using (and would to avoid using) any of the framework 3.5 addin stuff.

Fails at the following line everytime.

fe = FrameworkElementAdapters.ContractToViewAdapter(tab.ReturnBrowserObject)

tab.ReturnBrowserObject returns an INativeHandleContract which the above line is suppose to convert to a FrameworkElement.

edit: Code The relevant code from the host process.

 Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        'Try
        Dim h As EventWaitHandle
        g = Guid.NewGuid()
        h = New EventWaitHandle(False, EventResetMode.ManualReset, "Tab" & g.ToString)
        StartTabProcess()
        Dim f As Boolean = h.WaitOne(New TimeSpan(0, 0, 10), False)
        If f = False Then
            p.Kill()
        End If
        CreateIPCChannels()
        Dim inhc As INativeHandleContract = tabClient.ReturnBrowserObject
        fe = FrameworkElementAdapters.ContractToViewAdapter(inhc)
        Me.Grid1.Children.Add(fe)

        'Catch ex As Exception
        '    MsgBox(ex.ToString)

        'End Try
    End Sub 
Private Sub StartTabProcess()
        Dim str As String = String.Format(CultureInfo.InvariantCulture, "/guid:{0} /id:{1}", New Object() {g, Process.GetCurrentProcess.Id})
        p = New Process
        p.StartInfo.CreateNoWindow = True
        p.StartInfo.UseShellExecute = False
        p.StartInfo.Arguments = str
        p.StartInfo.FileName = "BrowserTabHost.exe"
        p.Start()
    End Sub
Private Sub CreateClientIPC()
        Dim serverProv As New BinaryServerFormatterSinkProvider()
        serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
        Dim clientProv As New BinaryClientFormatterSinkProvider()

        Dim properties As System.Collections.IDictionary = New System.Collections.Hashtable()
        properties("name") = "Client"
        properties("portName") = g.ToString
        properties("typeFilterLevel") = "Full"
        properties("exclusiveAddressUse") = "False"
        ' Create the channel. 
        Dim serverChannel As New IpcChannel(properties, clientProv, serverProv)
        ChannelServices.RegisterChannel(serverChannel, False)

        tabClient = DirectCast(Activator.GetObject(GetType(BrowserObject), "ipc://" & g.ToString & "/TabClient"), BrowserObject)
    End Sub

And the remoting object

<Serializable()> _
Public Class BrowserObject
    Inherits MarshalByRefObject
    Public ihc As INativeHandleContract
    Public ad As Dispatcher
    Public handle As IntPtr
    Public Delegate Sub ManipulateWB()
    Dim newWeb As WebBrowser
    Public Delegate Function CreateAndReturnWebInstance()
    Public Property Browser As Pajocomo.Windows.Forms.WebBrowserControl
    Dim wfh As WindowsFormsHost
    Public Sub New()
        ad = Dispatcher.Current
    End Sub
    Public Function ReturnBrowserObject() As INativeHandleContract
        Try
            ad.DoWork(New CreateAndReturnWebInstance(Function()
                                                         newWeb = New WebBrowser
                                                         'wfh.Child = newWeb
                                                         ihc = FrameworkElementAdapters.ViewToContractAdapter(newWeb)
                                                         Return Nothing
                                                     End Function))

            Return ihc
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function
    Public Sub SetDockSettings()
        'Browser.Dispatcher.BeginInvoke(New ManipulateWB(Sub()
        '                                                    Browser.NavigateToURL("http://neowin.net")
        '                                                End Sub))
    End Sub
    Private Function CreateWebInstance()
        '    Browser = New Controls.WebBrowser
        Return Browser
    End Function
End Class
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Similar question was asked here

.NET remoting exception: Permission denied: cannot call non-public or static methods remotely

Also take a look on this question.

http://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/d8fd1cb7-6c6f-4ef4-b690-804c2147ce8b

Is your code using some static or non public member? 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. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...