When i enter castle valkihar I get attacked
Solution 1:
It's not entirely clear from your description at which point in Dawnguard's main story you are, however it sounds like you're either banished from the castle or not welcome yet.
In either case, my suggestion would be to try to push on in the main story for a bit. Helping the Volkihar clan should pretty quickly give you the reputation to roam the castle freely.