{"id":3820,"date":"2024-10-31T13:01:00","date_gmt":"2024-10-31T13:01:00","guid":{"rendered":"https:\/\/john.pentaidea.com\/?p=3820"},"modified":"2025-06-12T10:57:38","modified_gmt":"2025-06-12T10:57:38","slug":"c-net-net-core-faq","status":"publish","type":"post","link":"https:\/\/john.pentaidea.com\/?p=3820","title":{"rendered":"C#\/.NET\/.NET.Core FAQ"},"content":{"rendered":"<p><b><span style=\"font-size: 14pt\"><span>Other\u00a0<\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Print console log:<\/p>\n<\/li>\n<\/ul>\n<pre><code>Debug.WriteLine(\"Hello World\");\nConsole.WriteLine(\"Hello World\");\u00a0 \/\/ not working\n<\/code><\/pre>\n<ul>\n<li>\n<p>Best practice for just a-z0-9 string comparison<\/p>\n<\/li>\n<\/ul>\n<pre><code>stringA.Equals(stringB, StringComparison.OrdinalIgnoreCase)\n<\/code><\/pre>\n<ul>\n<li>\n<p>Debug back to previous file\/historcal breakpoint<\/p>\n<\/li>\n<ul>\n<li>\n<p>Step Backward &#8220;<b>Alt + [<\/b> &#8220;<\/p>\n<\/li>\n<li>\n<p>For full functions with Enable &#8220;<b>IntelliTrace snapshots<\/b>&#8220;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p>Damn DB connectionString<\/p>\n<\/li>\n<\/ul>\n<pre><code>\/\/ Netcore appsetting - mdf\nconnectionString=\"Data Source=(localdb)\\\\MSSQLLocalDB;Initial Catalog=dbtest;Trusted_Connection=True;\" providerName=\"System.Data.SqlClient\"\n\n\/\/ Netcore appsetting - sqlite?\nconnectionString=\"DataSource=.\/database\/app.db\" \n\n\/\/ appsetting for AD \n\"ConnectionStrings\": {\n\u00a0 \u00a0 \"Database\":Server=localhost;Database=master;Integrated Security=True;Trusted_Connection=True;\"(MultiSubnetFailover=True;ConnectRetryCount=3;ConnectRetryInterval=3;Connection Timeout=30;) }\n\n\n\n<\/code><\/pre>\n<ul>\n<li>\n<p>VS: write to console<\/p>\n<\/li>\n<\/ul>\n<pre><code>System.Diagnostics.Debug.WriteLine()\n<\/code><\/pre>\n<ul>\n<li>\n<p>Implement <\/p>\n<\/li>\n<li>\n<p>New a sample application by cli tool with authentication<\/p>\n<\/li>\n<\/ul>\n<pre><code>dotnet new mvc --auth Individual\n<\/code><\/pre>\n<ul>\n<li>\n<p>Define property with default value\u00a0 in single line<\/p>\n<\/li>\n<\/ul>\n<pre><code>public int X { get; set; } = x; \/\/ C# 6 or higher\n<\/code><\/pre>\n<ul>\n<li>\n<p>Improve Visual Studio 2019 performance<\/p>\n<\/li>\n<ul>\n<li>\n<p>Disable the Diagnostic Tools, <b>Tools &gt; Options &gt; Enable Diagnostic Tools<\/b><\/p>\n<\/li>\n<li>\n<p>Ref: <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/visual-studio-performance-tips-and-tricks?view=vs-2019\" rev=\"en_rl_none\">https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/visual-studio-performance-tips-and-tricks?view=vs-2019<\/a><\/p>\n<\/li>\n<\/ul>\n<li>\n<p>[AutoMapper] installiation for NetCore<\/p>\n<\/li>\n<\/ul>\n<pre><code># install package (and DI)\nAutoMapper.Extensions.Microsoft.DependencyInjection\n\n# Add DI\nservices.AddAutoMapper(typeof(MappingProfile));\n\n# Add Profile\npublic class MappingProfile : Profile\n{\n\u00a0 \u00a0 public MappingProfile()\n\u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 CreateMap&lt;Source, Dest&gt;().ReverseMap();\n\u00a0 \u00a0 }\n}\n\n# Start mapping\nprivate readonly IMapper _mapper;\npublic ValuedController(IMapper mapper)\n{\n\u00a0 \u00a0 _mapper = mapper;\n}\n...\nDest campaign = _mapper.Map&lt;Source&gt;(request);\n\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>[AutoMapper]<\/b> Error mapping: lost child mapping: <b>Mapping object to child object<\/b><\/p>\n<\/li>\n<\/ul>\n<pre><code>Mapper.CreateMap&lt;ParentDto, Parent&gt;()\n\u00a0 .ForMember(m =&gt; m.Children, o =&gt; o.Ignore()) \/\/ To avoid automapping attempt\n\u00a0 .AfterMap((p,o) =&gt; { o.Children.xxx = p.ChildrenXXX); });\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Entity Framework error \u201cSequence contains no elements\u201d<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Cause:\u00a0Find() not returning value\u00a0<\/p>\n<\/li>\n<li>\n<p>Solve: Use FindOrDefault() rather than\u00a0Find() to get &#8220;null&#8221;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>C# &#8211; Substring by regex, not found: empty<\/b><\/p>\n<\/li>\n<\/ul>\n<pre><code>Regex.Match(input, @\"FindKey=(\\w+)\").Groups[1].Value\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Prebuild event in Visual Studio replacing $(SolutionDir) with *Undefined*<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Msg:<\/p>\n<\/li>\n<ul>\n<li>\n<p>when using\u00a0<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<pre><code>\u00a0 &lt;Project&gt;\n\u00a0 ...\n\u00a0 \u00a0 &lt;Target Name=\"AfterBuild\"&gt;\n\u00a0 \u00a0 \u00a0 &lt;Copy SourceFiles=\"$(SolutionDir)..\\Lib\\*.dll\" DestinationFolder=\"$(OutDir)Debug\\bin\" SkipUnchangedFiles=\"false\" \/&gt;\n\u00a0 \u00a0 \u00a0 &lt;Copy SourceFiles=\"$(SolutionDir)..\\Lib\\*.dll\" DestinationFolder=\"$(OutDir)Release\\bin\" SkipUnchangedFiles=\"false\" \/&gt;\n\u00a0 \u00a0 &lt;\/Target&gt;\n\u00a0 &lt;\/Project&gt;<\/code><\/pre>\n<ul>\n<ul>\n<ul>\n<li>\n<p>Get error<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<pre><code>18:17:09 D:\\CI_FOLDER\\SYSTEM\\Jenkins\\workspace\\XXX_Daily_Build\\Src\\XXX\\XXX.csproj(273,5): error MSB3030: Could not copy the file \"*Undefined*..\\Lib\\x86\\YYY.dll\" because it was not found.\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>Ans:\u00a0\u00a0replacing all $(SolutionDir) with $(ProjectDir)..\\.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>IIS &#8211;\u00a0HTTP Error 404.3-Not Found in IIS 7.5 ()<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Msg:\u00a0The page you are requesting cannot be served because of the extension configuration. If the page is script, add a handler. If the file should be downloaded, add a MIME map.<\/p>\n<\/li>\n<li>\n<p>Ans:\u00a0\u00a0<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>Control Panel -&gt; Programs and Features -&gt; Turn Windows features on or off\nInternet Information Services -&gt; World Wide Web Services -&gt; Application Development Features\n&gt;&gt;\nCheck all ASP.NET (.NET Extensibility, ISAPI Extensions, ISAPI Filters will be selected automatically).\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>VS &#8211; Trace back code (find last step on break point)<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>After version Visual Studio Enterprise <b>2017 version 15.5<\/b> Preview.<\/p>\n<\/li>\n<li>\n<p>Enable : <b>Tools<\/b>, <b>Options<\/b>, <b>IntelliTrace<\/b> settings, and select the option \u201c<b>IntelliTrace events and snapshots.<\/b>\u201d<\/p>\n<\/li>\n<li>\n<p>Get trace back on <b>Stack Frame<\/b>\u00a0<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/d4d341ad54844fe50e2d1b88fe25bb5e.png\" \/><\/li>\n<\/ul>\n<\/ul>\n<p><b><span style=\"font-size: 14pt\"><span>C#<\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Nullable type<\/p>\n<\/li>\n<\/ul>\n<pre><code>\/\/ ex. Guid? aa\n\/\/ if aa is null\naa.HasValue == False\naa == null\naa.Value =&gt; exception\nGuid.NewGuid() == aa\u00a0 =&gt; can do compare with guid or null\n\n\/\/ if aa not null \naa.HasValue == True\naa.Value =&gt; type is Guid not Guid?\n<\/code><\/pre>\n<p><b><span style=\"font-size: 14pt\"><span>.NET.Standard\u00a0<\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Enable C# 8 in your project<\/p>\n<\/li>\n<\/ul>\n<pre><code>\/\/ To use C# 8 features you need to enable it in your project. This may already be the case by default, but you can be explicit by editing the csproj and adding \/\/&lt;LangVersion&gt;8.0&lt;\/LangVersion&gt;:\n\n&lt;Project Sdk=\"Microsoft.NET.Sdk\"&gt;\n\u00a0 &lt;PropertyGroup&gt;\n\u00a0 \u00a0 &lt;OutputType&gt;Exe&lt;\/OutputType&gt;\n\u00a0 \u00a0 &lt;TargetFramework&gt;netstandard2.0&lt;\/TargetFramework&gt;\n\u00a0 \u00a0 &lt;LangVersion&gt;8.0&lt;\/LangVersion&gt; &lt;!-- \ud83d\udc48 Enable C# 8 features --&gt;\n\u00a0 &lt;\/PropertyGroup&gt;&lt;\/Project&gt;<\/code><\/pre>\n<p><b><span><span style=\"font-size: 18.6667px\"><span>.NET.Core\u00a0<\/span><\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>error: ArgumentException, Format of the initialization string does not conform to specification starting at index 0.<\/p>\n<\/li>\n<ul>\n<li>\n<p>use wrong\/unsupport db conection string,\u00a0 in `_connectionFactory.GetDBConnetionString()`<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 using (IDbConnection connection = new SqlConnection(_connectionFactory.GetDBConnetionString()))\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 connection.Open();\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 connection.ExecuteScalar(XXX_SQL, new\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Id = Id,\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 });\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\n<\/code><\/pre>\n<ul>\n<li>\n<p>Error when sending message to Kafka<\/p>\n<\/li>\n<ul>\n<li>\n<p>Error:<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>{\"Method not found: 'System.Threading.Tasks.Task`1&lt;Confluent.Kafka.DeliveryResult`2&lt;!0,!1&gt;&gt; Confluent.Kafka.IProducer`2.ProduceAsync(System.String, Confluent.Kafka.Message`2&lt;!0,!1&gt;)'.\"}\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>Ans:\u00a0 Install package: &#8220;Confluent.Kafka&#8221;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>Enable debugging on IIS (Detailed error message)<\/b><\/p>\n<\/li>\n<li>\n<p><b>HTTP Error 500.30 &#8211; ANCM In-Process Start Failure<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Issue:\u00a0If the target machine you are deploying to doesn&#8217;t have ANCMV2, you can&#8217;t use IIS InProcess hosting.<\/p>\n<\/li>\n<li>\n<p>Solve (choose one):\u00a0<\/p>\n<\/li>\n<ol>\n<li>\n<p>Install bundle which has ASPNETCoreModuleV2.<\/p>\n<\/li>\n<li>\n<p>Modify .csproj file.<\/p>\n<\/li>\n<\/ol>\n<\/ul>\n<\/ul>\n<pre><code>\u00a0 &lt;PropertyGroup&gt;\n\u00a0 \u00a0 &lt;TargetFramework&gt;netcoreapp2.2&lt;\/TargetFramework&gt;\n--\u00a0 &lt;AspNetCoreHostingModel&gt;InProcess&lt;\/AspNetCoreHostingModel&gt;\n++\u00a0 &lt;AspNetCoreHostingModel&gt;OutOfProcess&lt;\/AspNetCoreHostingModel&gt;\n++\u00a0 &lt;AspNetCoreModuleName&gt;AspNetCoreModule&lt;\/AspNetCoreModuleName&gt;\n\u00a0 &lt;\/PropertyGroup&gt;<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>Ref:\u00a0<a href=\"https:\/\/stackoverflow.com\/a\/53814861\/3634867\" rev=\"en_rl_none\">https:\/\/stackoverflow.com\/a\/53814861\/3634867<\/a><\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>HTTP Error 500.30 &#8211; ANCM In-Process Start Failure<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Issue: can&#8217;t read db connection string of appsettings.json when initializing NetCore .<\/p>\n<\/li>\n<li>\n<p>Solve: fix the format and make it do reading appsettings.json correctly.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>500.19 &#8220;handlers&#8221; This configuration section cannot be used at this path<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Issue: can&#8217;t read &lt;handlers&gt; section at web.config<\/p>\n<\/li>\n<li>\n<p>Solve:<\/p>\n<\/li>\n<ul>\n<li>\n<p>Install windows feature &#8220;Application Development Features&#8221; in World Wide Web Services(IIS)<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/354d3bd2cb478f035869e5700b2a14ab.png\" \/><\/li>\n<\/ul>\n<\/ul>\n<li>\n<p><b>HTTP error 500.30 &#8211; ANCM in-process start failure<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>ANCM == AspNetCoreModule\u00a0<\/p>\n<\/li>\n<li>\n<p>Issue: Logging to specific log folder permission denied<\/p>\n<\/li>\n<li>\n<p>Solve:<\/p>\n<\/li>\n<ul>\n<li>\n<p>Get issue detail by opening stdoutLogEnabled=&#8221;true&#8221; in web.config.<\/p>\n<\/li>\n<li>\n<p>Set log folder permission &#8220;Read\/Write\/Modify&#8221; to local user &#8220;IIS_IUSRS&#8221;.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/efccd39a7a6b02b1fea249596cb43b03.png\" \/><\/li>\n<\/ul>\n<\/ul>\n<li>\n<p><b><span style=\"font-size: 10pt\">Json config with strong type<\/span><\/b><\/p>\n<\/li>\n<\/ul>\n<p><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u5728\u00a0<\/span><\/span><\/span><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>Startup.ConfigureServices<\/span><\/span><\/span><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u00a0\u900f\u904e\u00a0<\/span><\/span><\/span><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>services.Configure&lt;T&gt;()<\/span><\/span><\/span><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u4ee5\u5f37\u578b\u5225\u5c0d\u61c9\u00a0<\/span><\/span><\/span><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>IConfiguration<\/span><\/span><\/span><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u00a0\u5be6\u4f8b\u7684\u65b9\u5f0f\uff0c\u52a0\u5165\u81f3 DI \u5bb9\u5668\uff1a<\/span><\/span><\/span><\/p>\n<p><span style=\"font-size: 10pt\"><i>Startup.cs<\/i><\/span><\/p>\n<table width=\"932px\" style=\"border-collapse:collapse;width:932px\">\n<tr style=\"padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px\">\n<td style=\"border-color:#ccc;border-width:1px;border-style:solid;padding:10px\">\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>1<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>2<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>3<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>4<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>5<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>6<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>7<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>8<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>9<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>10<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>11<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>12<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>13<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>14<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>15<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>16<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>17<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>18<\/span><\/span><\/span><\/div>\n<\/td>\n<td style=\"vertical-align:top;border-color:#ccc;border-width:1px;border-style:solid;padding:10px\">\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span style=\"color:green\">\/\/ &#8230;<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>public<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>class<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>Startup<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>private<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">IConfiguration _config;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>public<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>Startup<\/span><span>(IConfiguration config)<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">_config = config;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>public<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>void<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>ConfigureServices<\/span><span>(IServiceCollection services)<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span style=\"color:green\">\/\/ &#8230;<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">services.Configure&lt;Settings&gt;(_config);<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span style=\"color:green\">\/\/ &#8230;<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u4f7f\u7528\u7684 DI \u578b\u5225\u6539\u6210\u00a0<\/span><\/span><\/span><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>IOptions&lt;T&gt;<\/span><\/span><\/span><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\uff0c\u5982\u4e0b\uff1a<\/span><\/span><\/span><\/p>\n<p><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><i><span>Controllers\\HomeController.cs<\/span><\/i><\/span><\/span><\/p>\n<table width=\"931px\" style=\"border-collapse:collapse;width:931px\">\n<tr style=\"padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px\">\n<td style=\"border-color:#ccc;border-width:1px;border-style:solid;padding:10px\">\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>1<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>2<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>3<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>4<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>5<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>6<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>7<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>8<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>9<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>10<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>11<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>12<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>13<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>14<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>15<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>16<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>17<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>18<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>19<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>20<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>21<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>22<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>23<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>24<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>25<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>26<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>27<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>28<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>29<\/span><\/span><\/span><\/div>\n<\/td>\n<td style=\"vertical-align:top;border-color:#ccc;border-width:1px;border-style:solid;padding:10px\">\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>using<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">Microsoft.AspNetCore.Mvc;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>using<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">Microsoft.Extensions.Configuration;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>using<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">Microsoft.Extensions.Options;<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>namespace<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>MyWebsite.Controllers<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>public<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>class<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>HomeController<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">:<\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>Controller<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>private<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>readonly<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">Settings _settings;<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>public<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>HomeController<\/span><span>(IOptions&lt;Settings&gt; settings)<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">_settings = settings.Value;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>public<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>string<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>Index<\/span><span>()<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">{<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>var<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">defaultCulture = _settings.SupportedCultures[<span>1<\/span>];<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>var<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">subProperty1 = _settings.CustomObject.Property.SubProperty1;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>var<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">subProperty2 = _settings.CustomObject.Property.SubProperty2;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>var<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">subProperty3 = _settings.CustomObject.Property.SubProperty3;<\/span><\/span><\/div>\n<div><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>return<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>$&#8221;defaultCulture({defaultCulture.GetType()}):<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>{defaultCulture}\\r\\n&#8221;<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">+<\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>$&#8221;subProperty1({subProperty1.GetType()}):<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>{subProperty1}\\r\\n&#8221;<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">+<\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>$&#8221;subProperty2({subProperty2.GetType()}):<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>{subProperty2}\\r\\n&#8221;<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">+<\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>$&#8221;subProperty3({subProperty3.GetType()}):<\/span><\/span><\/span> <span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>{subProperty3}\\r\\n&#8221;<\/span>;<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">}<\/span><\/span><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u8f38\u51fa\u7d50\u679c\u5982\u4e0b\uff1a<\/span><\/span><\/span><\/p>\n<table width=\"941px\" style=\"border-collapse:collapse;width:941px\">\n<tr style=\"padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px\">\n<td style=\"border-color:#ccc;border-width:1px;border-style:solid;padding:10px\">\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>1<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>2<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>3<\/span><\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\"><span>4<\/span><\/span><\/span><\/div>\n<\/td>\n<td style=\"vertical-align:top;border-color:#ccc;border-width:1px;border-style:solid;padding:10px\">\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">defaultCulture(System.String): zh-TW<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">subProperty1(System.Int32): 1<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">subProperty2(System.Boolean): True<\/span><\/span><\/div>\n<div><span style=\", Consolas, monospace, sans-serif\"><span style=\"font-size: 10pt\">subProperty3(System.String): This is sub property.<\/span><\/span><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p><span style=\", Arial, sans-serif\"><span style=\"font-size: 10pt\"><span>\u9019\u6a23\u5c31\u53ef\u4ee5\u662f\u5f37\u578b\u5225\uff0c\u4e14\u6709\u660e\u78ba\u7684\u578b\u614b\u3002<\/span><\/span><\/span><\/p>\n<ul>\n<li>\n<p><b>After new installing IIS and Net.Core Bundle, get Error message from website:\u00a0<span style=\"--en-highlight:yellow;background-color: #ffef9e\">HTTP Error 502.5 &#8211; Process Failure<\/span>\u00a0<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Ans1: Install the right <b>NetCore runtime (beside server hosting bundle)<\/b> (more detail message: dotnet XXX.dll)<\/p>\n<\/li>\n<li>\n<p>Ans2: restart IIS by following commands.<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>net stop was \/y\nnet start w3svc\n<\/code><\/pre>\n<ul>\n<li>\n<p><b><span><span style=\"font-size: 10pt\"><span>Got 502.3 error when upgrading .Net.Core version<\/span><\/span><\/span><\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p><span style=\"font-size: 10pt\">Error message:<\/span><\/p>\n<p><span style=\"font-size: 10pt\">An assembly specified in the application dependencies manifest (CloudKeyPool.deps.json) was not found:<\/span><\/p>\n<p><span style=\"font-size: 10pt\">package: &#8216;Microsoft.ApplicationInsights.AspNetCore&#8217;, version: &#8216;2.1.1&#8217;<\/span><\/p>\n<p><span style=\"font-size: 10pt\">path: &#8216;lib\/netstandard1.6\/Microsoft.ApplicationInsights.AspNetCore.dll&#8217;<\/span><\/p>\n<p><span style=\"font-size: 10pt\">This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:\u00a0\u00a0\u00a0\u00a0aspnetcore-store-2.0.0-linux-x64.xml;aspnetcore-store-2.0.0-osx-x64.xml;aspnetcore-store-2.0.0-win7-x64.xml;aspnetcore-store-2.0.0-win7-x86.xml<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"font-size: 10pt\">Solution: Add the follows into .csproj file.<\/span><\/p>\n<p><span style=\", Menlo, Courier, monospace\"><span style=\"font-size: 10pt\">&lt;PropertyGroup&gt;<\/span><\/span><\/p>\n<p><span style=\", Menlo, Courier, monospace\"><span style=\"font-size: 10pt\">&lt;PublishWithAspNetCoreTargetManifest&gt;false&lt;\/PublishWithAspNetCoreTargetManifest&gt;<\/span><\/span><\/p>\n<p><span style=\", Menlo, Courier, monospace\"><span style=\"font-size: 10pt\">&lt;\/PropertyGroup&gt;<\/span><\/span><\/p>\n<\/li>\n<li>\n<p><span style=\", Menlo, Courier, monospace\"><span style=\"font-size: 10pt\">Ref:<\/span><\/span>\u00a0<span style=\"font-family: SFMono-Regular\"><span style=\"font-size: 10pt\"><a href=\"https:\/\/github.com\/dotnet\/coreclr\/issues\/13542\" rev=\"en_rl_none\">https:\/\/github.com\/dotnet\/coreclr\/issues\/13542<\/a><\/span><\/span><\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b><span><span style=\"font-size: 10pt\"><span>Enable IIS Debug log\u00a0<\/span><\/span><\/span><\/b><\/p>\n<p><span style=\"font-size: 10pt\">\u7de8\u8f2f\u00a0<i>web.config<\/i>\u00a0\u6a94\u6848\u3002\u00a0\u5c07\u00a0<\/span><b><span style=\"font-size: 10pt\">stdoutLogEnabled<\/span><\/b><span style=\"font-size: 10pt\">\u00a0\u8a2d\u5b9a\u70ba\u00a0<\/span><span style=\"font-family: monospace, monospace\"><span style=\"font-size: 10pt\">true<\/span><\/span><span style=\"font-size: 10pt\">\uff0c\u4e26\u5c07\u00a0<\/span><b><span style=\"font-size: 10pt\">stdoutLogFile<\/span><\/b><span style=\"font-size: 10pt\">\u00a0\u8def\u5f91\u8b8a\u66f4\u70ba\u6307\u5411 [logs] \u8cc7\u6599\u593e (\u4f8b\u5982\u00a0<\/span><span style=\"font-family: monospace, monospace\"><span style=\"font-size: 10pt\">.\\logs\\stdout<\/span><\/span><span style=\"font-size: 10pt\">)\u3002\u00a0\u8def\u5f91\u4e2d\u7684\u00a0<\/span><span style=\"font-family: monospace, monospace\"><span style=\"font-size: 10pt\">stdout<\/span><\/span><span style=\"font-size: 10pt\">\u00a0\u662f\u8a18\u9304\u6a94\u540d\u7a31\u524d\u7f6e\u8a5e\u3002\u00a0\u5efa\u7acb\u8a18\u9304\u6a94\u6642\uff0c\u7cfb\u7d71\u6703\u81ea\u52d5\u65b0\u589e\u6642\u9593\u6233\u8a18\u3001\u8655\u7406\u5e8f\u8b58\u5225\u78bc\u53ca\u526f\u6a94\u540d\u3002\u00a0\u4f7f\u7528\u00a0<\/span><span style=\"font-family: monospace, monospace\"><span style=\"font-size: 10pt\">stdout<\/span><\/span><span style=\"font-size: 10pt\">\u00a0\u4f5c\u70ba\u6a94\u6848\u540d\u7a31\u524d\u7f6e\u8a5e\u6642\uff0c\u4e00\u822c\u8a18\u9304\u6a94\u6703\u547d\u540d\u70ba<i>stdout_20180205184032_5412.log<\/i>\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><b><span><span style=\"font-size: 10pt\"><span>\u00a0Error\u00a0\u00a0\u00a0\u00a0NETSDK1004\u00a0\u00a0\u00a0\u00a0Assets file &#8216;D:\\{solutionPath}\\obj\\project.assets.json&#8217; not found. Run a NuGet package restore to generate this file.<\/span><\/span><\/span><\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p><span><span style=\"font-size: 10pt\"><span>Tools<\/span><\/span><\/span> <span><span style=\"font-size: 10pt\"><span>&gt;<\/span><\/span><\/span> <span><span style=\"font-size: 10pt\"><span>NuGet Package Manager<\/span><\/span><\/span> <span><span style=\"font-size: 10pt\"><span>&gt;<\/span><\/span><\/span> <span><span style=\"font-size: 10pt\"><span>Package Manager Console<\/span><\/span><\/span> <span><span style=\"font-size: 10pt\"><span>and run:<\/span><\/span><\/span><\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>dotnet restore\n<\/code><\/pre>\n<ul>\n<li>\n<p><b><span><span style=\"font-size: 10pt\"><span>\u00a0How to debug with local NuGet packages<\/span><\/span><\/span><\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p><span><span>Put *.nupkg at specific folder, and add this folder into Tools -&gt; Options -&gt; Add a new NuGet source.<\/span><\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png\" \/><\/li>\n<li>\n<p><span><span>Make the new source checked ONLY (avoid other confusing packages)<\/span><\/span><\/p>\n<\/li>\n<li>\n<p><span><span>Refresh NuGet list.<\/span><\/span><\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b><span><span style=\"font-size: 10pt\"><span>\u00a0Change Nuget feed\/source position<\/span><\/span><\/span><\/b><\/p>\n<\/li>\n<\/ul>\n<pre><code>C:\\Users\\{{UserName}}\\AppData\\Roaming\\NuGet\\NuGet.Config\nC:\\WINDOWS\\system32\\config\\systemprofile\\AppData\\Roaming\\NuGet\\NuGet.Config\u00a0 \u00a0 \u00a0 \/\/For local user:\"SYSTEM\"\n\n=== NuGet.Config ===\n&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;configuration&gt;\n\u00a0 &lt;packageSources&gt;\n\u00a0 \u00a0 &lt;add key=\"nuget.org\" value=\"https:\/\/api.nuget.org\/v3\/index.json\" protocolVersion=\"3\" \/&gt;\n\u00a0 \u00a0 &lt;add key=\"{{new-source}}\" value=\"{{serverLink}}\" \/&gt;\n\u00a0 &lt;\/packageSources&gt;\n&lt;\/configuration&gt;<\/code><\/pre>\n<ul>\n<li>\n<p><b>Check the log of windows service<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>&#8220;Computer Management&#8221; -&gt; &#8220;Event Viewer&#8221; -&gt; &#8220;Windows Logs&#8221; -&gt; &#8220;System&#8221; -&gt; filter by &#8220;Service Control Manager&#8221;<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/78d8e37cb1319da8a13d730bd9405fb0.png\" \/><\/p>\n<p><b><span><span style=\"font-size: 18.6667px\"><span>.NET.Framework\u00a0<\/span><\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>Build errors, can run debug but keep showing errors, like <code>The type 'Expression&lt;&gt;' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.<\/code>, <\/p>\n<p>solution(might be caused by too many projects references, complier got confused):<\/p>\n<\/li>\n<ol>\n<li>\n<p>Fully clean build stuffs:<\/p>\n<p><code>Get-ChildItem .\\ -include bin,obj,.vs -Force -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }<\/code><\/p>\n<\/li>\n<li>\n<p>Pull\/download\/restore existing .dll on Git.<\/p>\n<\/li>\n<\/ol>\n<li>\n<p>List installed NET.framework version \u7248\u672c<\/p>\n<\/li>\n<\/ul>\n<pre><code># all\nreg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\"\n\n# v4 in detail\nreg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\full\" \/v version\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Remove all cache for .NET project<\/b><\/p>\n<\/li>\n<li>\n<p><b>Get &#8220;NULL object not reference&#8221; error when calling Task&lt;XXModel&gt; method<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Ans: Not catching response value.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>Missing NuGet package, eg. System<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Msg:\u00a0This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.<\/p>\n<\/li>\n<li>\n<p>Ans:\u00a0<\/p>\n<\/li>\n<ul>\n<li>\n<p>Reinstall nuget package.<\/p>\n<\/li>\n<li>\n<p>Fix &#8220;package&#8221; folder path inside .csproj file.<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<li>\n<p><b>List usage<\/b><\/p>\n<\/li>\n<\/ul>\n<pre><code>\/\/ if all no null\nif (list.All(x =&gt; x.MyProperty != null))\/\/ do something\n\/\/ if one not null\nif (list.Any(x =&gt; x.MyProperty != null))\/\/ do something\n\n\/\/ find or default\nList&lt;int?&gt; evens = new List&lt;int?&gt; { 0, 2, 4, 6, 8 };\nvar greaterThan10 = evens.Find(c =&gt; c &gt; 10);\nif (greaterThan10 != null)\n{\n\u00a0 \u00a0 \/\/ ...\n}\n\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Mocking static method\/class (Warning: bad idea to mock static)<\/b><\/p>\n<\/li>\n<\/ul>\n<pre><code>You can achieve this with Pose library available from nuget. It allows you to mock, among other things, static methods. In your test method write this:\n\nShim shim = Shim.Replace(() =&gt; StaticClass.GetFile(Is.A&lt;string&gt;()))\n\u00a0 \u00a0 .With((string name) =&gt; \/*Here return your mocked value for test*\/);var sut = new Service();PoseContext.Isolate(() =&gt;\n\u00a0 \u00a0 result = sut.foo(\"filename\") \/*Here the foo will take your mocked implementation of GetFile*\/, shim);\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>Upgrade NET error<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Msg:\u00a0Your project does not reference &#8220;.NETFramework,Version=v4.7.2&#8221; framework. Add a reference to &#8220;.NETFramework,Version=v4.7.2&#8221; in the &#8220;TargetFrameworks&#8221; property of your project file and then re-run NuGet restore<\/p>\n<\/li>\n<li>\n<p>Ans: Delete &#8220;<b>obj<\/b>&#8221; folder and rebuild.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>FileLoadException when using MailKit\/MimeKit<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Error:\u00a0MimeKit The located assembly&#8217;s manifest definition does not match the assembly reference<\/p>\n<\/li>\n<li>\n<p>Ans: Update Nuget\u00a0MimeKit to the same to all project.<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>Can not delete \\bin\\roslyn\\VBCSCompiler.exe &#8211; Access is denied<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Task manager -&gt; stop all &#8220;VBCSCompiler.exe&#8221;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>Config file ScFilesToTransform\u00a0does not define a value for metadata &#8220;Link&#8221;.<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>ErrorMsg:<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>Error\u00a0 \u00a0 \u00a0 \u00a0 The item \"config\\xxx.config\" in item list \"ScFilesToTransform\" does not define a value for metadata \"Link\".\u00a0 In order to use this metadata, either qualify it by specifying %(ScFilesToTransform.Link), or ensure that all items in this list define a value for this metadata.\u00a0 \u00a0 YYY.Project\u00a0 \u00a0  \n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>Solve:\u00a0 Change &#8220;config\\xxx.config&#8221; to &#8220;Copy if newer&#8221;<\/p>\n<\/li>\n<\/ul>\n<li>\n<p><b>Couldn&#8217;t load\u00a0EnterpriseLibrary.Logging<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>ErrorMsg:<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>loggingConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Logging\n<\/code><\/pre>\n<ul>\n<ul>\n<li>\n<p>Solve: Version and PublicKeyToken should be the same<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<pre><code>Version=x.x.x.x, Culture=neutral, PublicKeyToken=yyyyyyyyy\n<\/code><\/pre>\n<ul>\n<li>\n<p><b>IIS rewrite module &#8211; remove sub-folder issue\u00a0<\/b><\/p>\n<\/li>\n<li>\n<p><b>HTTP Error 500.30 &#8211; ANCM In-Process Start Failure<\/b><\/p>\n<\/li>\n<ul>\n<li>\n<p>Issue:\u00a0If the target machine you are deploying to doesn&#8217;t have ANCMV2, you can&#8217;t use IIS InProcess hosting.<\/p>\n<\/li>\n<li>\n<p>Solve (ch<\/p>\n<\/li>\n<\/ul>\n<\/ul>\n<p><b><span><span style=\"font-size: 18.6667px\"><span>.NET.Framework \/ IIS<\/span><\/span><\/span><\/b><\/p>\n<ul>\n<li>\n<p>How to do IIS decrypt <\/p>\n<\/li>\n<\/ul>\n<pre><code>C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ASPNET_REGIIS.exe -pdf \"connectionStrings\" \"{{folder_path}}\"\n<\/code><\/pre>\n<ul>\n<li><\/li>\n<\/ul>\n<p><span style=\"font-size: 10pt\">#Net #Net.Core #IIS #Visual stodio #VS<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Other\u00a0<\/p>\n<\/div>","protected":false},"author":1,"featured_media":4015,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[14],"class_list":["post-3820","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts","tag-faq"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C#\/.NET\/.NET.Core FAQ - John&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/john.pentaidea.com\/?p=3820\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C#\/.NET\/.NET.Core FAQ - John&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Other\u00a0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/john.pentaidea.com\/?p=3820\" \/>\n<meta property=\"og:site_name\" content=\"John&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-31T13:01:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-12T10:57:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png\" \/>\n\t<meta property=\"og:image:width\" content=\"841\" \/>\n\t<meta property=\"og:image:height\" content=\"184\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"jj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jj\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=3820\",\"url\":\"https:\/\/john.pentaidea.com\/?p=3820\",\"name\":\"C#\/.NET\/.NET.Core FAQ - John&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/john.pentaidea.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=3820#primaryimage\"},\"image\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=3820#primaryimage\"},\"thumbnailUrl\":\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png\",\"datePublished\":\"2024-10-31T13:01:00+00:00\",\"dateModified\":\"2025-06-12T10:57:38+00:00\",\"author\":{\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\"},\"breadcrumb\":{\"@id\":\"https:\/\/john.pentaidea.com\/?p=3820#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/john.pentaidea.com\/?p=3820\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=3820#primaryimage\",\"url\":\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png\",\"contentUrl\":\"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png\",\"width\":841,\"height\":184},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/john.pentaidea.com\/?p=3820#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/john.pentaidea.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C#\/.NET\/.NET.Core FAQ\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/john.pentaidea.com\/#website\",\"url\":\"https:\/\/john.pentaidea.com\/\",\"name\":\"John's Blog\",\"description\":\"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/john.pentaidea.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f\",\"name\":\"jj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g\",\"caption\":\"jj\"},\"sameAs\":[\"https:\/\/john.pentaidea.com\"],\"url\":\"https:\/\/john.pentaidea.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C#\/.NET\/.NET.Core FAQ - John&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/john.pentaidea.com\/?p=3820","og_locale":"en_US","og_type":"article","og_title":"C#\/.NET\/.NET.Core FAQ - John&#039;s Blog","og_description":"Other\u00a0","og_url":"https:\/\/john.pentaidea.com\/?p=3820","og_site_name":"John&#039;s Blog","article_published_time":"2024-10-31T13:01:00+00:00","article_modified_time":"2025-06-12T10:57:38+00:00","og_image":[{"width":841,"height":184,"url":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png","type":"image\/png"}],"author":"jj","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jj","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/john.pentaidea.com\/?p=3820","url":"https:\/\/john.pentaidea.com\/?p=3820","name":"C#\/.NET\/.NET.Core FAQ - John&#039;s Blog","isPartOf":{"@id":"https:\/\/john.pentaidea.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/john.pentaidea.com\/?p=3820#primaryimage"},"image":{"@id":"https:\/\/john.pentaidea.com\/?p=3820#primaryimage"},"thumbnailUrl":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png","datePublished":"2024-10-31T13:01:00+00:00","dateModified":"2025-06-12T10:57:38+00:00","author":{"@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f"},"breadcrumb":{"@id":"https:\/\/john.pentaidea.com\/?p=3820#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/john.pentaidea.com\/?p=3820"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/john.pentaidea.com\/?p=3820#primaryimage","url":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png","contentUrl":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png","width":841,"height":184},{"@type":"BreadcrumbList","@id":"https:\/\/john.pentaidea.com\/?p=3820#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/john.pentaidea.com\/"},{"@type":"ListItem","position":2,"name":"C#\/.NET\/.NET.Core FAQ"}]},{"@type":"WebSite","@id":"https:\/\/john.pentaidea.com\/#website","url":"https:\/\/john.pentaidea.com\/","name":"John's Blog","description":"\u4e16\u754c\u56e0\u601d\u7dd2\u800c\u8907\u96dc, \u4eba\u56e0\u5922\u60f3\u800c\u5049\u5927","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/john.pentaidea.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/3d2e5980a7d3023e93b91d668d2a4a4f","name":"jj","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/john.pentaidea.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a685414cd92056415bc823b5cfbbf95a44a98df88d8c040b18613724c1c0724b?s=96&d=mm&r=g","caption":"jj"},"sameAs":["https:\/\/john.pentaidea.com"],"url":"https:\/\/john.pentaidea.com\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/john.pentaidea.com\/wp-content\/uploads\/2025\/06\/0065cc6b6c97f58bff280f355847d688.png","_links":{"self":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/3820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3820"}],"version-history":[{"count":6,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/3820\/revisions"}],"predecessor-version":[{"id":4021,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/posts\/3820\/revisions\/4021"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=\/wp\/v2\/media\/4015"}],"wp:attachment":[{"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/john.pentaidea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}