Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error occurred in the Microsoft .NET Framework while trying to load assembly id 65675

I have to work on an existing application, comprises of many projects including a database project. In the statup project, which is a windows app., when making a call to a Adapter.Fill(dataTable);a scary error appears saying that:

An error occurred in the Microsoft .NET Framework while trying to load assembly id 65675. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: 
System.IO.FileLoadException: Could not load file or assembly 'xxxxx.yyyy.database, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
System.IO.FileLoadException: 
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
 (.Net SqlClient Data Provider)



   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at XXX.YY.Data.dsLandholdingsTableAdapters.LandholdingsTableAdapter.Fill(LandholdingsDataTable dataTable, String IV_LRNO, String SearchField, String SearchVal, Nullable`1 SearchType) in E:\Projects\PPP\XXX\YYY\Data\dsLandholdings.Designer.cs:line 5678
   at XXX.YYY.Browse.BrowseLandholdings.btnSearch_Click(Object sender, EventArgs e) in E:\Projects\PPPP\XXXX\YYY\Browse\BrowseLandholdings.cs:line 352

After investigating on the web, I found that it may help to change the "Permission level" on the "Database" tab of my "Database project properties" from "safe" to either "Unsafe" or "External". Dtabase Project Properties

But the error is still coming up after doing mentioned change!

Does anyone possibly have any idea why this is happening?

Any help appreciated in advance.

like image 552
Amir Rezvani Avatar asked Nov 11 '11 02:11

Amir Rezvani


People also ask

How do you check if CLR is enabled or not?

To determine if CLR is enabled, execute the following commands: EXEC SP_CONFIGURE 'show advanced options', '1'; RECONFIGURE WITH OVERRIDE; EXEC SP_CONFIGURE 'clr enabled';

How do I set unsafe Assembly permission?

To change the permission set of an assembly to UNSAFE requires membership in the sysadmin fixed server role. If you are creating assemblies: We recommend that the TRUSTWORTHY Database Property on a database not be set to ON only to run common language runtime (CLR) code in the server process.

What is CLR in SQL Server?

CLR Integration Security NET Framework common language runtime (CLR) manages and secures access between different types of CLR and non-CLR objects running within SQL Server. These objects may be called by a Transact-SQL statement or another CLR object running in the server.


3 Answers

This worked for me

EXEC sp_configure 'show advanced options', '1';
GO
RECONFIGURE;
GO

--Enable CLR (.NET Common Language Runtime)
exec sp_configure 'clr enabled', '1';
GO
RECONFIGURE;
GO
--Enable xp_CmdShell stored procedure to run Command Line programs from within T-SQL
--EXEC sp_configure 'xp_cmdshell', 1
--GO

EXEC sp_configure 'show advanced options', '0';
GO
RECONFIGURE;


 /****this is another one****/
USE master
GO
ALTER DATABASE <DB_NAME>SET TRUSTWORTHY ON

USE <DB_NAME>
GO
EXEC sp_changedbowner 'sa'
/****when error occured relating to m,emory***/ 
like image 44
Yoosaf Abdulla Avatar answered Oct 23 '22 07:10

Yoosaf Abdulla


This did the trick for me:

USE <DATABASE>;
EXEC sp_configure 'clr enabled' ,1
GO

RECONFIGURE
GO
EXEC sp_configure 'clr enabled'   -- make sure it took
GO

USE <DATABASE>
GO

EXEC sp_changedbowner 'sa'
USE <DATABASE>
GO

ALTER DATABASE <DATABASE> SET TRUSTWORTHY ON;  
like image 148
KirstieBallance Avatar answered Oct 23 '22 05:10

KirstieBallance


At long last, I could fix it,

  1. Enable the "CLR Integration" in SQL server.
  2. Deploy the CLR Object ,which in my case was the Database Project,and I set the Permission level to external as well.

Thanks for all comments/answers.

like image 1
Amir Rezvani Avatar answered Oct 23 '22 05:10

Amir Rezvani