When trying to return with a complex object in .NET Core API, which has a Type property in it, the serializer gives the following exception :
System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues.
Workaround: Declare an enumeration for your types (ex: enum { string, int, etc }) you can parse the value for the requested type explicitly.
This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.
There are tons of newly created logging engines for .NET Core. Log4Net is stable, old school technology in the market. Consider using newer logging technologies, such as NLog or Serilog. But if you want to use this engine, you can make it work.
If the “AddLog4Net” method call is unrecognized by IntelliSense, make sure you have installed the Logging extension NuGet package mentioned above.
Add a new file to your project, and name it log4Net.config. The template should be used is Web Configuration file.
Make changes in the newly generated file, here you can configure the applications logging. I’ve skipped Console logging, Microsoft’s console logger visualize logs much greater. You can learn configuring Log4Net more at https://logging.apache.org/log4net/release/manual/configuration.html A quick start configuration example:
This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.
You may want to host your .NET Core application in a Windows computer, even a Windows server. You want to get rid of Console windows, and do not want to start the app manually after the computer is started, or restart it when the application has crashed. This tutorial helps you to make a windows service from your .NET Core application, especially a .NET Core WebAPI.
Install the “Microsoft.Extensions.Hosting.WindowsServices” NuGet package for you .NET Core application. This can be achieved from NuGet package manager console:
This is all of the code change you need to do. Let’s Publish your application.
Publish your application to a folder
Make the following changes in the following dialog by pressing an edit button next to a summary label.
Set the deployment mode toself-contained
Click on Publish. Once the publish is done, copy the published files to a specific directory of the computer, or an another computer. Run the powershell script above, to create a new windows service on the hosting computer.
Do NOT forget to set the inbound policies for your application in Advanced Windows Firewall. Also keep in mind, if you want to access your web application outside of your local network, you need to forward ports on your router.
This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.
Cookie settings
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Cookie
Duration
Description
_ga
2 years
Google Analytics : Used to distinguish users.
_gat
1 minute
Google Analytics
_gid
24 hours
Google Analytics : Used to distinguish users.
AMP_TOKEN
30 seconds to 1 year
Google Analytics: Contains a token that can be used to retrieve a Client ID from AMP Client ID service. Other possible values indicate opt-out, inflight request or an error retrieving a Client ID from AMP Client ID service.