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

23

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.

c#
.net
winforms
dll
asked on Stack Overflow Nov 11, 2011 by Amir Rezvani • edited Nov 15, 2011 by Amir Rezvani

5 Answers

44

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;  
answered on Stack Overflow Mar 11, 2014 by KirstieBallance • edited May 29, 2015 by KirstieBallance
3

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***/ 
answered on Stack Overflow Sep 25, 2018 by Yoosaf Abdulla
1

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.

answered on Stack Overflow Nov 15, 2011 by Amir Rezvani
0

The stack trace points to an assembly it could not load. If you're using .dll files to build or load anything (data import/export), you may want to start there.

Check to make sure the assembly is the proper version for your application, or that it even exists within the directory.

Also, double check the naming convention in the assembly. The stack trace shows an assembly name or codebase being invalid. Is the language parseable within your application? Is there a typo in the name?

These may be really elementary places to start, so my apologies if you've tried these. I've run into traces like this before, and it my case it usually amounted to a missing .dll or version incompatibility.

answered on Stack Overflow Nov 15, 2011 by Phoenix
0

Ensure that the assembly you are using the xxxxx.yyyy.database assembly from is not targeting an older version of the .NET Framework.

answered on Stack Overflow Nov 15, 2011 by Eben Roux

User contributions licensed under CC BY-SA 3.0