Forum Widgets
Latest Discussions
C# JSON deserialization returns null
Hi there, so first of, I just started working with JSON deserialization today and just know the bare basics. Basically I am currently developing a bot wich should get data from an API of a minecraft server. So far everything works perfectly except one thing: Since a minecraft uuid can start with a number (like for example "121e2d73913041ffaa49af39d124673f") visual studio automatically creates the uuid part with "_" ("public _121E2d73913041ffaa49af39d124673f _121e2d73913041ffaa49af39d124673f { get; set; }"). Now, when I try to request data from a uuid wich starts with a letter everything works fine. However when I request it from a uuid with anumber, it will return null. My guess is, that since the JSON itself does not have "_", it wont get deserialized into the in-code version with "_". -> btw, I am using System.Text.Json, not Newtonsoft.Json but would have no problems changing... I hope. So, my question is, if there is a way to get this to work or maby work arround it? Thanks in advance :DDefinitivVair0Jan 05, 2025Copper Contributor12Views0likes0CommentsChange language for unexpected runtime error messages
I develop apps in VB .NET (currently using .NET 9) for my company. Our IT department controls the language/regional/locale setting for all computers and they will not allow us to change any systems from the default english - U.S.A. So, I make all of my apps to where the user can select what langauge they want the app's UI to be displayed in while they're using it - without changing any system settings, including all custom and expected error message boxes, and doing so by using string resource file. This works very, very well... except for any unexpected error messages which my creep up as they are always displayed in 'en-US'. How can I make my VB applications display all unexpected runtime (while the released application is running) error messages in the same preferred language the user has chosen to display the app's UI in - without changing the computer's language? I've tried the following in my app's entrypoint method and NONE work so far: CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("es-ES") System.Globalization.CultureInfo.DefaultThreadCurrentUICulture=System.Globalization.CultureInfo.GetCultureInfo("es-ES"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES") System.Threading.Thread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");GypsyPrinceJan 01, 2025Copper Contributor6Views0likes0CommentsExtract images from excel stored as Place in cell
Hello experts, I am trying to extract images from an Excel file using a C# program. My code successfully retrieves images that are placed over cells in the worksheet. Now, I need to adapt this functionality so that it can retrieve images which are stored as Place in cell in the excel .I want use this Azure Function for Business Central integration here is the code using Openize.Cells; using System.IO; using DocumentFormat.OpenXml; class Program { static void Main(string[] args) { string filePath = "C:\\Users\\Raj.Kamal\\Downloads\\test.xlsx"; // The path to your workbook string outputDirectory = "C:\\Users\\Raj.Kamal\\Downloads"; // Load the workbook from the specified file path Workbook wb = new Workbook(filePath); // Select the first worksheet from the workbook var worksheet = wb.Worksheets[0]; // Extract images from the worksheet var images = worksheet.ExtractImages(); // Check if the output directory exists; if not, create it if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } // Loop through each extracted image foreach (var image in images) { // Construct a unique file path for the image using a GUID var outputFilePath = Path.Combine(outputDirectory, $"Image_{Guid.NewGuid()}.{image.Extension}"); // Save the image data to the constructed file path using (var fileStream = File.Create(outputFilePath)) { image.Data.CopyTo(fileStream); } } } } Any code snippets, documentation links, or best practices would be greatly appreciated. Excel file:RajKamalDec 09, 2024Copper Contributor39Views0likes0CommentsEnhancing Console.ReadLine to Accept a Message Parameter
n Python, the input function allows you to display a message and wait for user input in a single line of code. However, in C#, achieving the same functionality requires two lines: one for Console.WriteLine to display the message and another for Console.ReadLine to capture the input. Is it possible to have a ReadLine function in C# that takes a message as a parameter and waits for user input?PaulinusWongDec 01, 2024Copper Contributor10Views0likes0CommentsPregunta PdfViewer
Hola a todos Estoy trabajando con PdfViewer de Patagames para visualizar PDFs en un formulario WindowsForm. Tengo dos botones, uno para ajustar al ancho de página y otro para mostrar toda la página, pero no consigo implementar el código. ¿Podrían ayudarme? Gracias de antemano.JDamianOlivaNov 19, 2024Copper Contributor16Views0likes0CommentsWhy is System.Text.Rune named like this?
.NET uses UTF-16 for string encoding. This means: char type, which is atomic unit of string, is 16-bit size data type. that surrogate pairs are used forSupplementary code points,U+10000..U+10FFFF, while forBasic Multilingual Plane,U+0000..U+FFFFone char is sufficient to express any Unicode scalar value. .NET Rune comes in with ability to bypass surrogate pair problems, e.g. their unintended split. Thus by one variable all scalar values can be expressed. var a = new Rune('a'); var grinnigFace = new Rune ( '\uD83D', '\uDE00' ); There exist many terms related to string and char types: symbol, character, pictogram, emoji, grapheme, script, letter, mark, punctuation, accent, diacritics, emoticon, … .NET chose to use textual element as synonym for what is grapheme +/ cluster in Unicode. Unicode® Technical Standard #51 Note that all emoji sequences are single grapheme clusters: It is also not 100 % correct to use "grapheme". Grapheme In linguistics, a grapheme is the smallest functional unit of a writing system. While let saythis🧑🏿:christmas_tree: emoji is composed as sequence of: 1F9D1, 🧑, \Ud83e\Uddd1 1F3FF, 🏿, \Ud83c\Udfff 200D, , \U200d 1F384, :christmas_tree:, \Ud83c\Udf84 hardly can be any unit considered functional unit of writing system. DocumentThe Unicode® Standard: A Technical Introductionis more specific. For example, in historic Spanish language sorting, "ll"; counts as a single text element. However, when Spanish words are typed, "ll" is two separate text elements: "l" and "l". Text elements are encoded as sequences of one or more characters. Certain of these sequences are called combining character sequences, made up of a base letter and one or more combining marks, which are rendered around the base letter (above it, below it, etc.). For example, a sequence of "a" followed by a combining circumflex "^" would be rendered as "â". There can be seen some intersection between Unicode and .NET ontext/textual element. Nonetheless, rather opaque terminology reign is apparent. The Rune https://www.vocabulary.com/dictionary/rune A rune is a letter used in early Germanic writing. A linguist might be interested in runes because they're evidence of ancient languages, while a mystic might use runes, believed by some to have magical properties, in fortune-telling. https://www.thefreedictionary.com/rune 1a) Any of the characters in several alphabets used by ancient Germanic peoples from the 3rd to the 13th century. 1b) A similar character in another alphabet, sometimes believed to have magic powers. 2) A poem or incantation of mysterious significance, especially a magic charm. After deeper look,"rune"does not resemble any of terminology used by Unicode and seems to be tightly coupled with Germanic tribes' writing system. As far as I can see, Rune is nothing more then Unicode Scalar Value. It is not important whether UCP is expressed by 1:1 numeric relation, surrogate pairs or by series of doggies and cats. It could be said that .NET is about to contribute to terminologygoulash: Why Rune is not UnicodeScalarValueor something more technical accurate? I failed on finding any reference on why this name was chosen. Is there some specific reason? Or Rune is just fine as grapheme, glyph, symbol and others would be?PerceptiveFilamentOct 03, 2024Copper Contributor169Views0likes1CommentPossible to change method called inside foreach?
I have a created a function as below public static ICustomers[]? SanitiseCustomers(this string[]? custVals, float boxed = 0.5f) { List<ICustomers> customers = []; foreach (var c in custVals) { customers.Add(c.Sanitize(boxed)); } return [.. customers]; } I want to replace the Sanitize function within the foreach loop to a different method. I dont want to copy and paste the function and create a new one and changing Sanitize to FriendlyBox but trying to see if there is a way to switch the method name depending on the way this function is called?Pattison159Sep 24, 2024Copper Contributor145Views0likes0CommentsSimple Guide On Effective Use Of Parallel Programming For C# In A Managed Code Environment:
Parallel programming in C# uses a variation of Managed Threading, that relies on PLINQ, Expression Trees, The Barrier Class, Thread Class, BackgroundWorker Class, SpinWait Struct, SpinLock Struct, and Thread-Tracking Mode for SpinLock. The reason is that it's faster to use the environment to determine how many cores / threads are available, as to not starve the device of resources, which at that point, you have to use the BackgroundWorker Class to manage each task you've created. Often in this scenario, you can end up with a deadlock condition, because you have more than one task trying to access a shared resource. It's much easier and faster to split up each task, ONLY using byte arrays, assigning each task individual byte arrays to sort / parse, encrypted or not, with the Stream class, or a sub variation of that Class, and then when each task finishes, they all finish at different times, but the shared resource is divided up into portions, so that they will only be able to fill one area of that array. The reason why Barrier is used in this situation, is it forces each one to wait until all the tasks are finished, or until they all ARRIVE at the same place, which solves one timing issue, yet it might create another where there's a bit of a timing mismatch if your estimates are wrong, you overshoot or undershoot I mean. At the very end, you can use a separate process to just COPY from each individual array, without a deadlock scenario occurring. The only issue, is you have to estimate how many threads are available ahead of time, and you can't use every single thread, yet you're going to have to divide a single resource between all those threads. Beforehand, you have to verify if it's a waste of time to use more than one thread. The reason why I say this, is that a lot of people use reference types, not knowing they are immutable, and they take a huge / massive performance hit because of this. Often you have to convert strings into byte arrays, or use a pre-initialized character array at the start of the program, which contains the Unicode values that you want to recast individually as strings, and then use a byte array as an INDEX or a placeholder, of a Unicode character array. If you’re not encrypting the byte arrays, or using them for text parsing, which byte arrays tend to be best in high throughput scenarios, than integer arrays will suffice. The index can be scrambled based on how you want to represent that one string, though it's smarter to only cast a new reference type when you want to display text on the screen. If you spend too much time manually parsing using built-in libraries, it's REALLY SLOW. A byte array is better to use than an integer array in this sort of situation. You might have to create separate indexes with a byte array representing a set of binary flags, to determine whether each one is a letter, number, symbol, etc, or how you want to classify each one based on the code chart that you're using. You would be better off in that situation to just use right shift / left shift / XOR, etc, to set the flags. Then you have something which is also very fast, and almost equivalent to a Barrel Shifter, given C# does not allow you to use pointers, as it's managed code / a managed environment. All the Boolean Logical Operators with Compound Assignment rely on pre-initialized Cast Expressions of Integer Literals, Bitwise and Shift Operators, combined with Lambda Expressions, and Operator Overloading. The purpose of the Shift Operators is to mask / pad the bits of one byte value with zeroes, so that your Cast Expression Of An Integer Literal, which serves at the mask, always gives you a fixed / deterministic result, when used in conjunction with Boolean Logical Operators, especially if the value is smaller than 8-bits / a single byte, or you're dealing with a larger array has to represent a flag "register" with a size of ( 2 ^ 8 ) 256 bits, which is basically a Double-Word: "Microsoft Learn - Boolean logical operators - AND, OR, NOT, XOR - Compound assignment" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/boolean-logical-operators#compound-assignment" "Microsoft Learn - Bitwise and shift operators (C# reference)" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators" "Microsoft Learn - Operator overloading - predefined unary, arithmetic, equality and comparison operators" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/operator-overloading" "Microsoft Learn - Lambda expressions and anonymous functions" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions" "Microsoft Learn - Integral numeric types (C# reference) - Integer literals" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types#integer-literals" "Microsoft Learn - Type-testing operators and cast expressions - is, as, typeof and casts - Cast expression" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#cast-expression" "Microsoft Learn - Deserialization risks in use of BinaryFormatter and related types" -> "https://learn.microsoft.com/en-us/dotnet/standard/serialization/binaryformatter-security-guide" "Microsoft Learn - BinaryReader Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.io.binaryreader?view=netframework-4.0" "Microsoft Learn - Stream Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.io.stream?view=netframework-4.0" "Microsoft Learn - StreamWriter Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.io.streamwriter?view=netframework-4.0" "Microsoft Learn - StreamReader Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.io.streamreader?view=netframework-4.0" "Microsoft Learn - File and Stream I/O" -> "https://learn.microsoft.com/en-us/dotnet/standard/io/" "Microsoft Learn - Pipe Functions" -> "https://learn.microsoft.com/en-us/windows/win32/ipc/pipe-functions" "Microsoft Learn - System.IO.Pipes Namespace" -> "https://learn.microsoft.com/en-us/dotnet/api/system.io.pipes?view=netframework-4.0" "Microsoft Learn - Custom Partitioners for PLINQ and TPL" -> "https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/custom-partitioners-for-plinq-and-tpl" "Microsoft Learn - Expression Trees" -> "https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/expression-trees/" "Microsoft Learn - Build expression trees" -> "https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/expression-trees/expression-trees-building" "Microsoft Learn - Translate expression trees" -> "https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/expression-trees/expression-trees-translating" "Microsoft Learn - Execute expression trees" -> "https://learn.microsoft.com/en-us/dotnet/csharp/advanced-topics/expression-trees/expression-trees-execution" "Microsoft Learn - System.Windows.Threading Namespace" -> "https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading?view=netframework-4.0" "Microsoft Learn - System.Threading Namespace" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading?view=netframework-4.0" "Microsoft Learn - System.Threading.Channels Namespace" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels?view=netcore-3.0" "Microsoft Learn - System.Threading.Tasks Namespace" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks?view=netframework-4.0" "Microsoft Learn - Timer Class (System.Timers)" -> "https://learn.microsoft.com/en-us/dotnet/api/system.timers?view=netframework-4.0" "Microsoft Learn - Timer Class (System.Threading)" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.timer?view=netframework-4.0" "Microsoft Learn - DispatcherTimer Class (System.Windows.Threading)" -> "https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatchertimer?view=netframework-4.0" "Microsoft Learn - Dispatcher Class (System.Windows.Threading)" -> "https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatcher?view=netframework-4.0" "Microsoft Learn - Threads and threading" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/threads-and-threading" "Microsoft Learn - Using threads and threading" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/using-threads-and-threading" "Microsoft Learn - Introduction to PLINQ" -> "https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/introduction-to-plinq" "Microsoft Learn - Task Parallel Library (TPL)" -> "https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl" "Microsoft Learn - Lambda Expressions in PLINQ and TPL" -> "https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/lambda-expressions-in-plinq-and-tpl" "Microsoft Learn - Multithreading in Windows Forms Controls" -> "https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/multithreading-in-windows-forms-controls" "Microsoft Learn - Managed threading best practices" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices" "Microsoft Learn - Parallel programming in .NET: A guide to the documentation" -> "https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/" "Microsoft Learn - Thread Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread" "Microsoft Learn - BackgroundWorker Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker" "Microsoft Learn - Synchronizing data for multithreading" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/synchronizing-data-for-multithreading" "Microsoft Learn - Overview of synchronization primitives" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/overview-of-synchronization-primitives" "Microsoft Learn - Environment.ProcessorCount Property" -> "https://learn.microsoft.com/en-us/dotnet/api/system.environment.processorcount" "Microsoft Learn - Managed threading best practices - Number of Processors" -> "https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-1.1/1c9txz50(v=vs.71)#number-of-processors" "Microsoft Learn - lock statement - ensure exclusive access to a shared resource" -> "https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/lock" "Microsoft Learn - Reliability Best Practices" -> "https://learn.microsoft.com/en-us/dotnet/framework/performance/reliability-best-practices" "Microsoft Learn - BackgroundWorker Component Overview" -> "https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/backgroundworker-component-overview" "Microsoft Learn - How to: Run an Operation in the Background" -> "https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-run-an-operation-in-the-background" "Microsoft Learn - Thread-safe collections" -> "https://learn.microsoft.com/en-us/dotnet/standard/collections/thread-safe/" "Microsoft Learn - Threading objects and features" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/threading-objects-and-features" "Microsoft Learn - Barrier" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/barrier" "Microsoft Learn - Barrier Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.barrier?view=netframework-4.0" "Microsoft Learn - SpinWait" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/spinwait" "Microsoft Learn - SpinWait Struct" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.spinwait?view=netframework-4.0" "Microsoft Learn - SpinLock" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/spinlock" "Microsoft Learn - SpinLock Struct" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.spinlock?view=netframework-4.0" "Microsoft Learn - How to: use SpinLock for low-level synchronization" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/how-to-use-spinlock-for-low-level-synchronization" "Microsoft Learn - How to: Enable Thread-Tracking Mode in SpinLock" -> "https://learn.microsoft.com/en-us/dotnet/standard/threading/how-to-enable-thread-tracking-mode-in-spinlock" "Microsoft Learn - Chaining tasks using continuation tasks" -> "https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/chaining-tasks-by-using-continuation-tasks" "Microsoft Learn - Interlocked Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.interlocked?view=netframework-4.0" "Microsoft Learn - TaskFactory Class" -> "https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskfactory?view=netframework-4.0"MousefluffSep 17, 2024Iron Contributor224Views0likes1Comment- jaffarm183Sep 12, 2024Copper Contributor123Views0likes0Comments
The Importance of Finding the Right Bra Size
Finding the right goldies bra size is one of the most important things you can do when shopping for a new bra. If your bra does not fit you correctly, you’re not only going to be uncomfortable, but you’re also going to end up with unsightly lines, straps digging into your skin, and a bra that isn’t lifting you to your fullest potential. goldies bras reviews While this may not seem like a big deal when you’re just wearing the bra by itself, it becomes much more noticeable when you’re wearing a shirt or other top. If you’re trying to find your perfect bra size, be sure to take all of your measurements. This includes the circumference of your bust, the length of your torso, and your bra size. Keep in mind that bra sizes are not just measurements of the cups. There are other parts of the bra that need to be measured and checked to ensure the correct size.Donald589Aug 30, 2024Copper Contributor1.2KViews0likes2Comments