You may be able to wear pants to a barn wedding, it depends on the formality of the dress code. It is generally best to ask the couple or check in advance.