How to add HttpHandler located in GAC to IIS7.5 - iis

I want MyHandler installed in GAC to be applied to all applications hosted on IIS.
I made it work for particular application when I add Managed Handler on global level
<add name="MyHandler" path="*.txt" verb="*" type="MyHandlerAssembly.MyHandler" resourceType="Unspecified" preCondition="integratedMode" />
and .dll to /bin directory of particular apllication. At this point all works as expected excluding that I am not about add this .dll to each apllication.
So I added MyHandlerAssembly to GAC and then I modified type according to gacutil -l MyHandler:
<add name="MyHandler" path="*.txt" verb="*" type="MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a3126c79b7aa959" resourceType="Unspecified" preCondition="integratedMode" />
And I receiving error:
System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
With stacktrace:
[FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +314
System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +95
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +124
System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +47
System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +18
System.Web.Configuration.HandlerFactoryCache..ctor(String type) +27
System.Web.HttpApplication.GetFactory(String type) +95
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +352
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
What I am doing wrong? Thanks.
UPDATE 1.
Also tried to add my assembly to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config but received error:
Could not load file or assembly 'MyHandlerAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a3126c79b7aa959' or one of its dependencies. The system cannot find the file specified.

After adding assembly to GAC for applying changes need to restart IIS. So complete solution is:
Add assembly with module to GAC by executing gacutil.exe -i path_to_project\bin\MyHandlerAssembly.dll
Restart IIS
Add Handler Mapping of type MyHandlerAssembly.MyHandler, MyHandlerAssembly, Version=X.X.X.X, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX(new types from your assembly will be available after IIS restart)

Related

Servicestack NLog 4.0.43 error

I am struggling to find the problem, I have removed all ServiceStack components and added again.
When I check the references in my project it is correct.
I also tried to load the latest version Servicestack.NLog 4.0.43
but when I try to add in my project the error below comes up:
I am using the versions:
Servicestack 4.0.43
Servicestack.Logging.NLog 4.0.42
NLog 3.2.0.0
I can build the application, but it shows the error below:
Could not load file or assembly 'NLog' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Server Error in '/jobmanager' Application. Could not load file or
assembly 'NLog' or one of its dependencies. The located assembly's
manifest definition does not match the assembly reference. (Exception
from HRESULT: 0x80131040) Description: An unhandled exception occurred
during the execution of the current web request. Please review the
stack trace for more information about the error and where it
originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or
assembly 'NLog' or one of its dependencies. The located assembly's
manifest definition does not match the assembly reference. (Exception
from HRESULT: 0x80131040)
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to
determine why the assembly 'NLog' could not be loaded.
WRN: Assembly binding logging is turned OFF. To enable assembly bind
failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There
is some performance penalty associated with assembly bind failure
logging. To turn this feature off, remove the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileLoadException: Could not load file or assembly 'NLog' or one of
its dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)]
[FileLoadException: Could not load file or assembly 'NLog,
Version=3.2.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName
fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly
locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder,
Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks) +210
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr
pPrivHostBinder, Boolean forIntrospection) +242
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection) +17 System.Reflection.Assembly.Load(String
assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +122
[ConfigurationErrorsException: Could not load file or assembly 'NLog,
Version=3.2.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +12496980
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
+499 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +131 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
compConfig) +331
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String
preStartInitListPath, Boolean& isRefAssemblyLoaded) +148
System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost, IConfigMapPathFactory
configMapPathFactory, HostingEnvironmentParameters hostingParameters,
PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): Could not load file or assembly 'NLog,
Version=3.2.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)] System.Web.HttpRuntime.FirstRequestInit(HttpContext
context) +12618692
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
+159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +12458309
This should be fixed with the latest version on MyGet. Since you already have v4.0.43 installed you'll need to clear your NuGet Cache and delete your /packages folder to download the latest version.

How come azure website requires Owin?

