Recent Comments



Panache
May 10, 2024

re: Fighting WebView2 Visibility on Initialization

I just locate the form below the primary screen. The WebView2 loads, but is invisible to the user unless they check the task bar.


Darrell
May 07, 2024

re: Speed up your Start Menu by disabling Web Search

Great tip! It's annoying it's a setting that requires a registry change which is often a locked down for business laptops. oh well.


Jon Sagara
May 04, 2024

re: Speed up your Start Menu by disabling Web Search

Hi Rick,

I saw this little tool making the rounds this week, too:

https://github.com/xM4ddy/OFGB

Best,

Jon


Alexandre Jobin
May 01, 2024

re: ASP.NET Core Hosting Module with Shadow Copy Not Starting: Separate your Shadow Copy Folders!

I had the same kind of problem but with a little difference in the error description:

Application '/LM/W3SVC/1444810858/ROOT/mywebsite' with physical root 'D:\APPLS\WebApps\mywebapp' failed to load coreclr. Exception message: Unexpected exception: directory_iterator::directory_iterator: unknown error: "D:\APPLS\WebApps\MW5\MW5.DemandeRemboursement.Web\wwwroot\Composants"

The "Composants" folder is an actual folder, not a deleted one.

  • Each web sites use their own ShadowCopy folder
  • I can deploy many times without problem but one of them will cause the error where the site won't load
  • The only way I've found to fix it is to manually delete the ShadowCopy sub-folders and recyle the AppPool
  • I tried to enable cleanShadowCopyDirectory and since that day, the problem never came back
  • I then disabled cleanShadowCopyDirectory and the problem never came back for now... go figure
  • I enabled ASP.NET Core Module logs to have more info. I'm waiting for the error to come back.
    https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/logging-and-diagnostics?view=aspnetcore-8.0#enhanced-diagnostic-logs

Dalibor Čarapić
April 30, 2024

Rick Strahl
April 29, 2024

re: Programmatic Html to PDF Generation using the WebView2 Control with .NET

@Mohamed

... yeah, and net8.0-windows😄 - that's required in order to use the WebView component!


Manuel Frog
April 25, 2024

re: Connection Failures with Microsoft.Data.SqlClient 4 and later

Year 2023: I upgraded a project from ".NET Core 3.1" to ".NET 6". Some nuget packages had to be updated too; one of them was "Microsoft.Data.SqlClient". I got the above error, another gray hair, and gladly found your solution.

Year 2024: I am upgrading a project from ".NET Core 3.1" to ".NET 8". Some nuget packages had to be updated too; one of them was "Microsoft.Data.SqlClient". I get the above error, another gray hair, and gladly found your solution, again.

Thank you for your blog post! And see you next year in 2025. xD


Mohamed Elnakib
April 24, 2024

re: Programmatic Html to PDF Generation using the WebView2 Control with .NET

Hello, well Applicationpool with on default type network service - the only solution was changing my asp.net core project targetframework to net8.0-windows instead of net8.0


Rick Strahl
April 22, 2024

re: Programmatic Html to PDF Generation using the WebView2 Control with .NET

Make sure you're not using ApplicationPoolIdentity for the App Pool identity. That pseudo account will not be able to create an instance. You have to use a real Windows account for this to work - it works with Network Service, System or any custom Windows account.


Mohamed Elnakib
April 22, 2024

re: Programmatic Html to PDF Generation using the WebView2 Control with .NET

Hello, using this library inside ASP.Net core generated Error 'Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0


Anandastoon
April 15, 2024

re: Fixing Adsense Injecting 'height: auto !important' into scrolled Containers

Finally, Mutation Observer is the answer. I do not care if the ads were cut horribly, my visitor is more important. I've turned off autoads, the optimization size in global settings, etc. etc. Fixing the inline styling also did not work, days of my productivity wasted. I could not believed Google destroy the UX so much while they are promoting material design rules. Thank you for this article, too bad this page is not on the first page of Google Search. Those Community solutions on the top of the page, none of them worked.


Parker Too
April 07, 2024

re: Async Event Methods and preventDefault() in JavaScript

Ha - I have just spent hours on exactly this problem, then came across your post. Thanks for posting - I thought I was going mad!


Rick Strahl
April 02, 2024

re: Programmatic Html to PDF Generation using the WebView2 Control with .NET

