Small Aircraft; Low Wing; 1 Eng; Fixed Gear
Flight Crew Commercial; Flight Crew Instrument
Flight Crew Last 90 Days 23; Flight Crew Total 4749; Flight Crew Type 1257
Airspace Violation All Types; Conflict NMAC
Air Traffic Control Provided Assistance; Flight Crew Took Evasive Action
Human Factors; Procedure; Airspace Structure
I had just departed Manassas (HEF) Runway 34R. Tower had me maintain runway heading; then turned me on course to the west (out to the SFRA FLUKY gate); and switched me to Potomac Departure.  On my ADS-B in; I noted a target 100 feet below me; and simultaneously Potomac Departure called out that traffic and asked if I had it in sight.  I replied; 'No because it is directly under me.'  The low-wing light sport aircraft passes the wing directly under the pilot; so nothing directly under me can be seen.  I started to climb but Departure warned me there was also traffic above me.  It was then that I noticed that I had climbed into the bottom of the 2;500 foot ring of the Class Bravo.  Then Departure informed that traffic was no longer a factor; and I descended back below 2;500 [feet]. I believe Manassas Tower had me continue on runway heading to clear traffic that had just departed Runway 34L.  Perhaps Tower was not aware of the traffic which eventually found itself under me. HEF traffic is very constrained by Class Bravo to the North; the East and directly above; and R6608 directly south; leaving only two narrow paths for arrival and departure--to the west toward the FLUKY gate; or narrowly to the SSE between the Class Bravo and FRZ to the East and R6608 to the West.
Pilot reported enterring Class B airspace during a climb required to resolve an airborne conflict.