How to bind to an assembly outside the /bin folder - binding

I have a web-site named CCESD set up in IIS7; my application root folder is D:\Websites\CCESD\CCESD. I also have a folder holding third-party assemblies (not all of which are strong-named) at D:\Websites\CCESD\CCESD\BinCommon: this is because I also have many other web applications under this root site in IIS that will share the DLLs, some of which are unmanaged code and so can't go in the GAC. My web.config file looks like this:
<compilation defaultLanguage="c#" debug="true" targetFramework="4.0">
<assemblies>
...
<add assembly="Telerik.Web.UI, Version=2012.1.288.40, Culture=neutral, PublicKeyToken=121FAE78165BA3D4" />
</assemblies>
</compilation>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="BinCommon" />
</assemblyBinding>
</runtime>
However, when I try to run the web application, I get the following error (after enabling assembly-binding error logging):
Parser Error Message: Could not load file or assembly 'Telerik.Web.UI,
Version=2012.1.288.40, Culture=neutral,
PublicKeyToken=121fae78165ba3d4' or one of its dependencies. The
system cannot find the file specified.
Source File: D:\Websites\CCESD\CCESD\web.config Line: 144
Assembly Load Trace: The following information can be helpful to
determine why the assembly 'Telerik.Web.UI, Version=2012.1.288.40,
Culture=neutral, PublicKeyToken=121fae78165ba3d4' could not be loaded.
Assembly manager loaded from:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = IIS APPPOOL\CCESD
LOG: DisplayName = Telerik.Web.UI, Version=2012.1.288.40, Culture=neutral,PublicKeyToken=121fae78165ba3d4 (Fully-specified)
LOG: Appbase = file:///D:/Websites/CCESD/CCESD/
LOG: Initial PrivatePath = D:\Websites\CCESD\CCESD\bin Calling
assembly : (Unknown). ===
LOG: This bind starts in default load context.
LOG: Using application configuration file:
D:\Websites\CCESD\CCESD\web.configLOG: 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: Telerik.Web.UI, Version=2012.1.288.40,
Culture=neutral, PublicKeyToken=121fae78165ba3d4
LOG: Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary
ASP.NET Files/root/e11e9098/9e133b72/Telerik.Web.UI.DLL.
LOG: Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary
ASP.NET
Files/root/e11e9098/9e133b72/Telerik.Web.UI/Telerik.Web.UI.DLL.
LOG: Attempting download of new URL
file:///D:/Websites/CCESD/CCESD/bin/Telerik.Web.UI.DLL.
LOG: Attempting download of new URL
file:///D:/Websites/CCESD/CCESD/bin/Telerik.Web.UI/Telerik.Web.UI.DLL.
LOG: Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary
ASP.NET Files/root/e11e9098/9e133b72/Telerik.Web.UI.EXE.
LOG: Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary
ASP.NET
Files/root/e11e9098/9e133b72/Telerik.Web.UI/Telerik.Web.UI.EXE.
LOG: Attempting download of new URL
file:///D:/Websites/CCESD/CCESD/bin/Telerik.Web.UI.EXE.
LOG: Attempting download of new URL
file:///D:/Websites/CCESD/CCESD/bin/Telerik.Web.UI/Telerik.Web.UI.EXE.
I have checked that the file exists and the version and public-key information are correct. What am I doing wrong?

I found it eventually; in the end, it was down to this:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
My project began life in Visual Studio 2005; hence the xmlns attribute shown above was present in the containing element of my web.config file. Removing it fixed the problem and now my assemblies are being loaded correctly.
Googling reveals that the xmlns attribute is there to enable intellisense in Visual Studio (which indeed it does): it says nothing about having any effect on loading assemblies, so this is all a little strange (not to mention annoying). Still, now it's working.

Related

.NET 6.0 MVC App returns 404 in IIS on Windows 10

I've just refreshed an app written in .net 2.1 to .net 6.0. I worked through the errors and the site appears to compile cleanly. After I published to the server had many errors. Working through them, and standing up a full IIS install on my own machine, I now have it down to a 404 error.
When running the exe straight from the console it runs without errors.
Z:\ReportGroups>FleetLogix.ReportGroups.exe
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {snip} may be persisted to storage in unencrypted form.
c:\inetpub\wwwroot\ReportGroups>FleetLogix.ReportGroups.exe
Hosting environment: Production
Content root path: c:\inetpub\wwwroot\ReportGroups
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
Application is shutting down...
Web.config is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\FleetLogix.ReportGroups.dll" forwardWindowsAuthToken="false" startupTimeLimit="3600" requestTimeout="23:00:00" stdoutLogEnabled="false" hostingModel="inprocess" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
Looking through Event Viewer, there's nothing of note. System nothing for IIS, IIS-Configuration and IIS-Admin are empty.
Edit 2021-11-22
It took a morning, but I have Request Tracing installed. For those on windows 10, just go to Add Features > IIS > Health > Tracing. Don't believe the server 2012 pages. Below is a screenshot:
The actual xml and xslt were quite verbose.
I have reinstalled the Hosting package as administrator, just in case. The version installed was dotnet-hosting-6.0.0-win.exe. That didn't fix it. IIS was stopped/started at server level as well.
At the moment it looks like the handlerv2 is missing?
If any other logs or config are required please let me know
"At the moment it looks like the handlerv2 is missing?" is incorrect.
The correct interpretation of the FRT log is that ASP.NET Core module (handler configured in your web.config) runs fine, and decides that no routing rule yields a result for the incoming URL http://localhost/ReportGroups. Thus, it returns 404 as designed.
It is your responsibility to review IIS configuration (site/app) as well as your source code on routing to see what should be the right URL to use to access the target pages. And unless you share those parts, discussion on this question cannot move forward.

