6. The function $f(x)=\frac{\sin x+\cos x}{\sin x+\tan x}+$ $\frac{\tan x+\cot x}{\cos x+\tan x}+\frac{\sin x+\cos x}{\cos x+\cot x}+\frac{\tan x+\cot x}{\sin x+\cot x}$ has a minimum value of $(\quad$ when $x \in\left(0, \frac{\pi}{2}\right)$.
(A) 2
(B) 4
(C) 6
(D) 8
6. B.
$$
\begin{array}{l}
f(x)=(\sin x+\cos x)\left(\frac{1}{\sin x+\tan x}+ \\
\left.\quad \frac{1}{\cos x+\cot x}\right)+(\tan x+\cot x) . \\
\left(\frac{1}{\cos x+\tan x}+\frac{1}{\sin x+\cot x}\right) \\
\geqslant(\sin x+\cos x)\left(\frac{4}{\sin x+\tan x+\cos x+\cot x}\right)+ \\
\quad(\tan x+\cot x)\left(\frac{4}{\sin x+\tan x+\cos x+\cot x}\right) \\
=4 .
\end{array}
$$

For the equality to hold, it must be that
$$
\left\{\begin{array}{l}
\sin x+\tan x=\cos x+\cot x, \\
\tan x+\cos x=\cot x+\sin x .
\end{array}\right.
$$
Subtracting (2) from (1) gives $\sin x-\cos x=\cos x-\sin x$, which means $\sin x=\cos x$.
Since $x \in\left(0, \frac{\pi}{2}\right)$, we have $x=\frac{\pi}{4}$.
Therefore, $f(x)_{\text {min}}=f\left(\frac{\pi}{4}\right)=4$.