Recent Comments



Rick Strahl
Thursday

re: Back to Basics: String Interpolation in C#

@Luiz - Might be different versions of the compiler and .NET Runtime. Core vs. Classic and different versions of C# compiler are likely to account for the differences.


Luiz
Thursday

re: Back to Basics: String Interpolation in C#

Hi,

Great explanation. I tested the IL dumping using two different tools. LynqPad 5 as you mentioned and the result was exactly like yours. Also, I tested using ILDASM from Microsoft Visual Studio and the result is different.

O LynqPad 5 it says the interpolation is using String.Format, however on ILDASM it says interpolation uses String.Concat.

Questions: Do you know why LynqPad shows different results than ILDASM? Shouldn't we trust more on ILDASM since it is a Microsoft Visual Studio tool?


Rick Strahl
January 18, 2020

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core

@hess - Kestrel is the hosting interface that runs the ASP.NET Core application. It's the HTTP front end that provides the actual connections to the application. If you're running InProcess in IIS you can't have both Kestrel and IIS handling the connections. You can if you run OutOfProcess because OutOfProcess basically proxies to a separate Kestrel process (dotnet.exe).

Off the top of my head I don't know how IIS Express hosting works. I think the default hosting uses out of process hosting, but I think it probably depends on the project setting as well - I haven't checked recently.

In Visual Studio you can choose how you want to run your application in Debug mode: IIS Express, YourApp.exe (Kestrel standalone running dotnet.exe) or whatever else you set up and configure in launchsettings.json.


Hess
January 17, 2020

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core

You say "The In Process model does not use Kestrel".

Question: Is it still true when I explicitly ask for Kestrel in "Program.cs"?

"Host.CreateDefaultBuilder().ConfigureWebHostDefaults(webBuilder ⇒ webBuilder.UseKestrel())"

If yes, how does IIS Express which is spun up by Visual Studio in debug time can alter this and cancel Kestrel instantiating?


Rick Strahl
January 17, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

@Donnie - ASP.NET Core doesn't write the logs into wwwroot. It goes in the content root, which is the folder above it - wwwroot is a sibling folder to that. IOW, you can't access the logs via HTTP requests, so I don't think there's anything wrong with how that works.


Rick Strahl
January 16, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

@zjaadc - yup. Probably added recently when this was discovered.

But honestly even if I read this chances are I wouldn't have fixed it buried in all of this. In my case I didn't even realize I had the back reference in place it was likely imported inadvertently by a stray reference in the code from beta times.


zjaadc
January 16, 2020

Anders
January 15, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

Great post, we're in Germany and I'm sure it will help us as we're going to be deploying our app in about 5 months. However, I took a look at the thread on twitter and you omitted something in your post. You said,

@JustinKotalik on the ASP.NET team spotted my Github Issue and pin-pointed the solution only a little while after posting on Github:

That isn't what I saw. There was a non-microsoft guy that nailed it first before any of them and wasn't even mentioned in this post, just thought I would point that out because you're crediting the guys that created the problem in the first place 😃

Anyway, thanks for the post and for posting the twitter links so we could follow the progression. People like you don't get enough thanks for the valuable service you perform by running up against issues and then making sure guys like us don't have to spend the hours of anguish trying to figure out what the heck went wrong.


Donnie Hale
January 15, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

Rick,

Thanks for the post. One comment. As far as I know, the web.config that results from a "dotnet publish" still includes the stdout log file location of ".\logs\stdout". That's wrong and should be corrected by MS. I spent a couple of days on the phone w/ MS Azure support dealing with an ANCM issue. One recommendation coming out of that was that an application should never write to the "wwwroot" folder in an Azure app service.

For something running locally, it may not be a problem. But as is documented in other places, the better value for the stdout log file location is "\?%home%\LogFiles\stdout". Once I made that change in the app service's web.config, tracking down the real source of the error was quick.

-Donnie


Rick Strahl
January 15, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

Thanks @tune - fixed.

@rich - I don't know if I agree. web.config has never been a big issue for me. Maybe in the early .NET 2.0/3.x days, but in recent years there was very little that needs to be configured as the defaults were good. And those are the same defaults you use with .NET Core now.

