Unable to load DLL 'sni.dll' or one of its dependencies: Access is denied. (0x80070005 (E_ACCESSDENIED)) - entity-framework-core

I'm trying to use Entity Framework Core 3.1.7 (code first) with SQL Server Express.
add-migration works well but when I try to migrate to the database I
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.
---> System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: Access is denied. (0x80070005 (E_ACCESSDENIED))
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()
at Microsoft.Data.SqlClient.SNILoadHandle..ctor()
at Microsoft.Data.SqlClient.SNILoadHandle..cctor()
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.TdsParserStateObjectFactory.get_EncryptionOptions()
at Microsoft.Data.SqlClient.TdsParser..cctor()
--- End of inner exception stack trace ---
If I look for the file, it is there under ..\bin\Debug\netcoreapp3.1\runtimes\win-x64\native\
btw
Did try installing Microsoft.Data.SqlClient Nuget package but get the same error different

After a day and a half, I figure it out. It was the connection string (I'm using SQL Server Express) I changed 'localhost' for the computer's name and it worked.

Related

System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception

Due to the below error i am blocked on the work.
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlConnectionFactory' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlPerformanceCounters' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.Common.ADP' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.Data.Common.ADP..cctor()
--- End of inner exception stack trace ---
I have dereferenced the System.Data.SqlClient in the entire project but still getting this exception.
I have added the reference for Microsoft.Data.SqlClient i even upgraded this to the latest version.[version="5.0.1" targetFramework="net472"]
I have verifying the connection string by using the VS Community DataBase TestConnection it is working fine.
We are getting this error while trying to establish connection through c# code.
.NetFramework: net472
VSCommunity editor with C# as the scripting language and Windows 11 as the OS.

How could I load MongoDB Client and start a connection inside F# Interactive?

I'm using netcore 3.1, on macOS Catalina 10.15.6, and JetBrains Rider 2020.2 .
I tried starting a MongoDB connection with the following:
#r "../../../.nuget/packages/dnsclient/1.3.1/lib/net471/DnsClient.dll"
#r "../../../.nuget/packages/mongodb.driver.core/2.11.0/lib/net452/MongoDB.Driver.Core.dll"
#r "../../../.nuget/packages/mongodb.bson/2.11.0/lib/net452/MongoDB.Bson.dll"
#r "../../../.nuget/packages/mongodb.driver/2.11.0/lib/net452/MongoDB.Driver.dll"
let connection = MongoDB.Driver.MongoClient "someConnectionString"
however, when executed, there's still a problem loading the DnsClient assembly, as in the error message below:
System.TypeInitializationException: The type initializer for 'MongoDB.Driver.Core.Misc.DnsClientWrapper' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'DnsClient, Version=1.3.1.0, Culture=neutral, PublicKeyToken=4574bb5573c51424'. The system cannot find the file specified.
File name: 'DnsClient, Version=1.3.1.0, Culture=neutral, PublicKeyToken=4574bb5573c51424'
at MongoDB.Driver.Core.Misc.DnsClientWrapper..ctor()
at MongoDB.Driver.Core.Misc.DnsClientWrapper..cctor()
--- End of inner exception stack trace ---
at MongoDB.Driver.Core.Misc.DnsClientWrapper.get_Instance()
at MongoDB.Driver.Core.Configuration.ConnectionString..ctor(String connectionString)
at MongoDB.Driver.MongoUrlBuilder.Parse(String url)
at MongoDB.Driver.MongoUrlBuilder..ctor(String url)
at MongoDB.Driver.MongoUrl..ctor(String url)
at MongoDB.Driver.MongoClientSettings.FromConnectionString(String connectionString)
at MongoDB.Driver.MongoClient..ctor(String connectionString)
at <StartupCode$FSI_0181>.$FSI_0181.main#()
Stopped due to error
How to make the MongoDB.Driver.Core refer to the right path for DnsClient?
Try restore/install all your drivers(mongoDB.Driver.Core and ones depending on),
I got the same error with the following situation :
I have a DAL class library with dependency packages AspNetCore.Identity.MongoDBCore(2.1.1) and MongoDB.Driver.Core(2.11.0), An API project which lacked the Identity.MongoDBCore(2.1.1) but had the MongoDB.Driver.Core(2.11.0),
The Dependency container thrawed the DNSClient exception,{"The type initializer for 'MongoDB.Driver.Core.Misc.DnsClientWrapper' threw an exception."}

Unable to load DLL (Matlab Runtime ) from IIS 7

Resources:
MATLAB 2014 (MCR 8.4 = Matlab Compiler Runtime). (X64)
VS 2010
IIS7 Windows 2008R
Hello together,
I created a matlab script and already publsihed it as .NET dll (Via .NET Builder). Now I try to used that .dll in my web Service together with the MWArray. The MWArray.dll is important to convert the parameters from c# to matlab datatypes. When I publish the web Service on my IIS i get the following error when i executed the matlab function.
Blockquote System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'mclmcrrt8_4.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at MathWorks.MATLAB.NET.Utility.MWMCR.mclmcrInitialize2(Int32 primaryMode)
at MathWorks.MATLAB.NET.Utility.MWMCR..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Arrays.MWArray..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Arrays.MWNumericArray.get__Inf()
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..cctor()
--- End of inner exception stack trace ---
at MathWorks.MATLAB.NET.Arrays.MWNumericArray..ctor(Int32 scalar)
at WS_Splitoptimizer.Service1.Execute(Int32 Targetvalue, Int32[] Good_chip_per_wafer, Int32[] Wcmp_id, Double Overshoot_threshold) in H:\Eigene Dateien\Visual Studio 2008\Projects\WS_Splitoptimizer\WS_Splitoptimizer\WS_SplitOptimizer.asmx.cs:line 64
--- End of inner exception stack trace ---
The 'mclmcrrt8_4.dll' is the MCR .dll and it exist at the Server. I already give everyone full permisson to that file.
So my problem is that the IIS is not able to located the MCR location. Does anyone have an idea to solve that problem?
I'm out of ideas on things to check. Any ideas welcome!
Thanks in advance!

NUnit.ConsoleRunner.Runner "System.Security.SecurityException: That assembly does not allow partially trusted callers"

nunit-console.exe throws the following error while i tried to execute from Mapped Network Drive
Unhandled Exception: System.TypeInitializationException: The type initializer for 'NUnit.ConsoleRunner.Runner' threw an exception. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.
at NUnit.ConsoleRunner.Runner..cctor()
The action that failed was:
LinkDemand
The assembly or AppDomain that failed was:
nunit-console-runner, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77
The method that caused the failure was:
NUnit.Core.Logger GetLogger(System.Type)
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:///Z:/jenkinsworkspace/workspace/FlashUpload/tools/NUnit/lib/nunit-console-runner.DLL
--- End of inner exception stack trace ---
at NUnit.ConsoleRunner.Runner.Main(String[] args)
at NUnit.ConsoleRunner.Class1.Main(String[] args)**
I tried adding loadFromRemoteSources enabled="true" in nunit-console.exe.config, but that did not solve the problem.
Add this to the nunit-console.config file.
<supportedRuntime version="v4.0"/>
Got this from here:
Get .NET to consider a specific network share to be fully trusted:

Server Error loading HttpModule

I am stumped and need some suggestions in resolving the following error
I am getting in my application that is configured to use
an HttpModule that I have created:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Could not load type 'namespaceResponseModifier.ResponseModifer'.
...
Exception Details: System.Web.HttpException: Could not load
type 'namespaceResponseModifier.ResponseModifer'.
...
Stack Trace:
[HttpException (0x80004005): Could not load type 'namespaceResponseModifier.ResponseModifer'.]
...
[ConfigurationErrorsException: Could not load type 'namespaceResponseModifier.ResponseModifer'.]
...
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
The web server is IIS Express 7.0.
In the web.config file, the code for the element is:
<system.webServer>
<modules>
<add name="ResponseModifier"
type="namespaceResponseModifier.ResponseModifer" />
</modules>
</system.webServer>
The assembly for the HttpModule resides in
C:\...\HttpModulePreSendRequestContentCS\Bin\ResponseModifier.dll
I have also tried placing the source for the HttpModule in the App_Code directory
but I am still getting Server Error on loading the HttpModule.
In this 2nd scenario, I am getting the following error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Could not load type 'namespaceResponseModifier.ResponseModifer' from assembly 'App_Code'.
...
Exception Details: System.TypeLoadException: Could not load
type 'namespaceResponseModifier.ResponseModifer' from assembly 'App_Code'.
...
Stack Trace:
[TypeLoadException: Could not load type 'namespaceResponseModifier.ResponseModifer' from
assembly 'App_Code'.]
...
[ConfigurationErrorsException: Could not load type 'namespaceResponseModifier.ResponseModifer'
from assembly 'App_Code'.]
...
[HttpException (0x80004005): Could not load type 'namespaceResponseModifier.ResponseModifer'
from assembly 'App_Code'.]
...
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
I have also tried using the Visual Studio Development Web Server instead of the IIS Express Web Server.
I tried this server with both scenarios:
- with the assembly in the bin folder
- with the source in the App_Code folder.
These scenarios respectively produced the following Errors:
Server Error in '/HttpModulePreSendRequestContentCS' Application.
--------------------------------------------------------------------------------
Configuration Error
...
Parser Error Message: Could not load type 'ResponseModifer'.
(C:\...\HttpModulePreSendRequestContentCS\web.config line 8)
...
Source File: C:\...\HttpModulePreSendRequestContentCS\web.config Line: 8
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Server Error in '/HttpModulePreSendRequestContentCS' Application.
--------------------------------------------------------------------------------
Configuration Error
...
Parser Error Message: Could not load type 'ResponseModifer' from assembly 'App_Code'.
(C:\...\HttpModulePreSendRequestContentCS\web.config line 8)
...
Source File: C:\...\HttpModulePreSendRequestContentCS\web.config Line: 8
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Any suggestions as to what I can do to resolve the problem would be greatly appreciated.
Old question, but I believe your module add is incorrect.
<add name="NameOfModule" type="Namespace.NameOfModule, AssemblyName" />
Is the typical way I see it, so not knowing your namespace for this module, it'd look closer to:
<add name="ResponseModifier" type="ActualNameSpaceGoesHere.namespaceResponseModifier.ResponseModifer, ResponseModifier" />