Extending vector bundles on a given open subscheme, reprise In this question, Ariyan asks about the question of uniqueness of extensions of vector bundles when they exist.
Sasha's answer suggests that extensions of vector bundles don't always exist.
More precisely, if $F$ is a vector bundle on an open subscheme $U$, there does not always exist a vector bundle $F'$ on the ambient space $X$ such that $F'|_U \cong F$.
Can anyone give me a simple example of such an $F$?
I am mainly interested in the case when $X$ is a variety (over $\mathbb{C}$), and $U$ is an open subvariety. Probably I want $X$ to be smooth.
 A: Generalizing @Sasha's example.

Let $X$ be a regular projective scheme over a noetherian ring $A$, and let $Z$ be a closed subscheme of $X$ of codimension $\ge 3$.
  The ideal sheaf $I_Z$ is generated by sections after tensoring by $O_X(l)$ for some $l \gg 0$, it follows that we have an exact sequence
  $$
0 \to E \to O_X(l)^m \to O_X \to O_Z \to 0
$$
   for some $m$ large.
  If $U \subset X - Z$ is any open subset whose complement is of codimension $\ge 2$, then $E|U$ is locally free but does not extend to the whole of $X$, or to any open set containing an associated point of $Z$.



*

*For any $x\in X$, the ring $O_{X,x}$ is regular and thus the module $E_x$ is of finite projective dimension. 
For module with finite projective dimension, being a second syzygy is equivalent to being reflexive. 
It follows that $E_x$ is reflexive for all $x\in X$ and thus $E$ is reflexive. 
Clearly $E$ is locally free on $X-Z$.

*Let $z$ be an associated point of $Z$, then we claim $E_z$ is not free at $z$.
The module $O_{Z,z}$ has finite projective dimension pdim $O_{Z,z}$  = depth $O_{X,z}$ - depth $O_{Z,z}$ by the Auslander-Buchsbaum formula. Since $z$ is an associated point of $Z$, we have depth $O_{Z,z} = 0$. Since Z has codimension $\ge 3$, and $O_{X,z}$ is Cohen-Macaulay, we conclude that pdim $O_{Z,z}$ =  depth $O_{X,z}$ = dim $O_{X,z} \ge 3$. It follows that $E_z$ cannot be free, otherwise 
$$
0 \to  E_z \to O(l)^m_z \to O_{X,z} \to O_{Z,z} \to 0
$$ would be a free resolution of $O_{Z,z}$ of length 2.

*On a scheme satisfying (G1) (Gorenstein in codimension one) and Serre's condition (S2), e.g. normal, Cohen-Macaulay, regular, etc., a reflexive sheaf admits a unique extension from an open set whose complement has codimension $\ge 2$ to the whole space. 
A: The simplest example is the following. Take $X = A^3$ with coordinates $(x,y,z)$, and let $E = Ker(O_X \oplus O_X \oplus O_X \stackrel{(x,y,z)}\to O_X)$. Let $U$ be the complement of the point $(0,0,0) \in X$. Then $E_{|U}$ is a vector bundle. On the other hand, $E$ is not a vector bundle, but $E^{**} \cong E$, hence $E$ is the reflexive envelope of $i_*i^*E$, and thus there is no vector bundle on $X$ extending $E_{|U}$.

[Edit by Anton: I just spent some time digesting some pieces of the above answer, so figured I'd include the results for future readers similar to me.]

("$E$ is not a vector bundle") The sequence $O_X\xrightarrow{\pmatrix{z\\ y \\ x}}O_X^3\xrightarrow{\pmatrix{y & -z & 0\\ -x & 0 & z\\ 0 &x&-y}}O_X^3\xrightarrow{\pmatrix{x& y& z}}O_X$ is exact, so $E$ is the cokernel of the first map. Since taking fibers commutes with taking cokernels, we compute that $E$ has 2-dimensional fibers away from the origin, and 3-dimensional fiber at the origin.


("$E^{**}\cong E$") Note that $E$ is $S_2$ (i.e. sections defined away from codimension 2 extend uniquely) since it is the kernel of a map from an $S_2$ sheaf to a torsion-free sheaf (the section of $O_X^3$ extends uniquely, and its image is zero away from codimension 2, so must be zero, so the extended section is in $E$). Note also that the dual of any sheaf is $S_2$ (if $\phi\colon F\to O_X$ is defined on an open set $V$ with codimension 2 complement and $s$ is a section, $\phi(s)$ must be the unique extension of $\phi(s|_V)$ as a section of $O_X$), so $E^{**}$ is $S_2$. The canonical map $E\to E^{**}$ is then a map of $S_2$ sheaves which is an isomorphism away from codimension 2, so it must be an isomorphism.


("and thus there is no vector bundle on $X$ extending $E|_U$") If $F$ is an $S_2$ extension of $E|_U$ (i.e. $i^*F=i^*E$), then there is a map $F\to i_*i^*E\to (i_*i^*E)^{**}=E$ which is an isomorphism over $U$, so is an isomorphism by the argument in the previous paragraph. A vector bundle extension would be a different $S_2$ extension.

A: This is a little perverse, but rather than answering the question, I want to explain what
can go wrong when attempting to construct an example. This is the sort of thing one
never does normally so I think it's kind of interesting.


*

*If $X$ is a smooth curve, then any vector bundle $E$ on an open set $U$ extends.
To see this, we can assume after shrinking $X$, that $E$ is trivial. Then it can be
extended to a trivial bundle (the extension is not unique).

*If $X$ is smooth surface, then any vector bundle $E$ on an open set $U$ extends.
(I think that Olivier Benoist's answer contains a very nice idea, but I don't think the conclusion is OK.) To simplify the argument, assume that $X-U=\{p_1,p_2\ldots \}$ is zero dimensional. We can find finitely sections in a neigbourhood $V$ of $p_i$ which generate $E^*$. This yields an inclusion $E|_V\hookrightarrow \oplus \mathcal{O}_V^n$, and therefore  $j_*E|_V \hookrightarrow\mathcal{O}_X^n$,
where $j:U\hookrightarrow X$ is the inclusion. It follows easily, that $j_*E$ is coherent. Therefore $F=(j_*E)^{**}$ is a reflexive extension of $E$. However, reflexive sheaves have depth 2. Since by Auslander-Buchsbaum-Serre depth+proj.dim=2 in $\mathcal{O}_{p_i}$, we can conclude that $F$ is in fact locally free.

*In view of jvp's answer, we see that 2 does not hold in the analytic category.

*One might seek a topological obstruction involving Chern classes as in David Treumann's comment,
however: Claim: Any Chern class on $U$ extends to $X$, where $X$ is a smooth partial compactification. Proof: With a bit of fiddling one
can see that $c_p(E)$ would lie in 
$W_{2p}H^{2p}(U,\mathbb{Q})=im H^{2p}(X,\mathbb{Q})$ by Deligne, Theorie de Hodge II, III
A: In the analytic category there are line-bundles over $X = \mathbb C^2 - \{ 0\}$ which do not
extend to $\mathbb C^2$. Since $X$ has the homotopy type of the sphere $S^3$, the exponential sequence 
$$
0\to \mathbb Z \to \mathcal O_X \to \mathcal O_X^* \to 1 
$$
implies $H^1(X,\mathcal O_X) = H^1(X, \mathcal O_X^*)$. As $H^1(X,\mathcal O_X)$ is infinite dimensional, there are many non-zero elements in $H^1(X,\mathcal O_X^*)$. These define  line-bundles which do not extend. 
