Why does my Windows Service built with .net 6.0 and Host.CreateDefaultBuilder fails at startup with DI errors? - windows-services

I've spent too long on this not to share.
I made a Windows Service with .Net 6.0 and the Host.CreateDefaultBuilder method. It worked fine, was deployed correctly. Then I modified something that worked in dev, but failed at startup in prod.
Looking at the logs, there was a problem with Dependency Injection that pointed back to the first line of my Program.cs. I tried everything around every DI thing I injected in the code, all the way to doing an "empty service" that was running a Task.Delay loop with nothing injected at all. It still failed.
I went back with working versions stored in Git. Still failed.
Nothing changed on the server, afaik.

So ultimately, I figured out that the problem was in the bundling of the Publish process: when using publish as single file, it failed. Turning that feature off solved it.
So in your .csproj, add (or modify) this line:
<PublishSingleFile>false</PublishSingleFile>
I don't know why it worked at some point and stopped working, but there's definitely something not right with that process.

Related

Getting suddenly 403(.14) HTTP error after deplyoment ASP.NET MVC application over TeamCity

A few days ago I had to update our .NET Framework 4.8 web application. First it could not be builded because of some TeamCity error on the newest version, link here. After that it could be builded but since then it showed us a custom errorpage after deployment -> 403 - Forbidden. I just changed a string ("exec X" to "exec Y") so we can access a better and faster SQL procedure.
Removing the tiny piece of argument it suddenly succeded in building anyways but the HTTP error still was there.
Neither IIS, Server, Framework Version etc. was updated, only TeamCity and that small code and argument change.
Reverting the changes to the version which had been working fine did nothing.
After a while I found out that it is a 403.14 error and static files can be accessed, but Microsofts help page didn't help a bit, it just showed the directory -> look here.
After that, I decided to shutdown and backup TeamCity and install an older version of it -> Nope.
Searching google and stackoverflow for similiar problems I stumbled upon to this post especially where I tried every single answer. Before I answer further questions on about what I had tried, please read it.
Since nothing helped so far I decided to try something "dumb" and publish the project to the folder and copy the data manually to the server and voi la! It worked! But I don't know why
and also TeamCity still can't do it anymore.
No changes were done to AppPool or other settings, please keep that in mind.
Here are my build settings from teamcity:
Please don't mind missing build steps, since those are either uninteresting or disalbed because some of them I had created to test the failing deployment on our test system.
And also, when running it locally or copying published project works fine..
Problem was with the antivirus blocking some processes, so some Asax_global.dll was missing.

Old Version of Newtonsoft.JSon being Used in Docker

I have an application where I have removed my references to the Newtonsoft.Json library and used instead Swashbuckle.ASpNetCore.Newtonsoft version 6.1.4. When I run this locally everything works great. Swagger loads, I am able to query my API with no issues and the world is a nice place. I deploy this code to an Azure Server in Docker and where everything there was working great before, now I have problems. Swagger will not load and my API doesn't work at all, because the application doesn't even start. It would appear that something, somewhere is looking for Newtonsoft.Json version 12.0.0.0 because this is the error I get in the logs.
Any ideas would be greatly appreciated.
In case anyone else has this issue in the future, here is the solution in my case. The Coverlet NuGet package was causing this error. I removed the package and the problem went away.

How can I debug this error: 'Debugging information for iisexpress.exe cannot be found or does not match'?

