Microsoft Azure Tech support has confirmed that all version of .Net 4.XX including 4.7.2 is supported in SQL Server Managed Instance CLR.
We're transforming some portion of Business layer with 4.7.2 and latest EF 6.2
Use Entity Framework in CLR Stored procedure
https://patrickdesjardins.com/blog/how-to-use-third-party-dll-reference-in-a-sql-clr-function
Therefore in order to leverage existing investment in well tested code we want to move certain business layer into DB.
However we ran into problems, when publishing.
Creating [System.Dynamic]...
Warning: The Microsoft .NET Framework assembly 'system.dynamic, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.'
You are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
(47,1): SQL72014: .Net SqlClient Data Provider:
Msg 6218, Level 16, State 2, Line 1
CREATE ASSEMBLY for assembly 'System.Dynamic' failed because assembly 'System.Dynamic' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database.
CLR Verifier error messages if any will follow this message [ :
System.Dynamic.ArgBuilder::MarshalToRef][mdToken=0x6000002][offset 0x00000000] Code size is zero. [ : System.Dynamic.ArgBuilder::UnmarshalFromRef][mdToken=0x6000003][offset
P.S. (IMHO, doesn't matter if EF core as well, neverthless we're trying this with EF6.2)
EDIT: Have given UNSAFE permission to all assemblies I'm referring to: Here are all the dependencies:
<ItemGroup>
<Reference Include="Microsoft.CSharp">
<HintPath>..\packages2019\dotnet 4.7.2\Microsoft.CSharp.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
<IsModelAware>True</IsModelAware>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="System.Dynamic">
<HintPath>..\packages2019\dotnet 4.7.2\System.Dynamic.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
<IsModelAware>True</IsModelAware>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="System.Runtime.Serialization">
<HintPath>..\packages2019\dotnet 4.7.2\System.Runtime.Serialization.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
<IsModelAware>True</IsModelAware>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="SMDiagnostics">
<HintPath>..\packages2019\v4.0.30319\SMDiagnostics.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
<IsModelAware>True</IsModelAware>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="System.ServiceModel.Internals">
<HintPath>..\packages2019\v4.0.30319\System.ServiceModel.Internals.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
<IsModelAware>True</IsModelAware>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<SpecificVersion>True</SpecificVersion>
<IsModelAware>True</IsModelAware>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<SqlPermissionSet>UNSAFE</SqlPermissionSet>
<SpecificVersion>True</SpecificVersion>
<IsModelAware>True</IsModelAware>
<GenerateSqlClrDdl>True</GenerateSqlClrDdl>
</Reference>
EDIT 3: Unsafe code in Azure SQL Server MI
EDIT 4:
- The show-stopper is:
System.RunTime.Serialization
,
CREATE ASSEMBLY [System.Runtime.Serialization] AUTHORIZATION [dbo] FROM 0x4D5... WITH PERMISSION_SET = UNSAFE;
which prevents me to create Entity Framework UNSAFE assemblies into DB. Can we get past system.Runtime.Serialization?
GO
CREATE ASSEMBLY [EntityFramework]
AUTHORIZATION [dbo]
FROM 0x4D5A90...
WITH PERMISSION_SET = UNSAFE;
GO
PRINT N'Creating [EntityFramework.SqlServer]...';
GO
CREATE ASSEMBLY [EntityFramework.SqlServer]
AUTHORIZATION [dbo]
FROM 0x4...
WITH PERMISSION_SET = UNSAFE;
Warning: The Microsoft .NET Framework assembly 'system.runtime.serialization, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details. Msg 6218, Level 16, State 2, Line 11 CREATE ASSEMBLY for assembly 'System.Runtime.Serialization' failed because assembly 'System.Runtime.Serialization' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message [ : System.AppContextDefaultValues::PopulateDefaultValues][mdToken=0x6000001] [offset 0x00000000] Code size is zero.