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 7619705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:45:16+00:00 2026-05-31T03:45:16+00:00

I want to load this Class library : namespace ClassLibrary1 { public class Class1

  • 0

I want to load this Class library :


namespace ClassLibrary1
{
    public class Class1
    {
        public Class1()
        {
        }
        public static int Sum(int a, int b)
        {
            return a + b;
        }
    }
}

I have a wcf service which returns to me a byte[] array (ClassLibrary1) i can not load this assembly

static void Main(string[] args)
{
    FileTransferService.ApplicationHostServiceClient client = new FileTransferService.ApplicationHostServiceClient();

    FileTransferService.AssemblyPackage[] asmbs = client.GetFile();
    //var newDomain = AppDomain.CreateDomain("FooBar", null, null);
    foreach (FileTransferService.AssemblyPackage item in asmbs) 
    {
        byte[] mybuffer = item.Buffer;
        new AssemblyLoader().LoadAndCall(mybuffer);
    }
}

public class AssemblyLoader : MarshalByRefObject
{
    public void LoadAndCall(byte[] binary)
    {
        Assembly loadedAssembly = AppDomain.CurrentDomain.Load(binary);
        object[] tt = { 3, 6 };
        Type typ = loadedAssembly.GetType("ClassLibrary1.Class1");
        MethodInfo minfo = typ.GetMethod("Sum", BindingFlags.Public);
        int x = (int)minfo.Invoke(null, tt);
        Console.WriteLine(x);
    }
}

Error return to me in this method : Assembly loadedAssembly = AppDomain.CurrentDomain.Load(binary);

ERROR:

BADIMAGEFORMAT EXCEPTION
Could not load file or assembly '4096 bytes loaded from Client2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

EXCEPTION :

Bad IL format

i have googling this kind of error but no exact solution. i want to load my assembly using AppDomain.

  • 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-05-31T03:45:17+00:00Added an answer on May 31, 2026 at 3:45 am

    The first thing to check in this scenario is that the byte[] you received is exactly identical to the original, as there are many ways of making a mess of handing a chunk of binary. Perhaps write the file to disk (File.WriteAllBytes) and your favourite file compare tool, or use something like base-64 or a sha-1 hash to validate the contents. I strongly suspect you’ll find it isn’t the same.

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

Sidebar

Related Questions

So I've got a class like this: public class A { internal A(int i)
I want to create a static ruby class with a library of function. I
I have an ASP.NET website and a referenced class library project. In this class
I have a class from an external library that I want to extend with
I want to load this simple something into my Editor: Write:-repeat,write(hi),nl,fail. So that it
I want to load some helper in a model. How to do this? Tried
I would appreciate any help on this issue. Lets say I want to load
I'm having difficulty doing this seemingly simple task. I want to load XML files
Because I want to do things like load images from the web (see this
I have a C# ClassLibrary that contains a function to sum two numbers: namespace

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.