好的,我已经在这里找到了这个特定错误消息的解决方案。但我的情况略有不同。我的代码中没有“非公共”或“静态”方法。一切都是公开的。我要做的是将在一个进程中创建的FrameworkElement(更具体地说是Web浏览器控件)传递给另一个进程以供显示和使用。此外,我没有使用(并且会避免使用)任何框架3.5插件。
每次都在以下行失败。
fe = FrameworkElementAdapters.ContractToViewAdapter(tab.ReturnBrowserObject)
tab.ReturnBrowserObject返回一个INativeHandleContract,上面一行假设它转换为FrameworkElement。
编辑:代码 来自主机进程的相关代码。
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
答案 0 :(得分:1)
此处提出类似问题
.NET remoting exception: Permission denied: cannot call non-public or static methods remotely
另请查看此问题。
您的代码是使用静态还是非代码 公众会员?静态方法和 通过远程代理访问的字段, 实际上是在本地执行的 客户端。所以即使是一种类型 配置为远程静态 访问/调用不要远程。 如果需要访问静态数据 在服务器端,你需要包装 使用实例方法的静态访问/ 属性或字段。对于非公众, 你需要公开它们。 请检查您的代码,看看是否 这有帮助。
答案 1 :(得分:0)
好的,所以我最终得到了它。虽然不是我最初的想法。关键是Win32 API SetParent。浏览器控件在辅助进程中创建,并重新设置为主进程窗口的父级。剩下要解决的唯一问题是尺寸调整。