DCSIMG
.NET - Miscellaneous Debris

Miscellaneous Debris

Thoughts and Snippets

Browse by Tags

All Tags » .NET (RSS)
Remote Debugging through fire, snow or fog
Remote Debugging in Visual Studio is a wonderful feature, especially during the later stages of testing and deployment, and even (if all else fails) when in production, but getting it to work is rarely smooth. Everything is fine if both the computer running VS and the one running the application are in the same domain, but when they aren’t, things start to break, fast. I So for those stuck debugging remote applications in different domains, here’s a quick guide to east the pain. On the the remote...
The Case of the Unexpected Expected Exception
“NUnit is being problematic again”, they told me when I came to visit the project. “When running unattended it’s not catching assertions properly and the test is coming up green, but when stepping through in the debugger, it works fine.”. It’s nice, when getting a passing test is acknowledged as a bad thing, at least when you don’t expect it to be. In this case, though, the fault wasn’t really with NUnit. 1: [Test] 2: [ExpectedException] 3: public void DoTheTest() 4: { 5: _myComponent.RunMethod(...
שלישיה חזקה
פיני דיין כותב בבלוג שלו על שני classים נידחים שמתחבאים להם ב-System.Web כדי לשמור צמדים ושלשות של אובייקטים: Pair ו- Triplet . אני חושב ששימוש באובייקטים הללו הוא רעיון רע, ועדיף שיקברו יחד עם ה-.NET Framework 1.0 שהוליד אותם. יש לי שתי סיבות: א) המחלקות הללו יושבות ב-System.Web.UI, שיושב תחת System.Web.dll. אם אני לא כותב מערכת Web, זה מיותר לחלוטין להוסיף Reference ל-System.Web רק בשבילהם. וזה גם בלי להזכיר שהם לא היו אמורים לשבת ב-Namespace הזה מלכתחילה – אין בהם שום קשר ל-UI. גם אין בקלאסים...
Upgrading all projects to .NET 3.5
A simple macro to change the Target Framework for a project from .NET 2.0 to .NET 3.5, hacked together in a few minutes. This will fail for C++/CLI projects, and possibly VB.NET projects (haven't checked). Works fine for regular C# projects, as well as web projects:   For Each proj As Project In DTE.Solution.Projects Try proj.Properties.Item( "TargetFramework" ).Value = 196613 Debug.Print( "Upgraded {0} to 3.5" , proj.Name) Catch ex As Exception Debug.Print( "Failed...
Any signs of life for the SharePoint Extensions for Visual Studio?
Has anything been released - or, in fact, talked about - since August's release of the v1.1 CTP ? Haven't done any web-part development in a while and wanted to get back in the game. I last used the v1.0 extensions, and was surprised that nothing much has changed in that field except for the CTP release, and even that can't be downloaded - I just get a broken link.
Seeking advice - strong names and config files
I'll use my blog for a bit of fishing for advice and guidance on an issue that's been bugging me. We've been moving towards using strong names on all of our assemblies. The benefits are obvious, and it's a must before we deploy to clients out in the wild. The problem is that we have several different processes running, each with its own app.config or web.config file. These config files contain references to custom configuration sections, whether they're application configuration...
System.Diagnostics.EventLogEntry and the non-equal Equals.
Just a quick heads-up in case you're stumped with this problem, or just passing by: The System.Diagnostics.EventLogEntry class implements the Equals method to check if two entries are identical, even if they're not the same instance. However, contrary to best practices, it does NOT overload the operator==, so these two bits of code will behave differently: EventLog myEventLog = new EventLog( "Application" ); EventLogEntry entry1 = myEventLog.Entries[0]; EventLogEntry entry2 = myEventLog...
Displaying live log file contents
I'm writing some benchmarking code, which involves a Console application calling a COM+ hosted process and measuring performance. I want to constantly display results on my active console, but since some of my code is running out-of-process, I can't really write directly to the console from all parts of the system. Not to mention the fact that I want it logged to a file as well. So I cobbled together a quick Log class that does two things - it writes to a shared log file, keeping no locks...
Dynamically creating a Sharepoint Web-Service proxy instance
In my current code, I find myself accessing many Sharepoint web services. In one run of code I can access 5-6 different web services on dozens of different sites, not necessarily even on the same server. Given that I find myself writing a lot of boilerplate code looking like this: using (SiteData siteDataWS = new SiteData()) { siteDataWS.Credentials = CredentialsCache.DefaultNetworkCredentials; siteDataWS.Url = currentSite.ToString() + "/_vti_bin/SiteData.asmx"; // Do something with the WS. } Seeing...
Wrong constructor called in COM+: sneaky, sneaky bug
Here's another nasty one that tried to bite me today. Let's say I have the following classes: public class COMPlusClass : ServicedComponent { public COMPlusClass() { // Default initialization. } public COMPlusClass (string data) { // Parameterized initialization. } } public class Client { public Client() { COMPlusClass cpc = new COMPlusClass("I am a client"); } } Which constructor do you think will be called? Naturally, I wouldn't ask if it was the second one. Much to my surprise, the first constructor...
Unmanaged deployment is a true DLL Hell
By a staggering margin, most of my problems integrating C++/CLI code into my C#-based project has been deployment problems. Without fail, every integration or test deployment will be plagued with inexplicable problems. I'll try to list a few, with their causes and (probable) solutions: 1) .NET assemblies are usually very loose in what they'll bind to. If I compiled A.DLL against B.DLL version 1.0.0.0, it will still work if it can only find B.DLL version 1.2.0.0. I don't have to rebuild and reversion...
More Tales from the Unmanaged Side - System.String -> char*
Today, I had a very tight deadline to achieve a very simple task: pass a managed .NET string to an API function that expects a null-terminated char*. Trivial, you would expect? Unfortunately it wasn't. My first though was to do the pinning trick that I mentioned in my last post, but in this case I needed my resulting char* to be null-terminated. Second thought was to go to the System.Runtime.InteropServices.Marshal class and see what it had for me. I found two contenders: 1) Marshal::StringToBSTR...
A C# coder in a C++/CLI world, part 1
Recently I've found myself stumbling around some C++/CLI code. C++ is a language which I learned years ago and never really worked with seriously, so I've been cursing and moaning as I worked. Strange for me to go back to a (partially) unmanaged environment now, with all sorts of assumptions that I have proven to be false. I'll try to go over some pitfalls and insights I'm having during the visit. This is the first: The Garbage Collector really spoiled me. I'm not talking about deleting what I instantiated...
Allowing timeout on long-running operations - possible bug
A while ago, I wrote about a simple pattern to allow us to put a timeout limitation on a long running operations. Simply put, it allows us to replace this: public MyObject GetData() { try { MyObject data = BigComponent.LongRunningOperation(); return data; } catch (Exception ex) { // Log and rethrow. throw; } } with this: public MyObject GetData() { try { MyObject data; Thread t = new Thread( delegate() { data = BigComponent.LongRunningOperation(); }); t.Start(); bool success = t.Join(timeoutForOperation...
Some more glaring omissions in the Sharepoint 2007 SDK and Web Services
I downloaded the new Sharepoint 2007 SDK today, published last week though it's dated from April 2007. There appears to be no change history for this version of the SDK. I was hoping for more information on new Web Service methods available in 2007 - hoping that the lack of 2007-specific functionality was more of a documentation error than an actual oversight. It seems this is not the case. I've written about the lack of item-level permissions in the WSSv3 web services before, but I've...
More Posts Next page »