Castle Windsor issue with NUnit testing - Instance not initialize properly

In MVC application we are using windsor container and NUnit testing.
Following is the windsor registration code:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<HttpContextBase>().LifeStyle.PerWebRequest.UsingFactoryMethod(() => new HttpContextWrapper(HttpContext.Current)));
container.Register(Component.For<IHttpContextBaseWrapper>().ImplementedBy<HttpContextBaseWrapper>().LifestylePerWebRequest());
container.Register(Component.For<IWebUtility>().ImplementedBy<WebUtility>().LifestylePerWebRequest());
container.Register(Component.For<IExceptionReporter>().ImplementedBy<ExceptionReporter>().LifestylePerWebRequest());
container.Register(Component.For<ICacheProvider>().ImplementedBy<WebCacheProvider>().LifestylePerWebRequest());
container.Register(Component.For<IEmailNotifier>().ImplementedBy<EmailNotifier>().LifestylePerWebRequest());
container.Register(Component.For<IUserStore<ApplicationUser>>().ImplementedBy<ApplicationUserStore<ApplicationUser>>().LifestylePerWebRequest());
container.Register(Component.For<ApplicationUserManager>().ImplementedBy<ApplicationUserManager>().LifestylePerWebRequest());
}
It works fine with normal web request(from browser) but not working wile calling controller methods from NUnit test cases. It gives following error while resolving service instances.
Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule
To fix this add
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
to the <httpModules> section on your web.config.
If you plan running on IIS in Integrated Pipeline mode, you also need to add the module to the <modules> section under <system.webServer>.
Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file.
i tried putting
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
in app.config/web.config. But found same error.

UmbracoAzureBlobStorage - Files lost after some times Using Umbraco 7

I have a project that uses a combination of these tools:
==================================
Azure website
Azure Blob
Azure CDN
UmbracoAzureBlobStorage - 1.0.10.5 - https://github.com/idseefeld/UmbracoAzureBlobStorage
WindowsAzure.Storage - 4.3.0
Umbraco - 7.2.5 assembly: 1.0.5610.18894
idseefeld.de.UmbracoAzure - 1.0.0.0
https://our.umbraco.org/projects/backoffice-extensions/azure-blob-storage-provider/
==================================
config/FileSystemProviders.config
<FileSystemProviders>
<!-- Media -->
<Provider alias="media"
type="idseefeld.de.UmbracoAzure.AzureBlobFileSystem, idseefeld.de.UmbracoAzure">
<Parameters>
<add key="containerName" value="media" />
<add key="rootUrl" value="http://az739977.vo.msecnd.net/" />
<add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXX" />
</Parameters>
</Provider>
</FileSystemProviders>
==================================
The file upload is working as expected at start. But after sometime, and of course few uploads, it looks like our files are deleted from the blob and the CDN cannot serve them anymore.
Is there something I'm missing? I have almost the same configuration in another project and it's working as expected. I tried reinstalling the whole thing but the problem occurs everytimes.
https://our.umbraco.org/projects/backoffice-extensions/azure-blob-storage-provider/ show us configuration that point directly to the blob, not the CDN as I do. Should I take a look at this?
Uninstall-Pacakge UmbracoAzureBlobStorage
Uninstall-Package idseefeld.de.UmbracoAzure
Install-Package UmbracoAzureBlobStorage
Solved the problems. The project referenced the "idseefeld" DLL. It was kinda weird.

Graphics missing when deploying to azure

I just deployed my first MVC5 application to azure, and got everything to work, except that it is not showing graphics. On my development machine this works.
My graphics are in a folder ~/Content/Graphics, and this is the part of the _Layout.cshtml that references one,
<img src="#Url.Content("~/content/graphics/EluciusSoft_Logo.svg")" style="height:50px">
I know that the files are on the server, though, since I checked it with WebMatrix. Why are they not displaying?
EDIT: The browser console error message is the following:
Failed to load resource: the server responded with a status of 404
(Not Found)
Here is a screenshot of the site directory using WebMatrix.
If the webserver hasn't been configured with the MIME type for SVG, then it will return a 404 error when you try and access it. You can define the MIME type in your application's web.config:
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
</system.webServer>
</configuration>

Elmah.MVC working under IIS Express but not IIS 7.5

I'm trying to get Elmah working under ASP.NET MVC and I thought I had.
I used the very convenient Elmah MVC project which automatically setup my web.config file.
Now if I run the project under IIS Express then Elmah works just perfectly.
I can access it with the correct Authorisation and the logs are stored in my SQL Database.
However when I try and run it under IIS 7.5 I get an:
An HTTP 500.19 Internal Server error
Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x800700b7
Config Error Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'ErrorLog'
Config File web.config
Config Source:
111: <modules>
112: <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
113: </modules>
I'm baffled as to why this might be. As a test I've created a brand new clean MVC project and it reacts exactly the same way.
do a
<remove name="ErrorLog"/>
before the
<add />
to get rid of any default defined entries named ErrorLog in the modules section of your web.config file.

Resources