And remember - Kestrel is just an application web server, it's not a full Web Server that provides the hosting and Web support infrastructure. If you're just talking about Kestrel you still need IIS or something else to provide security, SSL, Caching etc. and THAT'S really what's causing the extra configuration nightmares in IIS for the most part. You will still have those with .NET Core unless you use some other host.


rich
January 15, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

I've seen that error but in my case it was when I'd updated an app to 3.1 and not installed 3.1 on the server.

I find .NET Core 3.1 the most insane aid to productivity since I started developing in 1985.

Did you ever think we would have XCOPY deployment of websites on Windows? No more bizarre error messages! No more spelunking through gargantuan web.config files trying to find the cause! No more deployment wizard!

Instead a vestigial web.config file to keep IIS happy, copy all the code into a folder, and move on with your day !


Tune
January 15, 2020

re: ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1

Thank you Rick,

For your comprehensive post! I stumbled upon a few minor typos:

  • Damien Edwards → Damian Edwards (twice)
  • packages/assmeblies → packages/assemblies
  • Apparently when there one → Apparently when one
  • buyt → but

Thanks for your sharing your experience(s)! Tune


Sanjay Gupta
January 15, 2020

re: FontAwesome Fonts and Mime Types in IIS and other Web Servers

In case it is still giving HTTP-404 error for .woff and .woff2 file types, add them in request filtering and it will work.


Rick Strahl
January 12, 2020

re: Using the ng-BootStrap TypeAhead Control with Dynamic Data

@Richard - this control is very funky in its behavior in other ways too, and to me at least damn unintuitive. I had no luck getting the converters to do the right thing, turning the result value from an object into a single string value for example. It worked for display, but the final value binding - not so much. I ended up having to change my service data returned to make this work 😏


HDN
January 12, 2020

re: Back to Basics: String Interpolation in C#

Great article. Thanks for clearly pointing out that this feature cannot be used as a template system.


Peter Drinnan
January 12, 2020

re: Using the ng-BootStrap TypeAhead Control with Dynamic Data

I agree with Asad. Would never have figured this out using the offical docs. This is the best example I have seen so far. Been on a dozen sites looking for something like this. Thanks so much.


Richard Bond
January 11, 2020

re: Using the ng-BootStrap TypeAhead Control with Dynamic Data

Thanks for this!

I struggled with this on my own site for a week before settling on a hacky work-around. With this new information, I'm excited to go back and do it "right".


Coy Meeks
January 07, 2020

re: Accessing Configuration in .NET Core Test Projects

Good stuff, Rick! To heck with mocking IConfig when you can just use the real thing! 😃

I wanted to check with you to see if you've ported this to work with Xunit. On my end, it doesn't appear that you need to specify the outputPath of the config and I wanted to confirm there would be no issues. Thanks again!


Rick Strahl
January 07, 2020

re: A few notes on creating Class Libraries for ASP.NET Core

@Evgeny - it depends on who your target is. If you're building internal infrastructure and you control what's being used then using full framework references is the way to go to keep maintenance minimal.

But if you're a library creator for a lib that's used by a general audience, you want to be careful to minimize dependencies to just what you need rather than forcing a full framework (and potentially a specific version thereof) on all your dependent users.


Evgeny Gorbovoy
January 07, 2020

re: A few notes on creating Class Libraries for ASP.NET Core

I'm going to reference exactly big meta package, because I'm moving almost everything from executable to satellite assembly and I can't spend time on finding appropriate package for everything. And as for me, netcore team should not expect that developers will do it. I'll also try to change SDK of assebly from Microsoft.NET.Sdk to Microsoft.NET.Sdk.Web, but that requires the creation of entry point.. All this things throw me off, honestly.


Alex Lindberg
January 06, 2020

re: Using the ng-BootStrap TypeAhead Control with Dynamic Data

This is close to what I am needing. My REST applications returns, using your example, a JSON using bandId as key along with other related data.

What I need to show in my ng-bootstrap typeahead is the Band Name based on bandId. The Band Name is found when using another REST query which returns the JSON you have described as [ { name: "band", id: "bandId" } ]

