Skip to main content

177 posts tagged with "technology"

View All Tags

Validating XML Via Embedded XSD Schema

· 2 min read

Problem​

You have some XML, and you need to validate it against a custom schema that you want to deploy with your .Net 2.0 assemblies. Issues addressed: opening the file and handling the schema validation.

Solution​

The XmlSchema class contains a Read method that takes a stream as a parameter. Nicely matching up to that, you can open a stream from an embedded resource (dead link removed; SF 2025).So, embed the schema. In Visual Studio's Solution Explorer, right-click the schema file and choose properties. Change the Build Action to "Embedded Resource".

Viewing Embedded Images in HTML E-mail (Base64)

· One min read

Problem​

you have image data from an HTML e-mail, but don't know what to do

with it. When you save it to disk it comes out with a weird string instead of binary data.

Solution​

pretty simple, you just have to know the terms. This string of data is actually Base64 encoded, which means that the binary data has been converted to a text string for easy transmission over text protocols. .Net Developer's Journal (dead link removed; SF 2025) has a good full explanation. All you have to do is convert the string over to a byte array using Convert.FromBase64String, then save your new byte[].

NUnit Ignores App.Config

· One min read

Problem​

You want to run NUnit tests in a class library (dll). These test rely on an application configuration file (app.config) for some settings, i.e. custom appSettings or database connection strings. The code compiles and runs fine by itself, but your unit tests always fail. Attaching the Visual Studio debugger to NUnit and stepping through the code, you see that the config seems to be ignored.

Threading and Waiting with Delegates

· 3 min read

One of the casualties of not having a full computer science education is that I was barely exposed to threading. In my two Java classes we touched upon it, and wrote some basic examples in the second semester, but that could hardly be called extensive use. Thus, a number of years on, it has been a bit of a struggle for me to use threads in a practical manner. Further complicating the matter is that I've wanted to use anonymous methods (aka delegates) and generally want to do some work after all threads have finished executing.

Windows Keyboard Shortcuts

· One min read

I've always been a fan of keyboard shortcuts, using them whenever possible. Today I accidentally pressed the Windows key and D at the same time — and suddenly found that my whole desktop was revealed. How did I not know about this? A quick search led me to a great page with another 8-10 shortcuts I didn't previously know. Now you too can be enlightened about the many uses of the Windows key.

Passing Objects Does Not Require 'ref'

· One min read

I'm willing to admit that I made a mistake, and I share this now for your reference (no pun intended): in C#, your basic data types (int, string, short, bool) are value-types. If you want to pass them to a method and have the original value updated, instead of a copy, then you must pass them with the ref or out keywords. But not so with reference-types (hence the name!), which includes classes.

One gray area: what to do with structs. That last link says: "when a struct is passed to a method, a copy of the struct is passed, but when a class instance is passed, a reference is passed." So there you have it. Definitely pays to know the differences between C# and C++!

Do not trust the generic List!

· 3 min read

Actually, that's a slightly misleading title. You should trust List<T>, but you should also know its limitations. Here is one of the dangers of launching into using new functionality without reading all of the documentation. I've been having trouble because a client application produces thousands of reports. These reports are supposed to be sorted in a particular manner. I've been sorting and sorting in SQL, and going not paying enough attention to test well. Results in production? Not sorted.

So naturally I started properly stepping through the application, inspecting results from SQL and in code. What do I find? That SQL is returning the proper sort order, but then the ordering is getting lost. Why is that?

Performance #7: An (unsafe) Dead End

· 2 min read

This article is part of the series An Exercise in Performance Tuning in C#.Net.

After a month-long hiatus — too much work, too fast and furious for posting — I'm back to the last posts in the series on real-world performance tuning. The point of these postings hasn't been to glorify my ability to tune a C# data processing application, but rather to share what I've learned in attempts to do so.

Where to next? Turns out my next steps were false starts, at least insofar as tuning is concerned. Still, there were some lessons (or should be) from these dead ends.

safnet logo