权限被拒绝:无法远程调用非公共或静态方法 [英] Permission denied: cannot call non-public or static methods remotely
问题描述
好的,我已经在此处找到了针对此特定错误消息的解决方案.但我的情况略有不同.我的代码中没有非公共"或静态"方法.都是公开的.我想要做的是将在一个进程中创建的 FrameworkElement(更具体地说是 Web 浏览器控件)传递给另一个进程以供显示和使用.此外,我没有使用(并且会避免使用)任何框架 3.5 插件.
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.
每次都在下一行失败.
<代码>fe = FrameworkElementAdapters.ContractToViewAdapter(tab.ReturnBrowserObject)
tab.ReturnBrowserObject 返回一个 INativeHandleContract,上面的行应该将其转换为 FrameworkElement.
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
和远程对象
<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
推荐答案
好的,我终于让它工作了.虽然不是我最初的打算.关键是 Win32 API SetParent.浏览器控件是在辅助进程中创建的,并重新指向主进程的窗口.唯一需要解决的问题是尺寸.
Ok so I got it working finally. Though not how I originally was going about it. The key is the Win32 API SetParent. The browser control is created in the secondary process and the re-parented to the primary process's window. The only issue left to solve is sizing.
这篇关于权限被拒绝:无法远程调用非公共或静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!