It is likely that you can. If the search was illegal, the prosecution cannot use the fact of your possession of the item against you in court. A dismissal is likely, unless the prosecution has another way of proving you guilty.