简体   繁体   English

使用Mono运行控制台应用程序时出现奇怪的错误?

[英]Weird error when running a console app with mono?

I'm trying to host a WCF service from a console app on my Ubuntu machine using mono, im just using the example code from MDSN to create a sample service, heres my code: 我正在尝试使用Mono在Ubuntu计算机上通过控制台应用程序托管WCF服务,仅使用MDSN中的示例代码创建示例服务,以下是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace ConsoleAppTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8080/hello");
            using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
            {
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                // Open the ServiceHost to start listening for messages. Since
                // no endpoints are explicitly configured, the runtime will create
                // one endpoint per base address for each service contract implemented
                // by the service.
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }

        }
    }

    [ServiceContract]
    public interface IHelloWorldService
    {
        [OperationContract]
        string SayHello(string name);
    }

    public class HelloWorldService : IHelloWorldService
    {
        public string SayHello(string name)
        {
            return string.Format("Hello, {0}", name);
        }
    }

}

When I build it and upload it to my Ubuntu machine, and run it with mono ConsoleAppTest.exe i get the following error: 当我构建它并将其上传到我的Ubuntu计算机上,并使用mono ConsoleAppTest.exe运行它时,出现以下错误:

Unhandled Exception:
System.InvalidProgramException: Invalid IL code in System.ServiceModel.ServiceHost:.ctor (System.Type,System.Uri[]): method body is empty.

  at ConsoleAppTest.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in System.ServiceModel.ServiceHost:.ctor (System.Type,System.Uri[]): method body is empty.

  at ConsoleAppTest.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

What does it mean that the method body is empty? 方法主体为空意味着什么?

We had this issue, then discovered that our reference to System.dll had Copy Local set to True. 我们遇到了这个问题,然后发现对System.dll的引用将“本地复制”设置为True。 We were building our application on Windows, then running it under Mono, so our application was being shipped with the System.dll from Windows which it was unable to load under Mono. 我们正在Windows上构建应用程序,然后在Mono下运行它,因此我们的应用程序随Windows一起附带了System.dll,但无法在Mono下加载。

The fix was to ensure that the reference to System.dll did not have Copy Local turned on, and that System.dll was not included in the build being run on Mono. 解决方法是确保对System.dll的引用未打开“本地复制”,并且确保在Mono上运行的版本中不包含System.dll。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 奇怪的单声道编译错误 - Weird Mono compilation error 在后台运行Mono应用程序时,我能否检测到缺少控制台? - Can I detect a lack of a Console when running a Mono application in the background? 错误:在 Mono 上运行应用程序时出现 SIGSEGV - Error: SIGSEGV when running application on Mono 在Mono中的外部控制台中运行程序 - Running program in external console in Mono 运行我的应用程序时出现奇怪的错误消息 - Weird error message when running my application 使用nunit-console和mono运行硒测试 - Running selenium test with nunit-console and mono 作为Windows服务运行的控制台应用程序会引发错误 - Console App running as a Windows Service throws an error 运行EConnect示例控制台应用程序时出现EntryPointNotFoundException - EntryPointNotFoundException when running EConnect sample console app 运行用于语音识别的控制台应用程序时的RaceOnRCWCleanup - RaceOnRCWCleanup when running console app for speech recognition 编译xamarin android(mono for android)应用时不断收到此错误 - keep getting this error when compiling xamarin android (mono for android) app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM