How do i mark as assembly as “safe”?
Alternatively, how do i have Visual Studio tell me when something in my assembly is not “safe”?
Sometimes you cannot use an assembly unless it is “safe” (e.g. from SQL Server).
i would like my assembly to be marked as safe. If my assembly cannot be marked as safe because it’s not safe, i’d like to know how i can know that my assembly is not safe.
There are some concepts in Visual Studio that seem to relate to safe-ness, that may or may not have anything to do with an assembly being “safe”:
-
Allow unsafe code assembly option:

- What is allowed if i check the allow unsafe code option?
- What is not allowed if i uncheck the allow unsafe code option?
-
What relation, if any, does “unsafe code” have to do with an assembly being “safe”?
(i ask because my assembly doesn’t “allow unsafe code”, but allows P/Invoke calls – which i thought was the definition of “unsafe”)
-
ClsCompliant assembly option:
[assembly: CLSCompliant(true)] namespace MyApplication- What is the relation, if any, does “cls compliant” code have to do with an assembly being “safe”?
-
unsafe code block:
int error; unsafe { error = 0x80004005; }The code inside the
unsafeblock is “unsafe” -
Microsoft recommends creating a class called
UnsafeNativeMethodsthat contain unsafe managed code:[SuppressUnmanagedCodeSecurity] internal static class UnsafeNativeMethods { ... }This contrasts with
SafeNativeMethods:[SuppressUnmanagedCodeSecurity] internal static class SafeNativeMethods { ... }that contains safe native methods, and
NativeMethods:internal static class SafeNativeMethods { ... }that contain native methods.
How do i mark as assembly as “safe”?
How does SQL know that as assembly is “not safe”?
so its about code execution permission set inside SQL Server code domain
Unsafeflag from VS has nothing to do, basically, with code execution security, but enables non managed code execution. So this about non managed code integration into managed code baseCLS Compilantattribute as defined here is about defining the code of the assembly marked with that attribute like a code that follows CSL (Common Language Specification) guideline. So this about compilation and code architecture.It defined in the first link in this answer and has relation with SQL Server integration.
Considering description provided: “Creates a managed application module that contains class metadata and managed code as an object in an instance of SQL Server”, SQL Server relays on
metadata, that in some fields provides an information about the fact if it is “safe” or not.