在C#Server进程中加载​​应用程序时抛出SEHException

时间:2017-10-17 06:44:54

标签: c# wcf .net-remoting service-model servicemodelex

我有一个.NET客户端,它有几个C#库文件,其中一个c#库文件加载第三方本机库。现在由于某些原因,我们希望将C#库转换为新的C#服务器进程,该进程将依次托管第三方本机库并使用它。 我使用.NET Remoting框架(HttpServerChannel)来实现这一目标。为了能够使用本机库API,我首先需要加载其中的一些内部模块和应用程序。在加载应用程序时,我得到了SEH例外。 注意:这适用于现有的体系结构,我在其中使用C#库来完成此工作而不是C#进程。 调用如下所示(API用于Teigha服务) SystemObjects.DynamicLinker.LoadApp(" GripPoints",true,true)

如果我因为不熟悉.NET REMOTING框架而遗漏了任何内容,请提前致歉。

发布更新后面的代码 - 已引用加载本机库的C#库来创建新的服务器进程。服务器代码如下。引用的C#库是" MyClassInternal"

`using MyClassInternal;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.Remoting;
 using System.Runtime.Remoting.Channels;
 using System.Runtime.Remoting.Channels.Http;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;

namespace DWGServerHost
{
   class DWGServerHostMain
   {
       public static int serverPort = 9876;
       static void Main(string[] args)
       {
           HttpServerChannel http = null;
           if (args.Length > 0 && !int.TryParse(args[0], out serverPort))
           {
               serverPort = 9876;
           }

           http = new HttpServerChannel(serverPort);
           ChannelServices.RegisterChannel(http, false);
           RemotingConfiguration.RegisterWellKnownServiceType(
           typeof(MyClass),
           "MyClassService",
           WellKnownObjectMode.SingleCall);
           Thread.CurrentThread.Join();
       }
   }

}`

在客户端,此服务已启动,然后按以下方式使用 -

                Process proc = new Process();
                proc.StartInfo.FileName = Path.Combine("Path to Exe", "DWGServerHost.exe");
                proc.StartInfo.Arguments = "9876";
                proc.StartInfo.CreateNoWindow = false;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.WorkingDirectory = "Path to Server Location";
                proc.Start();
                //SetErrorMode(0);
                if (proc.HasExited)
                {
                    Console.WriteLine("Could not start server");
                    return -1;
                }

                HttpClientChannel http = null;
                http = new HttpClientChannel();
                ChannelServices.RegisterChannel(http, false);

                assembly = Assembly.LoadFrom("Path to DLL");
                Object obj = Activator.GetObject(typeof(MyClass), "http://localhost:9876/MyClassService");
                MyClass myClass = (MyClass)obj;

" MyClassInternal"反过来,库加载第三方库并创建服务。对于使用第三方库API,必须进行一些初始化,如加载第三方库的内部库和模块。使用的API是 -     SystemObjects.DynamicLinker.LoadApp("GripPoints", true, true)

如果我们直接从C#库客户端加载C#库,上述API工作正常,并且在托管C#库的C#Server进程时它不起作用。

注意:" MyClassInternal"中的课程已经从MarshalByRefObject继承。所以在课堂上没有问题。

1 个答案:

答案 0 :(得分:0)

很抱歉,经过一些更改后,我更新的主机进程未放入所需位置。 我们可以关闭这个问题。

相关问题