@martin - I looked at select-pdf and decided against it. The community edition only prints a few pages, and the paid versions are expensive for distribution. It too uses Chromium - I think at this point they all do including the commercial ones from big vendors. They all wrap Chromium and then add some additional functionality on top, which is what I plan on doing here as well.


Martin K
April 02, 2024

re: Programmatic Html to PDF Generation using the WebView2 Control with .NET

Sorry, your post was TLDR...

I had to implement HTML 2 PDF as a service for a website i worked on recently and had the same troubles.

The Chromium solution wasn't an option since it requires full access to the server (AFAIK) and the website is hosted on a webhotel.. so i had to find something else.

My other problem was that the solution was written in Framework 4.8 (MVC5) and i didn't have time to upgrade.

I found SelectPDF : https://selectpdf.com/community-edition/ which is also available for "Core"

The community edition allows me to print 5 pages, which is more than enough for my project.

But yeah, it's a struggle finding a PDF "file printer" around and many require payment because their solution runs on Azure or AWS as an API. The freeware are usually outdated or rubbish (DinkToPdf).


Rick Strahl
April 01, 2024

re: Publishing and Running ASP.NET Core Applications with IIS

@timmy, there are a lot of choices available but none are quite as simple as publishing from Windows mainly because WebDeploy provides support for many different mechanisms all in one toolchain and it integrates with the CLI.

On the Mac you can use Visual Studio for Mac which has publish support that supports Azure. The new Visual Studio Code tooling might also have similar support by now. But I'm not sure whether there is plain FTP server transfer if you're not running an Azure hosted site or container. Finally there are various publish pipelines that you can use with your GitHub repo to publish from certain branches or new tags using GitHub Actions.

There's an FTP Publish GitHub action:

https://github.com/marketplace/actions/ftp-deploy

I haven't used this because I'm stuck with Windows Servers for my apps and use WebDeploy, and hosted or containerized apps with most customers but that looks like it would work for FTP publish.


timmy
March 31, 2024

re: Publishing and Running ASP.NET Core Applications with IIS

Thanks for the blog. Quite useful.

I'm trying to publish a ASP.NET application to IIS hosted on an Azure VM. There are a lot of guides on how to do this from a Windows development machine.

I'm developing on a Mac. Right now I can do a:

dotnet publish

And manually FTP it over. Are there commands that can allow this to be done in an automated fashion?


Rick Strahl
March 20, 2024

re: Runtime C# Code Compilation Revisited for Roslyn

The point is that CodeDom is legacy code that's part of .NET framework. It's still available on Core via library import, but it's basically wrapper interface on top of Roslyn to mimic the old functionality. There's no reason you should be using the CodeDom for code compilation at this point other than compatibility with existing code that is already using it.


Andrew
March 20, 2024

re: Runtime C# Code Compilation Revisited for Roslyn

Let me try again. The post states that the codedom is the old API, but on the documentation site it is listed under .net 8 extensions section. If you mentioned using of the codedom api anywhere in the context of .net 8, please let me know where. Before posting my question I read your entire post, examined the contents of Westwind.Scripting GitHub repo, and on top of that searched for every occurrence of codedom term on the page, and read again around each one. Only after that I posted my questions. I'm not sure how you arrived at your conclusion 😭


Rick Strahl
March 20, 2024

re: Runtime C# Code Compilation Revisited for Roslyn

@Andrew - apparently you didn't bother to read the post. 😄


andrew
March 09, 2024

re: Combining Bearer Token and Cookie Authentication in ASP.NET

Thanks so much for this article! I found it after days of trying to wrangle a similar setup with current ASP.NET/Identity .NET 8, and with it I was able to get 90% of the way there.

And thanks to @Jovica I was able to fix the last remaining piece to get the auth+authz portion (roles) working by adding that last options.DefaultAuthenticateScheme


Edward Lawrence Williams
March 06, 2024

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

Thank you for mentioning the logs! Hours later Im up and running.


Johnny
February 28, 2024

re: ISAPI Module Crashing on Application Pool Shutdown

@Richard Algeni Jr And what was it you did up to this point to solve it?


John M
February 22, 2024

re: I can’t find my Find Dialog in Visual Studio

Even in 2024 - working on an old project in VS 2008 - this also made my day! Thanks 😃


Oleh
February 21, 2024

re: Preventing iOS Textbox Auto Zooming and ViewPort Sizing

Thanks, mate, it was hard to find the answer to this question and only your guide includes all the required steps and details to avoid this redundant zooming.


Rick Strahl
February 20, 2024

