.net

If .Net Core can run on Windows, why can't you reference a .Net Core DLL in .Net Framework?

可紊 提交于 2021-02-17 04:48:05
问题 I get why .Net Framework could cause issues in .Net Core, IE because an API specific to the Windows platform doesn't exist. But why wouldn't you be able to directly reference .Net Core as a library in .Net Framework? If .Net Core runs on windows, what is preventing a .Net Framework app from using .Net Core as if it were a library? I'm aware that you can port the .Net Core library to a .Net Standard Library, but my question is why .Net Framework can't just reference anything written in .Net

Batch script calling robocopy in Process won't terminate

五迷三道 提交于 2021-02-17 04:41:20
问题 If process.Kill() is called from another thread or even another program, the process never comes out of WaitForExit() if the batch script used robocopy.exe until it is finished as if it wasn't killed. Robocopy.exe is called from the batch script. Every other script or program ends as you'd expect. ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "batch.bat"; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.RedirectStandardOutput = true;

Query or deserialize json with dynamic keys using System.Text.Json

╄→гoц情女王★ 提交于 2021-02-17 02:48:30
问题 I have json that looks like this, the key "123" could be any number. { "key1": "", "key2": { "items": { "123": { "pageid": 123, "name": "data" } } } } I want to deserialize or query the json with System.Text.Json so i can get the value of the key "name". How can I do that with System.Text.Json? I'm using .NET Core 3.1. 回答1: Something like: public class Rootobject { public string key1 { get; set; } public InnerObject key2 { get; set; } } public class InnerObject { public Dictionary<string,

Why event not fired when I change selection on DropDownList?

时光总嘲笑我的痴心妄想 提交于 2021-02-16 20:42:10
问题 I have this asp net drp box: <asp:DropDownList ID="ddlLayersList" runat="server" BackColor="#FFFFC0" CssClass="form-control fullwidth" OnTextChanged="ddlLayersList_SelectedIndexChanged" > </asp:DropDownList> Here is how I fill the drop box: private void SetLayers(Dictionary<string, string> layers) { ddlLayersList.DataSource = layers; ddlLayersList.DataValueField = "Key"; ddlLayersList.DataTextField = "Value"; ddlLayersList.DataBind(); ddlLayersList.Items.Insert(0, "-Select Item-"); } And here

Two interfaces have same method

心不动则不痛 提交于 2021-02-16 20:26:13
问题 Interface A { int Add(int a,int b); } Interface B { int Add(int a,int b); } Class D : A, B { int Add(int a,int b) { return a+b; } } Code works fine and didn't produce any error. Class D is using which interface's method? 回答1: Neither, since neither interface HAS a method, merely a method signature. Your method in D implements the signature provided by both interfaces, so it works. Remember, an interface merely specifies the signatures of methods that must exist in an implementation. 回答2:

Add name in My.Settings

≯℡__Kan透↙ 提交于 2021-02-16 20:19:58
问题 How to add a new name in My.Settings? So far, I've learned how to read and edit values in it, but how can I add another row/name at run-time? Something like: My.Settings.AddName.String("foo1") My.Settings.Save() My.Settings.foo1 = "fooNew" I can't see such on the web.. Thanks EDIT: will be used for the name,text and location of dynamically added buttons. SeeThisLink 回答1: The My.Settings application settings are compiled into your assembly. The properties cannot be altered at runtime because

.NET equivalent of Ruby's begin/rescue/else

谁说我不能喝 提交于 2021-02-16 20:01:19
问题 Ruby has an else block that would go in a begin/rescue (try/catch for .NET folks) begin #some code rescue #oh noes! Catches errors like catch blocks in .NET else #only executes when NO errors have occured ensure #always executes - just like the finally in .NET end The code in the else block will only execute if no errors have been raised. Is there a construct in .NET that provides this functionality? 回答1: In .NET, you can just list the code after #some code : try { // some code // Only

Where the 'Type' of a reference value is stored in memory?

左心房为你撑大大i 提交于 2021-02-16 19:50:21
问题 As the reference values are stored in the heap as a data; where do the type information of any reference value is stored? If there are a couple of instances of class Artist; when they are stored in the heap how the .Net tags those memory blocks as type of Artist? thanks! 回答1: void M() { Artist a = new Artist(); } When the method is called, a new stack frame is expanded, CLR has some preparation code before the first statement of the method is executed, like a prolegomenon . During this period

Selecting all items in a ListBox Winform Control

99封情书 提交于 2021-02-16 19:38:03
问题 I'm trying to select all items in ListBox and made this extension method for this purpose: public static void SetSelectedAllItems(this ListBox ctl) { for (int i = 0; i < ctl.Items.Count; i++) { ctl.SetSelected(i, true); } } Problem is that if I have lots of items in the ListBox, it takes a long time to accomplish this task and I can watch how the ListBox is automatically scrolling down and selecting items. Is there a way to temporary pause the update of a control, so that the task would

How to set assembly version, culture and public key token while compiling with Roslyn?

不羁的心 提交于 2021-02-16 19:22:27
问题 I'm using Roslyn to emit a CSharpCompilation object in Visual Studio to a file. The DLL that is generated does not contain any assembly info other than the assembly metadata, and I'd like to add the version and sign it if possible. How can these be done with Roslyn? 回答1: You need to include source code which sets the Assembly* attributes just like in the VS C# project templates. If you have done that, the .NET version info is set. You can read that information with Reflection or tools like