# $cast failed when casting sequence item

**URL:** <https://verificationacademy.com/forums/t/cast-failed-when-casting-sequence-item/48677>\
**Category:** SystemVerilog\
**Tags:** cast\
**Created:** [October 9, 2024, 10:51am UTC](https://verificationacademy.com/forums/t/cast-failed-when-casting-sequence-item/48677 "2024-10-09T10:51:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jela](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@jela](https://verificationacademy.com/forums/u/jela)\
**Post date:** [October 9, 2024, 10:51am UTC](https://verificationacademy.com/forums/t/cast-failed-when-casting-sequence-item/48677/1 "2024-10-09T10:51:40Z")

</div>

casting failed in the below code. It was working and then started failing the casting(no change in this sequence) . what could be the issue to make the casting failed in this code?

sequencer also having same transaction type.

```auto
import xyz:: *; 

class simple_seq extends simple_base_seq;  

 `uvm_object_utils(simple_seq) 
 `uvm_declare_p_sequencer(seqr1); 

 xyz::simple_txn txn1; 

 function new(string name = "simple_seq"); 
  super.new(name); 
endfunction : new 

 virtual task body(); 

If(!$cast (txn1, uvm_factory::get().create_object_by_name(xyz::simple_txn, simple_txn_inst1))) begin 
 `uvm_fatal(get_full_name(), unable to cast ") 
end 

//assigning values to transaction item in txn1
 .... 
 … 

endtask  
endclass

```

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [October 10, 2024, 1:06pm UTC](https://verificationacademy.com/forums/t/cast-failed-when-casting-sequence-item/48677/2 "2024-10-10T13:06:24Z")

</div>

The function create\_object\_by\_name() has the following definition:

```auto
function uvm_object create_object_by_name (
  string requested_type_name, 	   	
  string parent_inst_path = "",
  string name = "");

```

The first argument ‘requested\_type\_name’ should be a string. In your code, it appears that you are passing a data type (‘xyz::simple\_txn’). Is the code you posted correct? Or is there a typo? Also, the second argument is also a string, and the argument you pass also seems incorrect, although I don’t see ‘simple\_txn\_inst1’ defined anywhere.
