none
Peverify error - Unable to resovle token RRS feed

  • Question

  • hi,

    I am writing a very simple example from a book and I am getting an error when I run Peverify.  It says it is unable to verify token.  There are two files in the example. 

     

    The first one - CILCars.il doesn't throw up any errors when I run ilasm // dll CILCars.il

    I verify it using peverify CILCars.dll and all is ok

     

    here is the code :

     

    // Reference mscorlib.dll and
    // System.Windows.Forms.dll.
    .assembly extern mscorlib
    {
    	.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
    	.ver 4:0:0:0
    }
    
    .assembly extern System.Windows.Forms
    {
    	.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
    	.ver 4:0:0:0
    }
    
    // Define the single-file assembly.
    .assembly CILCars
    {
    	.hash algorithm 0X00008004
    	.ver 1:0:0:0
    }
    
    .module CILCars.dll
    
    // Implementation of CILCars.CILCar type.
    .namespace CILCars
    {
    	.class public auto ansi beforefieldinit CILCar
    	extends [mscorlib]System.Object
    	{
    	// The field data of the CILCar.
    	.field public string petName
    	.field public int32 currSpeed
    	
    	// The custom constructor simply allows the caller
    	// to assign the field data.
    	.method public hidebysig specialname rtspecialname
    	instance void .ctor(int32 c, string p) cil managed
    	{
    	.maxstack 8
    	
    	// Load first arg onto the stack and call base class ctor.
    	ldarg.0  // "this" object, not the int32!
    	call instance void [mscorlib]System.Object::.ctor()
    	
    	// Now load first and second args onto the stack.
    	ldarg.0 // "this" object
    	ldarg.1 // int32 arg
    	
    	// Store topmost stack (int 32) member in currSpeed field.
    	stfld int32 CILCars.CILCar::currSpeed
    	
    	// Load string arg and store in petName field.
    	ldarg.0  // "this" object
    	ldarg.2 // string arg
    	stfld string CILCars.CILCar::petName
    	ret
    	}
       }
    }	
    	
    .class public auto ansi beforefieldinit CILCarInfo
    	extends [mscorlib]System.Object
    	{
    	.method public hidebysig static void
    	Display(class CILCars.CILCar c) cil managed
    		{
    		.maxstack 8
    		
    		// We need a local string variable.
    		.locals init ([0] string caption)
    		
    		// Load string and the incoming CILCar onto the stack.
    		ldstr "{0}'s speed is:"
    		ldarg.0
    		
    		// Now place the value of the CILCar's petName on the 
    		// stack and call the static String.Format() method.
    		ldfld string CILCars.CILCar::petName
    		call string [mscorlib]System.String::Format(string, object)
    		stloc.0
    		
    		// Now load the value of the currSpeed field and get its string
    		// representation (note call to ToString().
    		ldarg.0
    		ldflda int32 CILCars.CILCar::currSpeed
    		call instance string [mscorlib]System.Int32::ToString()
    		ldloc.0
    		
    		// Now call the MessageBox.Show() method with loaded values.
    		call valuetype [System.Windows.Forms]
    		System.Windows.Forms.DialogResult
    		[System.Windows.Forms]
    		System.Windows.Forms.MessageBox::Show(string, string)
    		pop
    		ret
    		}
    	}
    
    	
    	

     

     

    The second file CarClient.il throws up an error when I run peverfity.  Here is the code :

    // External assembly refs.
    .assembly extern mscorlib
    {
    	.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
    	.ver 4:0:0:0
    }
    .assembly extern CILCars
    {
    	.ver 1:0:0:0
    }
    
    // Our executable assembly.
    .assembly CarClient
    {
    	.hash algorithm 0x00008004
    	.ver 1:0:0:0
    }
    .module CarClient.exe
    
    // Implementation of Program type.
    .namespace CarClient
    {
    	.class private auto ansi beforefieldinit Program
    	extends [mscorlib]System.Object
    	{
    		.method private hidebysig static void
    		Main(string[] args) cil managed
    		{
    			// Marks the entry point of the *.exe.
    			.entrypoint
    			.maxstack 8
    			
    			// Declare a local CILCar variable and push
    			// values onto the stack for ctor call.
    			.locals init ([0] class
    			[CILCars]CILCars.CILCar myCILCar)
    			ldc.i4 55
    			ldstr "Junior"
    			
    			// Make new CILCar; store and load reference.
    			newobj instance void
    				[CILCars]CILCars.CILCar::.ctor(int32, string)
    				stloc.0
    				ldloc.0
    				
    			// Call Display() and pass in topmost value on stack.
    			call void [CILCars]
    				CILCars.CILCarInfo::Display(
    					class [CILCars]CILCars.CILCar)
    					ret
    		}
    	}
    }
    			

    Any ideas ?

     

     

    Monday, April 29, 2013 12:36 PM

