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

  • SEARCH
  • Home
  • 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 8279893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:28:39+00:00 2026-06-08T09:28:39+00:00

I’m trying to embed mono in an application i’m writing, but mono_field_set_value doesn’t behave

  • 0

I’m trying to embed mono in an application i’m writing, but mono_field_set_value doesn’t behave like I think it should. Here is an example:

monotest.c:

#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
#include <stdio.h>

#define TRUE 1

int main(){
        MonoDomain *domain;
        MonoAssembly *assembly;
        MonoImage *image;
        MonoClass *klass;
        MonoObject *object;
        MonoClassField *field;
        MonoMethodDesc *desc;
        MonoMethod *method;
        int val;

        domain = mono_jit_init ("Domain");
        assembly = mono_domain_assembly_open (domain, "T.DLL");;
        image = mono_assembly_get_image(assembly);
        klass = mono_class_from_name(image, "", "T");
        mono_class_init (klass);
        object = mono_object_new (domain, klass);

        val=11;
        field = mono_class_get_field_from_name(klass,"i");
        mono_field_set_value(object,field,&val);
        //mono_field_set_value((MonoObject*)((void*)object-8),field,&val);                                                                                                                                                                                                                                                     

        printf("val = %d\n", val);

        desc = mono_method_desc_new (":Write()",TRUE);
        method = mono_method_desc_search_in_class (desc, klass);
        mono_runtime_invoke(method,object,NULL,NULL);

        return 0;
}

T.cs

public struct T
{

  public int i;
  public void Write()
  {

    System.Console.WriteLine(i);
  }
}

When run, i expect the output:

val = 11
11

but the second number (printed by the mono runtime) is random. What am I doing wrong?

  • 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-08T09:28:41+00:00Added an answer on June 8, 2026 at 9:28 am

    The argument to mono_runtime_invoke() is incorrect, it needs to be the unboxed pointer, since the type T is a struct.
    From the documentation at http://docs.go-mono.com/index.aspx?link=xhtml%3Adeploy%2Fmono-api-methods.html:

    obj is the ‘this’ pointer, it should be NULL for static methods, a
    MonoObject* for object instances and a pointer to the value type for
    value types.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.