re: Reading Raw ASP.NET Request.Body Multiple Times

@kapsiR - good catch. Might be useful to add that as another optional parameter to the helper.


kapsiR
February 20, 2024

re: Reading Raw ASP.NET Request.Body Multiple Times

EnableBuffering has an overload to specify the memory buffer size.
Would prefer that over using a file baked buffer if the size and RPS fit.


Patrik Pyrzanowski
February 15, 2024

re: HSTS: Fix automatic re-routing of http:// to https:// on localhost in Web Browsers

Thank you, I was wondering why my local development server was serving my app to Firefox just fine. But as soon as I tried to access it through chrome, I was rejected with the chrome error and always landed on the HTTPS protocol.

Note: Before my current project, I was playing around with TLS encryption and certificates on a dev-server on the same port, that's probably how my chrome instance was “poisoned” with the HSTS header 😠. Greetings from Germany!


Giorgi Chakhidze
February 13, 2024

re: Custom Message Formatting in WCF to add all Namespaces to the SOAP Envelope

Funny thing is, I have the exact opposite problem (with CoreWCF): need to move namespace declarations down to individual message elements.


Don Gunter
February 08, 2024

re: Embedding a minimal ASP.NET Web Server into a Desktop Application

Outstanding. I missed the WebSurge part as i was speed reading the first time. Nice. You have quite a few goodies. I'm glad I've found this.

I also found your github before I found your site. The things I've discovered: my ignorance 😉

if you have a moment, would you please explain serving pages with images? I appear to have gotten far enough to make great progress on a project using your server. WOW.

I've come to something i've not been able to handle and have to go to work. Ive served a page with an image. set a breakpoint in your server MapFallback call and it's the image.

i suspect my ignorance is showing.

it's most likely, the <img src="./images/1537317.jpg" alt="This is a picture of produce" width="1024" height="150">

i have tried using "http://127.0.0.1:5003/images/1537317.jpg"

does anyone have a suggestion?

Regards, D.


klaudyu
February 08, 2024

re: Programmatically Opening Windows Terminal in a Specific Folder

although I didn't see it documented (wt -h), this works: wt -d <folder> or wt --startingDirectory <folder>


Edward Lawrence Williams
January 31, 2024

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

Finding this post was like finding water after two days RUNNING in the desert. Thank you so much for sharing!


charlie robson
January 24, 2024

re: Keeping Content Out of the Publish Folder for WebDeploy

You are a supreme being. This has been killing me for weeks! The secret sauce is in the 'Update' override.


Adam
January 02, 2024

re: Preventing iOS Textbox Auto Zooming and ViewPort Sizing

Great content, thanks for this.

I tried the maximum-scale approach, but if I zoom in on another page and then go to my page that gets the viewport set to maximum-scale=1 it still gets the zoom from the previous page.

I do have minimum-scale=1 set and that does work if the page had been zoomed out it will force the new page to be the right scale on load.


Rick Strahl
November 29, 2023

re: Embedding a minimal ASP.NET Web Server into a Desktop Application

I don't think you'd be able to compile a desktop application via AOT.

But to be fair haven't tried it. If never had apps that I could have used AOT on work with it - only thing it ever works for is overly simplistic stuff that's truly self-contained and has few or no outside dependencies.


Fabio Silva
November 29, 2023

re: Embedding a minimal ASP.NET Web Server into a Desktop Application

Nice article, Rick!

Regarding the "Caveat: Requires the ASP.NET Runtime". Doesn't compiling the server app with AOT solve (or alleviate) this problem?


dr vlad
November 21, 2023

re: WPF Window Closing Errors

Thanks; this error is giving me a neck pain since yesterday - just trying to close a child window from its parent control and override the default close with the "x" button.


Michael
November 18, 2023

re: Role based JWT Tokens in ASP.NET Core APIs

Thank you for this article. I have been reading a lot of pages regarding this topic. But this is the best so far, the actualy made my understand every part of the flow. Good work.


Daniel
November 16, 2023

mark
November 15, 2023

re: Updating Assembly Redirects with NuGet

Running this gave me this error:

Add-BindingRedirect : Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401) At line:1 char:20

Get-Project -all | Add-BindingRedirect
CategoryInfo : NotSpecified: (:) [Add-BindingRedirect], FileLoadException
FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.AddBindingRedirectCommand

To solve this:

I was facing the same issue when attempting to run this command, but managed to run it by creating the DWORD variable LoaderOptimization with 1 for value under the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework, then restarting Visual Studio and running the command in the Package Manager Console again.

source: https://stackoverflow.com/questions/76049195/add-bindingredirect-loading-this-assembly-would-produce-a-different-grant-set

viswa
November 04, 2023

re: Fix that damn Git Unsafe Repository

Hi All,

I have already added following safe with * but still I'm not able to clone the repo using groovy script, error remains same

[safe]
        directory = *
stdout: 
stderr: fatal: not in a git directory

Dalibor Čarapić
October 31, 2023

re: Caching your WebView Environment to manage multiple WebView2 Controls

I hate these kinds of errors. WebView2 is probably spinning its own threads and one of them probably fails. Hopefully your solution solves the problem.
You probably tried everything but I have a few recommendation that might help:

  1. Check if the users where the application is failing are having different culture/regional settings (this used to cause issues with Word/Excel COM automation ... it might be the same there)
  2. Use procmon from systernals and capture which files/registry entries the application is 'touching'. If you get one of your customers which reported the issue to run the tool as well it might provide more insight.

Donald Adams
October 31, 2023

re: Caching your WebView Environment to manage multiple WebView2 Controls

This is a big problem for me when I either have multiple controls or the user opens up a second instance of the app. When the error occurs, my app disappears without warning. I agree with all that you wrote above.


Rick Strahl
October 31, 2023

re: Locked Files When Publishing .NET Core Apps to IIS with WebDeploy

@Martin - the issue is that the app is not reliably unloading or not unloading quickly enough perhaps. Yes it should work with just appoffline.html, but the reality is that it doesn't and so files are locked in the folder and can't be updated. Shadow copy works around that by putting things in a new folder and also managing the staggered execution letting the existing IIS AppDomain run out requests that might still be running, while getting the new AppDomain with the updated files to start up.


Martin Kirk
October 31, 2023

re: Locked Files When Publishing .NET Core Apps to IIS with WebDeploy

I wonder why this doesn't work with Filesystem deploy... it should be faily simple mechanic to add the app_offline and then proceed to copy files after waiting for x milliseconds.


Enrico
October 21, 2023

re: Fix that damn Git Unsafe Repository

How can I find the .gitconfig file in a linux distro? I am using openSUSE for a work from an undergraduate course and git config --global --add safe.directory <Git folder> just doesn't work...

thank you!


Øystein Amundsen
October 16, 2023

re: Preventing iOS Textbox Auto Zooming and ViewPort Sizing

Just putting this here: https://gist.github.com/OysteinAmundsen/9e6b2ebdf8264ec0e25a0540661949bc

It is made for angular, but the point is:

  1. Select input element
  2. On pointerover and focus, add maximum-scale=1 to the viewport meta tag.
  3. On pointerout (if input element is not focussed) and blur, remove the maximum-scale=1 from the viewport meta tag.

This works if you do not want to or cannot change font-size, and do not want to or should not prevent users from zooming in the application. Zoom is only disabled when input field is in focus.


Rick Strahl
October 04, 2023

re: Rolling Forward to Major Versions in .NET

Hmmm... I think the sdk key is used for picking the SDK version used for executing dotnet CLI commands, not for the runtime used to execute the application.

Should be easy to test - allowPreRelease plus rollforward should also allow using the preview release. I think I tried that at the time. I'll take another look when I get back to my machine.


Muhammad Rehan Saeed
October 03, 2023

re: Rolling Forward to Major Versions in .NET

You can set allowPrerelease in global.json like so:

{
  "sdk": {
    "allowPrerelease": false,
    "rollForward": "latestMajor",
    "version": "7.0.401"
  }
}

I personally also use the above settings and have found them to provide less friction.


MV10
September 15, 2023

re: Async and Async Void Event Handling in WPF

@Sam (does @ work here?) calls to await Task.Delay(0) will generally be more responsive. You pay the overhead of creating a system timer, but Task.Yield indefinitely surrenders control to the scheduler. I was recently benchmarking a background-thread audio-capture loop in a program rendering OpenGL frames on the main thread, and Delay reliably returned about 10% faster than Yield (3600 FPS vs 3250 FPS). Non-Task options were even better, but obviously have no applicability here.

As for ConfigureAwait most of what you read about .NET (Core) is really about ASP.NET, because Microsoft has gone almost completely web-blind. ASP.NET Core doesn't need it, but whether it is required elsewhere is still a question of the framework you're using.