How do you use put the bandId in the FormControl and while displaying the Band Name?


Simon Boland
January 05, 2020

re: Automating IIS Feature Installation with Powershell

I'm curious if there's a way to do the opposite and take an existing IIS configuration and list all of the options that are enabled? Is it simply a backup and restore procedure?

Basically I need to migrate an existing IIS application from one cloud provider to another and I think this is what I'm after.


Raja
January 02, 2020

re: Working around the lack of dynamic DbProviderFactory loading in .NET Core

Hi Rick/Adam, very good article.I need one help. with the .net core 3.1 it supports dbProviderFactory. I just came to know still we have to do call DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", SqlClientFactory.Instance); in order to get the specific instance.

I want to know which is the right place to do register. shall i register in start up?. I am trying to create a generic db helper which shd work all providers.

appreciate your help.


Rick Strahl
January 02, 2020

re: Back to Basics: Non-Navigating Links for JavaScript Handling

@Sro - Perhaps, but the whole point of this exercise is a 'non-navigating' link. If you're actually wanting to navigate then you can use a real link. IOW, you wouldn't have target="_blank" on a non-navigating link.


Sro
January 02, 2020

re: Back to Basics: Non-Navigating Links for JavaScript Handling

Well, #0 is not good enough if you have target="_blank"


Ken Lassesen
December 31, 2019

re: More on ASP.NET Core Running under IIS

I am looking at migrating a huge Asp.Classic (3K files) to Net.Core 3.1 in steps (i.e. folder by folder migration). We have figured out issues with sharing sessions and prefer not to go parallel sites (but may end going there if there is not a simple solution).

One line (in ←- --> below) in a merged Web.Config determines if Asp.Classic loads or Net.Core loads.

  • Commented out: Asp.Classic
  • Uncomment: Net.Core
    <system.webServer>
	    <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <!--<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />-->
      </handlers>
        <aspNetCore processPath="dotnet" arguments=".\WebApplication1.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>

I realize that ISAPI filter written in C++ is a possibility (in one way easy: if there is an .asp in the request go to Asp.Classic, otherwise pass to Net.Core)

Can you see any deal-breaker going the ISAPI filter route (or even better, know of a public Git project that does it?)


Wade @ DNCT
December 30, 2019

re: .NET Core 3.0 SDK Projects: Controlling Output Folders and Content

Just in response to Ruslan, I also had the same "issue" or more so confusion.

Rick is right in that when you do a dotnet publish, your wwwroot is copied by default. However I think what Ruslan is having issues with is on a build, the wwwroot not being copied to the debug folder which seems to be correct. The wwwroot is only copied when you do a full publish, but not when you do a "dotnet build" or "Ctrl+Shift+B".

Whether or not this is correct, I would question what you need the wwwroot in the debug folder for anyway, since if you are copying this to a remote server etc, then you should do a dotnet publish. And if you are debugging etc, then you should be using dotnet run etc.


Dave ORourke
December 30, 2019

re: Using .NET Standard with Full Framework .NET

Hi Rick. Just wanted to say thanks for this post. We hit this same problem while updating from .NET 4.6.0 to 4.6.2. When we updated our NuGet dependencies (Update-Package -Reinstall from Nuget Package Manager Console), we picked up a netstandard2.0 <HintPath> for a few packages. This then caused ~100 DLLs to be copied by MSBuild to our output folder. This was baffling until we found your post, which explained it all. We were able to side-step this problem by reverting the <HintPath> for the NuGet packages to something other than the netstandard2.0 version of the affected packages. This got us to .NET 4.6.2 without taking all those DLLs as deployment dependencies. I'm now in the process of retargeting to .NET 4.7.2 to prevent another member of our team from accidentally re-introducing this problem. So a big thanks from the TechSmith Camtasia team for your post! Much appreciated!


Rick Strahl
December 28, 2019

re: Debugging the Web Browser Control with FireBug

@buli - Yup the JavaScript Console is no longer available in VS2019 which is why I still keep VS2017 around 😦.


Asad
December 27, 2019

