Solution (source code)

= Solution

Let $B$ be the given <invariant bilinear form on a Lie algebra>. Choose a <basis> $x_1,\ldots,x_d$ and its $B$-dual <basis> $x^1,\ldots,x^d$, so $B(x_i,x^j)=\delta_i^j$. The <Casimir element> is
$$
\boxed{\Omega_B=\sum_i x_i x^i\in U(\mathfrak g).}
$$
The tensor $\sum_i x_i\otimes x^i$ is the inverse tensor of $B$, so it is independent of the chosen <basis>. Multiplication in the <universal enveloping algebra> therefore makes $\Omega_B$ independent of that choice as well.

For $z\in\mathfrak g$, write $[z,x_i]=\sum_j a_{ji}x_j$. Invariance means $B([z,x],y)+B(x,[z,y])=0$, whence $[z,x^i]=-\sum_j a_{ij}x^j$. Therefore
$$
[z,\Omega_B]=\sum_{i,j}a_{ji}x_jx^i-\sum_{i,j}a_{ij}x_ix^j=0,
$$
by interchanging $i,j$ in the second sum. Since $\mathfrak g$ generates its <universal enveloping algebra>, $\Omega_B$ is central. This argument does not require adding a symmetry assumption to the given <bilinear form>.

For the <sl2 Lie algebra>, take
$$
e=\begin{pmatrix}0&1\\0&0\end{pmatrix},\quad f=\begin{pmatrix}0&0\\1&0\end{pmatrix},\quad h=\begin{pmatrix}1&0\\0&-1\end{pmatrix},\qquad B(X,Y)=\operatorname{tr}(XY).
$$
The cyclic identity for the <trace> gives $B([Z,X],Y)+B(X,[Z,Y])=0$. The form is <nondegenerate>, since $B(e,f)=1$, $B(h,h)=2$, and all the other pairings except $B(f,e)$ are zero. The dual of $(e,f,h)$ is $(f,e,h/2)$, so
$$
\Omega_B=ef+fe+\tfrac12h^2.
$$
By the <classification of finite-dimensional sl2 representations>, an irreducible of <dimension> $n$ has a <highest-weight vector> $v$ with $ev=0$ and $hv=mv$, where $m=n-1$. Since $ef=fe+h$, one obtains
$$
\Omega_Bv=\left(m+\tfrac12m^2\right)v.
$$
Centrality and the <Schur lemma> then give the answer on the entire representation:
$$
\boxed{\Omega_B=\frac{n^2-1}{2}I.}
$$
This <Casimir eigenvalue for sl2> depends on normalization. Choosing the <Killing form> instead, $K=4B$, scales the dual <basis> and the <Casimir element> by $1/4$, giving $(n^2-1)I/8$.