Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:32:10+00:00 2026-06-09T19:32:10+00:00

I have the following class that maps some run loop calls from native code

  • 0

I have the following class that maps some run loop calls from native code to C# using Mono (in a mac) and the compiler just doesn’t work, it crashes all the time when trying to compile it. I have removed it to a separate project containing only this class but it’s still broken, so it seems like the issue is with this code specifically.

Has anyone seen anything like this?

using System;
using System.Threading;

namespace Integration.Mac
{

    public class CommonRunLoop
    {

        static IntPtr runLoopReference;

        public static IntPtr CommonRunLoopReference {
            get {
                return runLoopReference;
            }
        }

        static CommonRunLoop() {

            AutoResetEvent lockObj = new AutoResetEvent (true);

            Thread runLoop = new Thread (delegate() {
                runLoopReference = CFRunLoopGetCurrent ();
                lockObj.Set ();
                CFRunLoopRun ();
            });

            runLoop.IsBackground = true;
            runLoop.Name = "Common-Sync-Run-Loop";
            lockObj.WaitOne();
        }

        [DllImport ("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
        extern static IntPtr CFRunLoopGetCurrent ();

        [DllImport ("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
        extern static IntPtr CFRunLoopGetMain ();

        [DllImport ("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
        extern static void CFRunLoopRun ();

    } 
}

The compiler output is as follows:

Building Solution: calling-native-code-mono (Debug)

Building: calling-native-code-mono (Debug) Performing main
compilation…
/Library/Frameworks/Mono.framework/Versions/2.10.9/bin/dmcs /noconfig
“/out:/Users/mauricio/Projects/calling-native-code-mono/bin/Debug/calling-native-code-mono.dll”
“/r:/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/System.dll”
“/r:/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/System.Core.dll”
/nologo /warn:4 /debug:full /optimize- /codepage:utf8 “/define:DEBUG”
/t:library
“/Users/mauricio/Projects/calling-native-code-mono/CommonRunLoop.cs”
“/Users/mauricio/Projects/calling-native-code-mono/AssemblyInfo.cs”

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object at Mono.CSharp.EmitContext.Emit
(OpCode opcode, Mono.CSharp.MethodSpec method) [0x00000] in :0 at Mono.CSharp.New.Emit (Mono.CSharp.EmitContext ec,
IMemoryLocation target) [0x00000] in :0 at
Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression source, Boolean leave_copy, Boolean
prepare_for_load) [0x00000] in :0 at
Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean
is_statement) [0x00000] in :0 at
Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec)
[0x00000] in :0 at
Mono.CSharp.BlockVariableDeclaration.DoEmit (Mono.CSharp.EmitContext
ec) [0x00000] in :0 at Mono.CSharp.Statement.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
:0 at Mono.CSharp.Block.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000]
in :0 at Mono.CSharp.ToplevelBlock.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Constructor.Emit () [0x00000] in :0
at Mono.CSharp.TypeContainer.EmitType () [0x00000] in :0 at Mono.CSharp.ModuleContainer.Emit () [0x00000] in
:0 at Mono.CSharp.AssemblyDefinition.Emit ()
[0x00000] in :0 at Mono.CSharp.Driver.Compile ()
[0x00000] in :0 at Mono.CSharp.Driver.Main
(System.String[] args) [0x00000] in :0 [ERROR]
FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object
reference not set to an instance of an object at
Mono.CSharp.EmitContext.Emit (OpCode opcode, Mono.CSharp.MethodSpec
method) [0x00000] in :0 at Mono.CSharp.New.Emit
(Mono.CSharp.EmitContext ec, IMemoryLocation target) [0x00000] in
:0 at Mono.CSharp.VariableReference.EmitAssign
(Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean
leave_copy, Boolean prepare_for_load) [0x00000] in :0 at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec,
Boolean is_statement) [0x00000] in :0 at
Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec)
[0x00000] in :0 at
Mono.CSharp.BlockVariableDeclaration.DoEmit (Mono.CSharp.EmitContext
ec) [0x00000] in :0 at Mono.CSharp.Statement.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
:0 at Mono.CSharp.Block.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000]
in :0 at Mono.CSharp.ToplevelBlock.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Constructor.Emit () [0x00000] in :0
at Mono.CSharp.TypeContainer.EmitType () [0x00000] in :0 at Mono.CSharp.ModuleContainer.Emit () [0x00000] in
:0 at Mono.CSharp.AssemblyDefinition.Emit ()
[0x00000] in :0 at Mono.CSharp.Driver.Compile ()
[0x00000] in :0 at Mono.CSharp.Driver.Main
(System.String[] args) [0x00000] in :0

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object at Mono.CSharp.EmitContext.Emit
(OpCode opcode, Mono.CSharp.MethodSpec method) [0x00000] in :0 at Mono.CSharp.New.Emit (Mono.CSharp.EmitContext ec,
IMemoryLocation target) [0x00000] in :0 at
Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression source, Boolean leave_copy, Boolean
prepare_for_load) [0x00000] in :0 at
Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean
is_statement) [0x00000] in :0 at
Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec)
[0x00000] in :0 at
Mono.CSharp.BlockVariableDeclaration.DoEmit (Mono.CSharp.EmitContext
ec) [0x00000] in :0 at Mono.CSharp.Statement.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
:0 at Mono.CSharp.Block.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000]
in :0 at Mono.CSharp.ToplevelBlock.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Constructor.Emit () [0x00000] in :0
at Mono.CSharp.TypeContainer.EmitType () [0x00000] in :0 at Mono.CSharp.ModuleContainer.Emit () [0x00000] in
:0 at Mono.CSharp.AssemblyDefinition.Emit ()
[0x00000] in :0 at Mono.CSharp.Driver.Compile ()
[0x00000] in :0 at Mono.CSharp.Driver.Main
(System.String[] args) [0x00000] in :0 [ERROR]
FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object
reference not set to an instance of an object at
Mono.CSharp.EmitContext.Emit (OpCode opcode, Mono.CSharp.MethodSpec
method) [0x00000] in :0 at Mono.CSharp.New.Emit
(Mono.CSharp.EmitContext ec, IMemoryLocation target) [0x00000] in
:0 at Mono.CSharp.VariableReference.EmitAssign
(Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean
leave_copy, Boolean prepare_for_load) [0x00000] in :0 at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec,
Boolean is_statement) [0x00000] in :0 at
Mono.CSharp.Assign.EmitStatement (Mono.CSharp.EmitContext ec)
[0x00000] in :0 at
Mono.CSharp.BlockVariableDeclaration.DoEmit (Mono.CSharp.EmitContext
ec) [0x00000] in :0 at Mono.CSharp.Statement.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
:0 at Mono.CSharp.Block.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000]
in :0 at Mono.CSharp.ToplevelBlock.Emit
(Mono.CSharp.EmitContext ec) [0x00000] in :0 at
Mono.CSharp.Constructor.Emit () [0x00000] in :0
at Mono.CSharp.TypeContainer.EmitType () [0x00000] in :0 at Mono.CSharp.ModuleContainer.Emit () [0x00000] in
:0 at Mono.CSharp.AssemblyDefinition.Emit ()
[0x00000] in :0 at Mono.CSharp.Driver.Compile ()
[0x00000] in :0 at Mono.CSharp.Driver.Main
(System.String[] args) [0x00000] in :0 Build
complete — 1 error, 0 warnings

———————- Done ———————-

Build: 1 error, 0 warnings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:32:11+00:00Added an answer on June 9, 2026 at 7:32 pm

    Adding:

    using System.Runtime.InteropServices;
    

    At the beginning of the file fixed it, DLLImport is at that namespace. Not sure why the compiler didn’t just complain about it instead of crashing.

    A bug report was filled here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code snippet that i use to compile class at the run
Assume that we have the following code: class Program { static volatile bool flag1;
I have a class that looks like the following: public class MyClass { private
I have the following class written by someone else that I'm trying to understand
We have a class a class that looks something like the following: public class
I have the following methods in my Authentication class that is called by my
I have the following ugly if statement that is part of a class that
I have a class that has the following property that is generated by the
So I have a class that has the following member variables. I have get
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.