Posts Tagged ‘clr’

Watch Your code become intermediary C# before becoming CLR

August 5th, 2018

Go to https://sharplab.io and start typing away in the left screen. The internediary code or IL is presented in the right.

The code you write can be in C#8, F# or VBnet. The output can be the input (try `using` to see how it is just a shorthand for `try…catch`).

The output is C#, F# and Vbnet; but you can also choose IL, JITAsm, the syntax tree and some more.

Use it to get a better understanding of what is produced by your code.

It is all open source https://github.com/ashmind/SharpLabhttps://github.com/ashmind/SharpLab.

CREATE ASSEMBLY failed because method ‘…’ on type ‘…’ in safe assembly ‘…’ is storing to a static field. Storing to a static field is not allowed in safe assemblies.

August 18th, 2010

When working with CLR inside the SQLserver database one doesn’t have to deploy the DLL through Visual Studio.  Instead use the Create Assembly command.

There are several reasons for this command to fail and

CREATE ASSEMBLY failed because method 'AAA' on type 'BBB' in safe assembly 'CCC' is storing to a static field.
Storing to a static field is not allowed in safe assemblies.

is one of them.

Unless your assembly is very complex the diagnosis is easy.  The AAA is a static something.  If it is a property

public static Colour{ get; set; }

AAA will be

set_Colour

CCC is the assembly that refuses to install.

Find AAA.  Rewrite to be not static.  Compile.  Run create assembly again.