title: C# calling a MASM Assembly DLL
body: <p>For the sake of learning, I'm trying to call an Assembly function from C#. I'm working in a very sterile project doing everything as simply as I can. Here's my assembly (mostly cut and paste from <a href="http://www.codeproject.com/Articles/42835/Introduction-In-DLLs-Creation-Using-MASM" rel="nofollow">codeproject</a>):</p>
  
  <pre><code>.386
  .model flat, stdcall
  option casemap :none
  
  include \masm32\include\masm32rt.inc
  
  .code
  LibMain proc instance:dword,reason:dword,unused:dword 
       mov     eax,1
       ret
  LibMain     endp
  PrintMess proc
       print "Test"
       exit
  PrintMess endp
  End LibMain
  </code></pre>
  
  <p>Note: The assembly builds just fine. No errors and the only warning is that masm32rt.inc has another <code>.model</code> line that the assembler is ignoring, this warning is fine. I've set up my environment using <a href="http://www.deconflations.com/2011/masm-assembly-in-visual-studio-2010/" rel="nofollow">these instructions</a>.</p>
  
  <p>For C#, a language I'm much more familiar with, I've tried 2 main approaches: Reflection and adding the DLL as a reference. Both give me an error saying that an assembly manifest is expected. Here I'm at a lose.</p>
  
  <p>My C# is simply:</p>
  
  <pre><code>Assembly mylib = Assembly.LoadFile(@"C:\mypath\MyLib.dll");
  </code></pre>
  
  <p>And I get <code>The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)</code> as an error on that line. I don't know anything about assembly manifests. Any direction towards how to create and embed one would be appreciated.</p>