This is likely a bit esoteric, but I was setting up an ASP.NET Core 2.2 project recently where I wanted to store logs in MongoDB. I wanted to play with Serilog vs. some of the alternatives. I also wanted to use a configuration file, and I wasn't able to find any good examples online, so I figured I'd create a quick example in this post. This example is applicable to ASP.NET Core 2.2, and may work for other versions, but isn't tested with others.
Continue readingCategory: Software Development
MongoDB C# Aggregating and Grouping By Distinct Fields
This seems to be a difficult solution to search for at the moment. The MongoDB .NET driver documentation links to the unit test files on GitHub for examples on aggregation related items, but the links are broken. Looking at the repos on GitHub is useful to find the actual tests, but for the specific problem I was trying to solve, it wasn't entirely helpful.
Basically what I was trying to do would be relatively easy with SQL -- a SELECT DISTINCT
from a table/collection based on multiple fields. I really just wanted to get the unique combinations of several fields at the database layer without having to retrieve all the documents from the collection, and then figuring out which were distinct.
Appsettings.json in a .NET Core Console Application
This was originally written for .NET Core 2.0, but it should work in newer versions of .NET, and is the equivalent of the old app.config and ConfigurationManager pattern. Below are the steps to set it up.
Continue readingMicrosoft.SqlServer.Types version 10 or higher could not be found
If you have a connection to SQL Server where you’re using spatial types with Entity Framework, and deploying to an Azure service/server, you may come across the exception:
Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.
WCF Proxy Server Authentication
Many who've written a .NET application which calls a web service have had to deal with service calls passing through a proxy server. In the past, after generating the service client from WSDL, I’d set up a WebProxy (possibly with NetworkCredential) — which really isn’t all that bad, but somewhat annoying. Now, more ideally, the service calls are via svcutil generated WCF clients. However, handling proxies programmatically in WCF is more difficult since you can’t deal with a nice WebProxy object. You can set credentials via ChannelFactory.Credentials, but this has a drawback — your credentials need to be the same for the proxy and server authentication if they both use the same authentication scheme. The programmatic approach has always struck me as unnatural.
Continue reading