re: Using the ng-BootStrap TypeAhead Control with Dynamic Data

Thanks for this explanation. The official docs don't explain much.


Rick Strahl
December 25, 2019

re: Don't let ASP.NET Core Console Logging Slow your App down

@Matteo - thanks for that - that's a good data point.

Still not sure if that is the cause though -I'm running 8 simultaneous requests in these tests (full throttle, no delay) so in theory there shouldn't be more than 8 requests running simultaneously (maybe with some rolloff, but not massively over the 8 client treshold), unless... the caching is actually slow and the many debug log requests are quickly filling up the cache.


Conelious
December 23, 2019

re: Dynamically Loading Assemblies at Runtime in RazorPages

Hi Guys,

just been testing your app and indeed it crashes when in debug. However i then started experimenting other ways to load assemblies. i then made a some changes to the blazor router to load assemblies there and it seems to be working except when you get 2 assemblies with same route names. I was wondering what could be the draw back in using this method?

@using System.Reflection @using System.IO @using Microsoft.AspNetCore.Components;

Sorry, there's nothing at this address.

@code { List AdditionalAssemblies = new List();

protected override void OnInitialized()
{
    string Pathname = "C:\\source\\repos\\RazorClassLibTest\\RazorClassLibTest\\bin\\Debug\\netstandard2.0\\RazorClassLibTest.dll";
    string Pathname2 = @"C:\source\repos\RazorClassLib2\RazorClassLib2\bin\Debug\netstandard2.0\RazorClassLib2.dll";
    var assembly = Assembly.LoadFrom(Pathname);

    var type = assembly.GetType("RazorClassLibTest.Component1");
    if (type != null)
    {
        AdditionalAssemblies.Add(type.Assembly);
    }
   assembly = Assembly.LoadFrom(Pathname2);

    type = assembly.GetType("RazorClassLib2.Component1");
    if (type != null)
    {
        AdditionalAssemblies.Add(type.Assembly);
    }
}

buli
December 23, 2019

re: Debugging the Web Browser Control with FireBug

It seems that the "JavaScript Console" solution is removed in Visual Studio 2019.

Luckily the Firebug Lite still works in WPF's embedded web browser control 😃 The link in the code snippet is dead, but it can still be found on CDN's. Thanks for a nice solution!


Rick Strahl
December 19, 2019

re: VSIX Installer Extension Manifest and Visual Studio Version Numbers

@Dmitry - added an additional link to it in the Resources section as I meant to do 😄


Rick Strahl
December 19, 2019

re: VSIX Installer Extension Manifest and Visual Studio Version Numbers

@Dmitry - thanks, Mads' post is referenced in this post above.


Guest
December 19, 2019

re: Dealing with Anti-Virus False Positives

Everybody should report false positives issues in the antivirus twitter accounts!

If complains about false positives is constantly and publicly seen in their twitter accounts, that will really hurt them for sure!


Rick Strahl
December 18, 2019

re: Building a Live Reload Middleware Component for ASP.NET Core

This is meant only Live Reload the server that's running the application.

It is not doing any proxying. This only affects the server application running on whatever port your application is configured for. Unless you run your React app on the same port (ie. as part of the ASP.NET app) it won't refresh.


Rick Strahl
December 18, 2019

re: Strongly Typed Configuration Settings in ASP.NET Core

@Shweta - yes you can't 'intercept' the deserialization process as you could before so whatever value you get is what you get from the configuration. However, there are a few things you can do:

  • Post process the value in your ConfigureServices() handler and decode it there (meh)
  • Use a Getter on the ConnectionString property to decode the value on the fly (or once and cache)

Rick Strahl
December 18, 2019

re: IIS and ASP.NET Core Rewrite Rules for Static Files and Html 5 Routing

@sreedev - not sure what you're asking. If the route you are running is server route that route should be served by the server. Any other routes that map the explicit mappings you set up - including the defaulte empty route which should point at index.html - should be handled by IIS.


Shweta S
December 18, 2019

re: Strongly Typed Configuration Settings in ASP.NET Core

Hi Rick, thanks for the amazing article. I have a ConnectionString in the appSettings.json which is encrypted. Now in Startup in ConfigureServices, I'm decrpyting the same but I'm unable to override the encrypted value as I directly fetch the Configuration.GetSection("MySettings") and add it to Options.

// Add functionality to inject IOptions<T>
   services.AddOptions();
    
// Add our Config object so it can be injected
   services.Configure<MySettings>(Configuration.GetSection("MySettings"));

Hence when I try to read the same in the Controller as settings.Value.ConnectionString I get this as encrypted.

How can I override the same in the Startup before adding it to options. Let me know if I should add more details.

Thanks a lot in advance.


Question
December 17, 2019

re: Building a Live Reload Middleware Component for ASP.NET Core

I can't see where the client proxy part gets configured. I am using a react client that uses port 3000 and I thought your solution would intercept that port and forward it to the dotnet core port on 5000. Any help/advice would be greatly appreciated and thank for the great utility!


Sreedev Melethil
December 17, 2019

re: IIS and ASP.NET Core Rewrite Rules for Static Files and Html 5 Routing

Hi rick,

Greetings of the season.

This article helped a lot, thanks.

We have an angular 7 app hosted on IIS with this in web.config, when i refresh the angular app it goes back to the index.html, is there any way i can rewrite with subpage/route ?

Sreedev


JustMe
December 15, 2019

re: Video Rendering Issues for WPF Windows

While a bit late the party, this does not seem to be a rare issue. Apparently, the hardware rendering part is not properly implemented in WPF. Beside stability, disabling hardware rending also improves memory consumption and GC performance. Other than outlined in this blog post, it is also possible to simply add RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; to the 'MainWindow' constructor.

Thanks for posting!


Dmitry
December 14, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core

The docs are wrong also because 2.2 supports InProcess in addition to OutOfProcess

I guess you are referring to the statement

The in-process hosting model isn't supported for ASP.NET Core apps that target the .NET Framework.

from the 2.2 docs but this means only that it is not supported for the full framework (this statement is also present in 3.x docs).

I still believe that default value somehow changed between 2.2 and 3.x version (according to this commit). I'm just curious about what actual executable process or a module (ANCM?) is responsible for providing default value for hostingModel parameter if it is not provided explicitly (in .csproj or web.config) - couldn't find anything related to this change in asp.net core sources.


Giorgio
December 13, 2019

re: Live Reloading Server And Client Side ASP.NET Core Apps

I'm using the Live Reload MiddleWare with .Net 3.1, works a charm, thanks for this !


Rick Strahl
December 13, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core

I think the docs are actually incorrect. The default value that goes into web.config is determined by the AspNetCoreHostingModel set in the project - that writes out the value that's used. The docs are wrong also because 2.2 supports InProcess in addition to OutOfProcess which is the same as ASP.NET Core 3.x.

As long as you set the value in your project (or an explicit web.config) you get what you specify. If you're multi-hosting on older versions than 2.1 then you may have to default to OutOfProcess to make sure it works and let users explicitly change that value in their deploy scripts or manually change web.config used for publishing.


dave
December 13, 2019

re: Web Assembly and Blazor: Re-assembling the Web

the airs coming out of the blazor hypefest at light speed, funny a friend and I came to all the conclusions years ago now on initial look and zero has or can change, it's a fanbio inspired rabbit whole, "I only know C#" ,TFB, time to get on the .net core bandwagon blogger before it deflates, how about this some click bait like ".Net is DEAD, Long live .net core! and the rod stewart quaife, I only C#"


Dmitry
December 13, 2019

re: ASP.NET Core In Process Hosting on IIS with ASP.NET Core

Hi, Rick. Well explained post. But I have one question. Correct me, if I'm wrong: when we use in-process model - there no separate dotnet.exe process, and asp.net core app runs in bounds of original w3wp.exe process. So, the hosting model, and therefore, the decision if separate dotnet.exe process should be started lays on ANCM? According to the documentation: version 2.2 and version 3.1 have different default values for hostingModel attribute of aspNetCore element. I'm curious, how does it work, it seems that version of ANCM is still the same - AspNetCoreModuleV2, so, how default value is determined?