clr

What is the alternative to futures and promises in managed C++

荒凉一梦 提交于 2019-12-04 10:05:16
When compiling managed C++ code with the /clr flag, the compiler does not allow the include. I am trying to port my unmanaged C++ code into a managed C++ environment. I see that C# has the alternatives Task and TaskCompletionSource to replace futures and promises but I do not see these options available in managed C++. I need to perform interop with some C++ unmanaged libraries so I cannot switch to C# completely. I still need a C++ layer in between. How can I achieve future/promise functionality in managed C++? Here is an example of unmanaged code in C++ which compiles without the /clr flag:

Why does 'unbox.any' not provide a helpful exception text the way 'castclass' does?

眉间皱痕 提交于 2019-12-04 09:59:30
问题 To illustrate my question, consider these trivial examples (C#): object reference = new StringBuilder(); object box = 42; object unset = null; // CASE ONE: bad reference conversions (CIL instrcution 0x74 'castclass') try { string s = (string)reference; } catch (InvalidCastException ice) { Console.WriteLine(ice.Message); // Unable to cast object of type 'System.Text.StringBuilder' to type 'System.String'. } try { string s = (string)box; } catch (InvalidCastException ice) { Console.WriteLine

Converting bool expression to char in c#

…衆ロ難τιáo~ 提交于 2019-12-04 09:58:57
问题 I passed .NET quiz, when I met a question like below one. Char ch = Convert.ToChar('a' | 'e' | 'c' | 'a'); In console we can see that output for ch variable is g . Can someone describe what is happening ? Thanks! 回答1: This is not what it looks like at first spot. It is more of binary calculations on the int representation of these Char : Here is a full article explaining this with examples: Article So the binary result for the bitwise Or of these 'a' | 'e' | 'c' | 'a' is 103 . If you Convert

How much space does string.Empty take in CLR

天涯浪子 提交于 2019-12-04 09:45:31
How much space does string.Empty take in CLR? I'm guessing it's just one byte for the NULL character. No, the string is a complete object, with an object header (containing a type reference, sync block etc), length, and whatever characters are required... which will be a single null character (two bytes) and appropriate padding to round up to 4 or 8 bytes overall. Note that although strings in .NET have a length field, they're still null-terminated for the sake of interop. The null character is not included in the length. Of course, string.Empty will only refer to a single object no matter how

ILDasm, mscorlib and System.Runtime decompilation differences depending on the directory

别来无恙 提交于 2019-12-04 09:24:48
I have been playing around with ILDasm and have noticed that: Decompiling C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll (36KB) simply returns a manifest file. Decompiling C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.dll (114KB) returns the manifest and all types in the assembly. Decompiling C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\mscorlib.dll (38KB) simply returns a manifest file and decompiling C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll (5171KB) returns a manifest and all

#include <comutil.h> cause errors

风格不统一 提交于 2019-12-04 09:12:17
问题 VS 2010 C++ CLR Library project, errors on adding comutil.h library > Error 20 error LNK2001: unresolved > external symbol "extern "C" long > __stdcall VariantCopy(struct tagVARIANT *,struct tagVARIANT const > *)" (?VariantCopy@@$$J18YGJPAUtagVARIANT@@PBU1@@Z) D:\Projects\AL\Service\ncFlow\ncOPClient.NET\Stdafx.obj ncOPClient.NET > Error 18 error LNK2001: unresolved > external symbol "extern "C" void > __stdcall VariantInit(struct tagVARIANT *)" > (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z) D:

Diagnosing CLR errors in Windows Event Viewer

佐手、 提交于 2019-12-04 08:00:42
We have an .NET desktop application that crashed in production. How do we diagnose the error? I'd like to know the type of exception that occurred, the error message, and the stack trace. Because the exception wasn't handled by our code, we received the "This application has encountered a problem and needs to close" Windows message box. The only option was to close, there was no debug button. This MSDN article suggested looking in the Windows Event registry. I checked there, and here's the information inside it: Faulting application Initect.Server.UI.exe, version 0.12.9084.90, time stamp

What could explain over 5,000,000 System.WeakReference instances on the managed heap?

空扰寡人 提交于 2019-12-04 07:55:31
I have been running load tests against a production ASP.NET web application and am seeing a huge number of System.WeakReferences created on the heap. Within about 15 minutes under load managed heap memory has shot up to about 3GB and I have approximately 5,000,000 references to System.WeakReference. Performing a forced garbage collection of all generations does not release these references. I have seen posts about the __ENCLIST helper class which if assemblies are compiled in debug can create WeakReferences to all objects which are created, at first I thought this was the problem, but have

VC++ Calling a function of /clr project from a function of non /clr project within a solution

余生长醉 提交于 2019-12-04 07:53:57
I referred this somewhat similar question before asking this, but unable to solve my problem I am looking at an old application with many solutions. The problem is happening in one of the solutions (say S). Here is the situation: A project (say P1) inside S has all C/C++ files and needs to call a C# function Since P1 also contains .c files, I can't use /clr option with that If I compile the .c files in P1 as .cpp files then it generates lots of errors, I don't intend to change the source in that legacy .c file So I created another project (say P2) with /clr enabled and created one header file

HashSets don't keep the elements unique if you mutate their identity

匆匆过客 提交于 2019-12-04 05:46:43
When working with HashSets in C#, I recently came across an annoying problem: HashSets don't guarantee unicity of the elements; they are not Sets. What they do guarantee is that when Add(T item) is called the item is not added if for any item in the set item.equals(that) is true . This holds no longer if you manipulate items already in the set. A small program that demonstrates (copypasta from my Linqpad): void Main() { HashSet<Tester> testset = new HashSet<Tester>(); testset.Add(new Tester(1)); testset.Add(new Tester(2)); foreach(Tester tester in testset){ tester.Dump(); } foreach(Tester