.net

Optionally serialize a property based on its runtime value

…衆ロ難τιáo~ 提交于 2021-02-06 01:48:03
问题 Fundamentally, I want to include or omit a property from the generated Json based on its value at the time of serialization. More-specifically, I have a type that knows if a value has been assigned to it and I only want to serialize properties of that type if there has been something assigned to it (so I need to inspect the value at runtime). I'm trying to make it easy for my API to detect the difference between "has the default value" and "wasn't specified at all". A custom JsonConverter

Change assembly version for multiple projects

白昼怎懂夜的黑 提交于 2021-02-05 20:55:36
问题 How can I change the assembly version in the file AssemblyInfo.cs for multiple projects. We have around 75 project in our solution and we need to change the version almost every week. What is the fastest way to do this. 回答1: I usually create a file called AssemblyVersionInfo.cs that is included as a link in all projects. I make this file contain the version attributes, and remove the same attributes from the regular AssemblyInfo.cs files. Then you can update version numbers in one file only,

Strong Name sn.exe: Failed to install key pair — Object already exists

橙三吉。 提交于 2021-02-05 20:49:20
问题 I have 2 different versions of the same project on my machine. One from the code trunk, and the other from a code branch. These projects use a .pfx key to enable strong naming. When I first tried to compile the trunk version of the project I get the following error: Cannot import the following key file: sgKey.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key

Strong Name sn.exe: Failed to install key pair — Object already exists

有些话、适合烂在心里 提交于 2021-02-05 20:48:21
问题 I have 2 different versions of the same project on my machine. One from the code trunk, and the other from a code branch. These projects use a .pfx key to enable strong naming. When I first tried to compile the trunk version of the project I get the following error: Cannot import the following key file: sgKey.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key

The author primary signature's timestamp found a chain building issue: UntrustedRoot: self signed certificate in certificate chain

浪尽此生 提交于 2021-02-05 20:40:49
问题 While doing a docker build on my .NET Core project, I got the following error on all my NuGets: 80.19 /app/GradingTool.Tests/GradingTool.Tests.csproj : error NU3028: Package 'Microsoft.EntityFrameworkCore 5.0.0' from source 'https://api.nuget.org/v3/index.json': The author primary signature's timestamp found a chain building issue: UntrustedRoot: self signed certificate in certificate chain [/app/GradingTool.sln] #12 80.20 /app/GradingTool.Tests/GradingTool.Tests.csproj : error NU3037:

Force .NET interop to use local COM DLL

岁酱吖の 提交于 2021-02-05 20:35:36
问题 Is it possible to force an interop assembly to reference a local copy of its associated COM DLL? Here's the scenario: I have a .NET app that references an interop assembly (Interop.OTAClient.dll), which is the interop for a COM DLL (OTAClient.dll, which is the automation API for HP Quality Center). I'm not very knowledgable on COM, but as I understand it the interop assembly looks up the COM classes via GUID references in the registry, rather than pointing to a specific file. The issue I have

Force .NET interop to use local COM DLL

£可爱£侵袭症+ 提交于 2021-02-05 20:35:21
问题 Is it possible to force an interop assembly to reference a local copy of its associated COM DLL? Here's the scenario: I have a .NET app that references an interop assembly (Interop.OTAClient.dll), which is the interop for a COM DLL (OTAClient.dll, which is the automation API for HP Quality Center). I'm not very knowledgable on COM, but as I understand it the interop assembly looks up the COM classes via GUID references in the registry, rather than pointing to a specific file. The issue I have

Why does an empty struct in C# consume memory

吃可爱长大的小学妹 提交于 2021-02-05 20:28:00
问题 I always understood structs (value types) contain exactly the number of bytes as defined in the fields of the structure... however, I did some tests and there seems to be an exception for the empty structs: public class EmptyStructTest { static void Main(string[] args) { FindMemoryLoad<FooStruct>((id) => new FooStruct()); FindMemoryLoad<Bar<FooStruct>>((id) => new Bar<FooStruct>(id)); FindMemoryLoad<Bar<int>>((id) => new Bar<int>(id)); FindMemoryLoad<int>((id) => id); Console.ReadLine(); }

Why does an empty struct in C# consume memory

允我心安 提交于 2021-02-05 20:25:22
问题 I always understood structs (value types) contain exactly the number of bytes as defined in the fields of the structure... however, I did some tests and there seems to be an exception for the empty structs: public class EmptyStructTest { static void Main(string[] args) { FindMemoryLoad<FooStruct>((id) => new FooStruct()); FindMemoryLoad<Bar<FooStruct>>((id) => new Bar<FooStruct>(id)); FindMemoryLoad<Bar<int>>((id) => new Bar<int>(id)); FindMemoryLoad<int>((id) => id); Console.ReadLine(); }

How do I use the IComparable interface?

我的未来我决定 提交于 2021-02-05 20:23:22
问题 I need a basic example of how to use the IComparable interface so that I can sort in ascending or descending order and by different fields of the object type I'm sorting. 回答1: Well, since you are using List<T> it would be a lot simpler to just use a Comparison<T> , for example: List<Foo> data = ... // sort by name descending data.Sort((x,y) => -x.Name.CompareTo(y.Name)); Of course, with LINQ you could just use: var ordered = data.OrderByDescending(x=>x.Name); But you can re-introduce this in