I've been working on an MVC 5 code first project for a few months and (seemingly) out of nowhere, Visual Studio is refusing to debug and giving me some strange errors.
When I try to run the application Ctrl+F5 it builds ok but the browser never gets beyond the loading stage, I still have the pinwheel in the browser tab, but the app never loads.
When I try to debug the applicaiton F5 it builds ok, but then comes up with 2 errors, firstly Debugging information for iisexpress.exe cannot be found or does not match. Cannot find or open the PDB file. and then Process with an Id of xxxx is not running.
I've tried loading symbols from MS (https://stackoverflow.com/a/8138518/1778169), using a different database name, uninstalling VS extensions, performing all Windows Updates, repairing the VS installation and even reinstalling VS entirely. Nothing seems to help.
I'm not very familiar with PDB files, but I have done nothing knowingly to change this, and they seem to be in the right place:
I am running out of ideas, but really want to avoid a Windows reinstall if possible.
It's only happening in this one project, so the problem would seem to be with the project itself, not the installation. But I have no idea where to start debugging this problem, or looking for a solution.
Possibly Relevant
I tried running the app on a custom domain (set up in the hosts file and IIS Express's ApplicationHosts.config file). In an attempt to solve this problem I reverted these settings back to the default localhost:[port]. This doesn't seem to have made any difference, but thought I should mention it just in case.
My problem was that the Native Code box was ticked in the Debuggers section of the Web section in Project Properties.
I don't know how this came to be ticked, I certainly never ticked it.
Either way, unticking this box solved my problem.

Synapse and OpenSSL Connect not working in one app

I have done all the searching and can't find a solution to this weird problem that's been bugging me for about 5 hours. I started this app in Lazarus, but then took it across to D5pro to see if I could solve the problem. Thought it might have been a Lazarus "thing."
In D5, I have an app fully-working (so far so good) and I decided to try some different approaches to the look and feel so I "Save Project As" into a new folder. I then went through all of the included Units and saved them to the new Folder. I copied the two OpenSSL .DLL to the new folder. Did a compile and run and it all works fine. Well, almost.
When I tried the new app, the POP3 Unit crashes at "Login"
I have stepped through and all of the basic login stuff, Server, Name, SSL parameters etc is identical to the former version.
I went back to the original app and did a full Build and it still worked fine. I did a full Build on the new app and it still crashes at Login.
It gets through the pop3.Sock.SSLDoConnect() OK, but comes back from pop3.Login() with an error 10061 which according to the BlckSock Synapse-Unit, means "Connection refused."
When it returns from this call Result:=ssConnect(s, #name, SizeOfVarSin(name)); which I assume is in the .DLL it has a Result of -1 which then triggers the GetLastError and that is "10061 - Connection refused"
As far as I can find, everything is identical between the two projects. All Library Paths are in the Environment and not within the project.
Any thoughts and suggestions?
There is not much to work with. Can you see all parameters in the debugger on the various external call moments?
A change of compiler of course can make hidden bugs come to the surface, just like e.g. optimization. A well known difference is that the life time of temps might vary (see here).
Probably you need to nail the defining difference first. As with Delphi, the debugger is your friend here.
OK, problem solved.
Sir Rufo, it was a good idea but it did not help, but thanks for trying.
I had copied the ssleay32.dll into the new app folder BEFORE I started compiling. It did not work. I did a full Build and it still did not work.
I decided to delete the ssleay32.dll and libeay32.dll and do a full Build. I ran it and of course it crashed, but this time I expected that.
I then copied the two .ddl back into the new app folder and did another full Build.
Bingo problem solved. Seems weird but it is working with both Lazarus and D5. Something to do with the way the .dll gets linked into compiled .dcu.
Doing the Build with no .dll available cleared that. Dropping the .dll back into the Folder and another Build got the .dll linking correctly included into the .dcu.
Aaarrggghhhhh :)

Grails and IntelliJ Cache Issues

we are using Grails together with Maven and Intellij. For the beginning of the project it worked everything nicely. Now we are getting more and more strange effects like when somebody is checking in wrong code, some are getting error some are not.
Are there any best practices to config IntelliJ so thats it working on each machine good and predictable?
We found out that some having the "make" before starting the project disabled but this didnt solved the issue.
Thanks for your help!
Got very little problems in 2 years. Idea had couple of cache issues a year ago, I wiped caches by hand. Ever since then, had no problems with caches/indexes.
Couple of things I could think of:
grails clean usually fixes most weirdness;
Yes, removing "Before launch - make" flag stops Idea from doing wrong guesses and unnecessary compilation (which id does differently from Groovy compiler);
For every new run configuration, we add ValueFormatter to VM parameters, or add it to Grails defaults;
Create a run configuration for test-app and run it on regular basis;
Give it as much memory as you can in idea.vmoptions.

Resources