C# and ILASM

  • Thread starter Thread starter yoz
  • Start date Start date
Y

yoz

Hi,

I am unsure where to post this. I have an MSIL dll.

----

..assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 1:0:5000:0
}

..namespace Test
{
.class public obj1 extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor()
cil managed
{
.maxstack 1
ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}
}
}

---

that I compile with ilasm.exe

When I try to reference it in C# I get

"A reference to 'Test.dll' could not be loaded. This is not a valid assembly
or COM Component. Only assemblies with extension 'dll' and COM Components
can be referenced. Pleae make sure the file is accessible, and that it is a
valid assembly or COM Component".

The line to compile the module is
C:\WINNT\Microsoft.NET\Framework\v1.1.4322\ilasm.exe obj1.msil /dll
/res:obj1.rct /output:Test.dll

the obj1.rct file is join to the mail. If you can't read it just create a
resource file in C# and add the version.

NB:

Another test was to try to load it via the System.Reflection.Assembly

System.Reflection.Assembly a = System.Reflection.Assembly.Load("obj1.dll");

this throws an exception with "File or assembly name
C:\Files\msil\test\obj1.dll, or one of its dependencies, was not found."

Thanks in advance
Yoz
 
Yoz,

Your DLL lacks an assembly manifest (it's just a module), that's why
you can't reference it. Add something like

..assembly MyAsm
{
.ver 1:2:3:4
}

to your code.

Another test was to try to load it via the System.Reflection.Assembly

System.Reflection.Assembly a = System.Reflection.Assembly.Load("obj1.dll");

this throws an exception with "File or assembly name
C:\Files\msil\test\obj1.dll, or one of its dependencies, was not found."

Assembly.Load takes an assembly name, not a file path. To load an
assembly from a file path you use Assembly.LoadFrom.



Mattias
 
Thanks a lot.

Sorry, I am just a begginer :-)


Mattias Sjögren said:
Yoz,

Your DLL lacks an assembly manifest (it's just a module), that's why
you can't reference it. Add something like

.assembly MyAsm
{
.ver 1:2:3:4
}

to your code.



Assembly.Load takes an assembly name, not a file path. To load an
assembly from a file path you use Assembly.LoadFrom.



Mattias
 
Back
Top