Answers

  • Hi Aindriu,

    >>That didn't work.  When I move the brackets around I get another error

    Error: No entry point declared for executable

    Could not create output file

    I am afraid you modified the wrong file.

    I mean CILCars.dll

    And leave your exe file unchanged.

    The CILCars.dll is indeed an dll, not executable.

    Just in case, you should use the /exe switch for CarClient.il file when you generate the exe file.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aindriu80 Thursday, May 2, 2013 12:28 PM
    Wednesday, May 1, 2013 3:42 PM
    Moderator

All replies

  • Hi Aind,

    Although the file CILCars.dll is successful, this issue is still related to this reference.

    In this assembly, you exclude the class CILCarInfo from the namespace: CILCars. But you use it like it is still in this assembly. When runtime, this type cannot be resolved correctly.

    So the correct is very simple:

    Move the close bracket to the end of the file to include the type in the namespace and it is not necessary to re-generate the CarClient exe file:

    // Reference mscorlib.dll and
    // System.Windows.Forms.dll.
    .assembly extern mscorlib
    {
    	.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
    	.ver 4:0:0:0
    }
    
    .assembly extern System.Windows.Forms
    {
    	.publickeytoken = (B7 7A 5C 56 19 34 E0 89)
    	.ver 4:0:0:0
    }
    
    // Define the single-file assembly.
    .assembly CILCars
    {
    	.hash algorithm 0X00008004
    	.ver 1:0:0:0
    }
    
    .module CILCars.dll
    
    // Implementation of CILCars.CILCar type.
    .namespace CILCars
    {
    	.class public auto ansi beforefieldinit CILCar
    	extends [mscorlib]System.Object
    	{
    	// The field data of the CILCar.
    	.field public string petName
    	.field public int32 currSpeed
    	
    	// The custom constructor simply allows the caller
    	// to assign the field data.
    	.method public hidebysig specialname rtspecialname
    	instance void .ctor(int32 c, string p) cil managed
    	{
    	.maxstack 8
    	
    	// Load first arg onto the stack and call base class ctor.
    	ldarg.0  // "this" object, not the int32!
    	call instance void [mscorlib]System.Object::.ctor()
    	
    	// Now load first and second args onto the stack.
    	ldarg.0 // "this" object
    	ldarg.1 // int32 arg
    	
    	// Store topmost stack (int 32) member in currSpeed field.
    	stfld int32 CILCars.CILCar::currSpeed
    	
    	// Load string arg and store in petName field.
    	ldarg.0  // "this" object
    	ldarg.2 // string arg
    	stfld string CILCars.CILCar::petName
    	ret
    	}
       }
    // }	move this bracket to the end of the file
    	
    .class public auto ansi beforefieldinit CILCarInfo
    	extends [mscorlib]System.Object
    	{
    	.method public hidebysig static void
    	Display(class CILCars.CILCar c) cil managed
    		{
    		.maxstack 8
    		
    		// We need a local string variable.
    		.locals init ([0] string caption)
    		
    		// Load string and the incoming CILCar onto the stack.
    		ldstr "{0}'s speed is:"
    		ldarg.0
    		
    		// Now place the value of the CILCar's petName on the 
    		// stack and call the static String.Format() method.
    		ldfld string CILCars.CILCar::petName
    		call string [mscorlib]System.String::Format(string, object)
    		stloc.0
    		
    		// Now load the value of the currSpeed field and get its string
    		// representation (note call to ToString().
    		ldarg.0
    		ldflda int32 CILCars.CILCar::currSpeed
    		call instance string [mscorlib]System.Int32::ToString()
    		ldloc.0
    		
    		// Now call the MessageBox.Show() method with loaded values.
    		call valuetype [System.Windows.Forms]
    		System.Windows.Forms.DialogResult
    		[System.Windows.Forms]
    		System.Windows.Forms.MessageBox::Show(string, string)
    		pop
    		ret
    		}
    	}
    }  // add it here

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 30, 2013 10:13 AM
    Moderator
  • That didn't work.  When I move the brackets around I get another error

    Error: No entry point declared for executable

    Could not create output file

    Tuesday, April 30, 2013 11:05 AM
  • Hi Aindriu,

    >>That didn't work.  When I move the brackets around I get another error

    Error: No entry point declared for executable

    Could not create output file

    I am afraid you modified the wrong file.

    I mean CILCars.dll

    And leave your exe file unchanged.

    The CILCars.dll is indeed an dll, not executable.

    Just in case, you should use the /exe switch for CarClient.il file when you generate the exe file.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aindriu80 Thursday, May 2, 2013 12:28 PM
    Wednesday, May 1, 2013 3:42 PM
    Moderator
  • I got it to work.  I think I got mixed up with the file extension .il and .dll when using peverify.

    Thanks very much for your help !!!

    Thursday, May 2, 2013 12:28 PM