Server Error loading HttpModule - web-config

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" />

Related

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 'sni.dll' or one of its dependencies: Access is denied. (0x80070005 (E_ACCESSDENIED))

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.

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:

Using ASP.NET Identity on MVC 5 project but httpcontext User.ProviderName is "AspNetSqlRoleProvider"

I have a MVC 5 project using ASP.NET Identity (Invidual user account). As Database ORM I am using Entity framework 6 and IoC is taken care by Ninject.
Solution structure is following
MVC project
-- has my controllers, views and ninject setup. For Ninject I got Ninject.MVC3 from nuget.
Data project
--- has my DataContext (IdentityDbContext) and my ApplicationUser (IdentityUser). My
Data services and all repositories
Core project
-- has all my entities and interfaces
[Authorize] attribute works fine and I have to login to access tha annotated action, but when I set [Authorize(Roles = "Admin")] I get
Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
I created my on CustomAuthorize attibute which was basically a copy of Authorize and noticed that the
httpcontext in protected virtual bool AuthorizeCore(HttpContextBase httpContext) User.ProviderName is "AspNetSqlRoleProvider".
So I added Rolemanages clear to my web.config. This resulted in
Configuration Error Description: An error occurred during the
processing of a configuration file required to service this request.
Please review the specific error details below and modify your
configuration file appropriately.
Parser Error Message: Default Role Provider could not be found.
Source Error:
Line 53: --> Line 54: Line 55: Line
56: Line 57:
Source File:
...myproject\WebUI\web.config
Line: 55
So whats the deal here? How can I set the Default Role Provider to use ASP.NET Identity?
So right after I posted the question I figured the answer. I had to add
<system.webServer>
<modules>
...
<remove name="RoleManager" />
</modules>
</system.webServer>
That did it. But there still is a question of why?

Could not load file or assembly 'Microsoft.PowerShell.Security' or one of its dependencies. The system cannot find the file specified

I'm running PowerShell from a C# console app. My dev box has PowerShell 3.0 - the target machines will probably have v2.0. My project file has a reference to the assembly:
<Reference Include="System.Management.Automation" />
which seems to be the recommended way. I'm getting a System.IO.FileNotFoundException when I call runspace.Open():
using (var runspace = RunspaceFactory.CreateRunspace(initialSessionState))
{
runspace.AvailabilityChanged += runspace_AvailabilityChanged;
runspace.StateChanged += runspace_StateChanged;
runspace.Open();
...
}
The exception details are:
Message: Could not load file or assembly 'Microsoft.PowerShell.Security' or one of its dependencies. The system cannot find the file specified.
FusionLog:
=== Pre-bind state information ===
LOG: User = MYDOMAIN\MyUser
LOG: DisplayName = Microsoft.PowerShell.Security
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Microsoft.PowerShell.Security | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\MyUser.MYDOMAIN\Projects\PoSh\PoShRunner1\bin\Debug\PoShRunner1.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.DLL.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security.EXE.
LOG: Attempting download of new URL file:///C:/Users/MyUser.MYDOMAIN/Projects/PoSh/PoShRunner1/bin/Debug/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.EXE.
If I turn off Common Language Runtime Exceptions in VS 2012, I get
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.DllNotFoundException' occurred in System.Management.Automation.dll
A first chance exception of type 'System.Management.Automation.Host.HostException' occurred in System.Management.Automation.dll
in the output log.
I've had a look at the document referenced in the fusion log but most of it doesn't seem to apply to this case or help much with my understanding. Microsoft.PowerShell.Security is in the GAC so what's the problem?
The problem is that you compiled against the powershell 3.0 system.management.automation (s.m.a.) assembly - 3.0.0.0 - instead of the powershell 2.0 s.m.a which is 1.0.0.0.
Open your project, browse to the 1.0.0.0 version and recompile. PowerShell 3.0 installs both 1.0.0.0 and 3.0.0.0 s.m.a assemblies to the GAC. Then your program will work on systems with either 2.0 or 3.0 versions of powershell.