I have created a simple WebApi project that doesn't reference MVC and everything and doesn't require Owin or anything that I don't yet understand.
It runs OK on IIS Express, but once I deploy to cloud it says
"Could not load file or assembly 'Microsoft.Owin' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
There is no reference to Owin anywhere.
OK. I added Owin package, but NuGet has only 2.0.2.0 package at the moment, but for some reason it requires 3.0.0.0.
[FileLoadException: Could not load file or assembly 'Microsoft.Owin' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
[FileLoadException: Could not load file or assembly 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +736
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +284
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521
[HttpException (0x80004005): Could not load file or assembly 'Microsoft.Owin, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
I finally fixed that by
Adding Owin package
Explicitly Owin binding to version 2.0.1.0
Removing Owin from Startup.
But that is something I just don't understand. (Started happening after I updated Visual Studio 2013 to Update 4)
OWIN is the standard interface between .NET web servers and web applications used by Microsoft since they went "fully" open-source with the ASP.NET Web Stack. I think that the OWIN Package became mandatory for ASP.NET WEB.API projects since Visual Studio 2013 Update 4.
You can find more info on OWIN here: http://coding.abel.nu/2014/05/whats-this-owin-stuff-about/

Issue after upgrading Sitefinity 6.3 (Windows Azure Webproject) to Sitefinity 7.0

I have a website developed in Sitefinity 6.3 that is deployed on windows Azure (website deployed in Cloud Service). Now I have upgraded the project to sitefinity 7.0 as mentioned on their migration page.
Project upgraded successfully, and I followied the steps to remove & add References, but then I ran the project & it showed me following error:
Assembly 'Telerik.Sitefinity, Version=7.0.5100.0, Culture=neutral, PublicKeyToken=b28c218413bdf563'
uses 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
which has a higher version than referenced assembly
'Microsoft.WindowsAzure.ServiceRuntime, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Then I installed the Azure SDK version 2.2, then following error was displaying:
Could not load file or assembly 'msshrtmi' or one of its
dependencies. An attempt was made to load a program with an incorrect
format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'msshrtmi' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = msshrtmi
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: msshrtmi | Domain ID: 2
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:/user/Projects/TestTime/Code/From Svn/Unpublished/TestTime/
LOG: Initial PrivatePath = C:\user\Projects\TestTime\Code\From Svn\Unpublished\TestTime\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\user\Projects\TestTime\Code\From Svn\Unpublished\TestTime\web.config
LOG: Using host configuration file: C:\Users\Administrator\Documents\IISExpress\config\aspnet.config
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:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/eaa8f4f5/4dd032f8/msshrtmi.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/eaa8f4f5/4dd032f8/msshrtmi/msshrtmi.DLL.
LOG: Attempting download of new URL file:///C:/user/Projects/TestTime/Code/From Svn/Unpublished/TestTime/bin/msshrtmi.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstReques
I tried setting following tag in web.config :
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
</assemblyBinding
I also copied the related dlls in bin folder & added reference to project.
But nothing seemed to work for me, Please let me know where am I going wrong?
Edit: ------------------------
Thanks [DrewG] for sharing important info.
I followed all the steps as DrewG mentioned. Then I got error when I ran the project in Visual Studio for Post Build task, then I removed that task & Changed following setting in web.config:
<bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.2.0.0"/>
to
<bindingRedirect oldVersion="0.0.0.0-2.5.0.0" newVersion="2.2.0.0"/>
Then it run perfectly, Then I removed the References folder, then It also run perfectly.
Now, I could not recognise wht was fixed by DrewG's steps, but after reverting all the steps it's working correct. I would like to know what might be fixed?
Thanks
I had a similar problem caused from running the project locally. It's trying to load the 64 bit version of that dll (msshrtmi.dll).
Azure is wanting the 64 bit version of the .dll but you either need to use the 32bit version when you run locally or you need to setup a site in IIS with a 64bit app pool to be able to test locally.
I came up with a bit of a hack to get this to work on our azure sites but it has been working before and after an upgrade to Sitefinity 7 so maybe it will help you out.
I copied the 64bit and 32bit msshrtmi.dll files to a folder named References in the same directory as the .sln file. Then I wrote a quick .bat file and added it as a Post Build Task for the project that passes my current build profile.
Note: I have a Build profile with the name "Azure" that I use to update some other settings rather than using Thunder. The Azure build profile is basically just a copy of Release, but I like to test Release builds locally too.
Build task looks like this
call $(SolutionDir)References\AZURE.bat $(ConfigurationName) $(SolutionDir)
AZURE.bat file looks like this
If %1 == Azure echo "Copying 64bit version of msshrtmi.dll"
If %1 == Azure copy %2\References\64\msshrtmi.dll %2\YourProject\Bin\msshrtmi.dll
If NOT %1 == Azure echo "Copying 32bit version of msshrtmi.dll"
If NOT %1 == Azure copy %2\References\32\msshrtmi.dll %2\YourProject\Bin\msshrtmi.dll

IIS can't load dependent DLL

I have created a DLL with C++/CLI in order to wrap some unmanaged C++ code (e.g. boost). This work quite fine as long as I
put all dependent DLLs into one folder and
propagate via %PATH% environment that folder to the IIS (requires a restart of the system).
However Microsoft states that it should be enough to put all dependencies within the bin directory under the application path. This ends up with saying the following:
Server Error in '/' Application.
Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
[ConfigurationErrorsException: Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677
[HttpException (0x80004005): Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090988
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
I have looked at suggestion from Microsoft and others and adjusted the web.config accordingly. Neither of them worked out for me.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="/bin;bin/modules;/modules;\modules;bin\modules" />
<dependentAssembly>
<assemblyIdentity name="boost_chrono-vc100-mt-gd-1_52" publicKeyToken="0" culture="neutral" />
<codeBase version="0.0.0.0" href="file:///C:/app/bin/modules/boost_chrono-vc100-mt-gd-1_52.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Is there any possibility to tell the IIS a specific path just for this application, e.g. via web.config. I think on production systems it would not be very wise to make all these libraries via %PATH% systemwide available. At least it would be interesting which DLL could not be found (I know about dependency walker, but due to the fact that all DLLs are in the same directory it does not complain about any missing file).
I wanted to execute function from C++ DLL which resides in subfolder of 'bin', and on IIS i had to add my web application to AppPool with ADMIN rights. After that, it loads without errors, in common AppPool it won't load (execute) properly.

IIS skip assembly binding

I have a problem starting a Web Application of mine, which runs under IIS 8.
The 'yellow screen of death' states this:
Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' could not be loaded.
=== Pre-bind state information ===
LOG: User = IIS APPPOOL\XYZweb
LOG: DisplayName = RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b
(Fully-specified)
LOG: Appbase = file:///C:/Code/Application/XYZ 4-Web/ABC.XYZ.Web/
LOG: Initial PrivatePath = C:\Code\Application\XYZ 4-Web\ABC.XYZ.Web\bin
Calling assembly : ABC.RegularExpressions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=f59eabe05cc67589.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\Application\XYZ 4-Web\ABC.XYZ.Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
Stack Trace:
[FileNotFoundException: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified.]
System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +371
System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +19
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +319
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +203
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1179
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +146
WebActivator.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +114
WebActivator.ActivationManager.RunActivationMethods() +286
WebActivator.ActivationManager.RunPreStartMethods() +38
WebActivator.ActivationManager.Run() +56
[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +12880923
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12880632
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +240
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'RegexAssemblyBuilder, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b40604c47d15475b' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12880068
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12721257
Now, I do have this RegexAssemblyBuilder.exe file in my solution and if I paste it into the bin folder and refresh the page everything works. It is also very likely that there is some issue about the calling assembly which looks for this file, and I have already informed my colleagues about that (I didn't develop it...). In the meantime, to make it work, and for future knowledge, I would like to know if there is the chance to tell IIS not to resolve this binding (which by the way I never use). I can't remove the calling .dll though.
Thank you
You could just set the Build Action to Content and then set Copy To Output Directory to Copy Always to have this assembly added to the bin directly at all tiimes. Otherwise, you could remove the reference to the executable from the project properties, or check to make sure that there is no mention of it in the web.config file. There is no method to prevent IIS from binding to an assembly when it is referenced inside a project. IIS builds up all the referenced assemblies when it does its initial compilation on the first request of the application.

Resources