Next generation's garbage RSS 2.0
# Friday, November 13, 2009
There appears to be a bug in how Visual Studio does "Add Service Reference" proxy generation for VB.NET projects.

I ran into this issue when trying to add a service reference to Bing Maps and I believe it is not limited to that. I think it stems from it misunderstanding that enum instance variables cannot be tested for equality using .Equals in VB... not sure why.

I think the solution is to simply replace the offending line:
If Me.enumfield.Equals(value) <> true Then
with
If Not Object.Equals(Me.enumfield ,Value) Then

BTW: DO NOT compare boolean results to True or False as they have done!

Use
If boolean_results Then
or
If Not boolean_results Then
[EDIT 2010-07-07]
Specifically, this block of code is wrong:
<System.Runtime.Serialization.DataMemberAttribute()>  _
Public Property CompareOperator() As SearchService.CompareOperator
Get
Return Me.CompareOperatorField
End Get
Set
If (Me.CompareOperatorField.Equals(value) <> true) Then
Me.CompareOperatorField = value
Me.RaisePropertyChanged("CompareOperator")
End If
End Set
End Property
and should be replaced with this:
<System.Runtime.Serialization.DataMemberAttribute()>  _
Public Property CompareOperator() As SearchService.CompareOperator
Get
Return Me.CompareOperatorField
End Get
Set
If Not Object.Equals(Me.CompareOperatorField,value) Then
Me.CompareOperatorField = value
Me.RaisePropertyChanged("CompareOperator")
End If
End Set
End Property
Made this edit so search engines would pick it up... so I can find my own fix next time I run into it. :) [/EDIT]

Friday, November 13, 2009 4:41:25 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET Internals | Bing Maps | Visual Studio
# Monday, October 19, 2009
I'm actually going to encourage you to consider using GC methods. Well, now hang on cowboys... this is for pretty limited circumstances.

You see, the GC class can do more than compact memory. It can also run finalizers on unreferenced objects. If you are writing a class that included a finalizer (which you would only need if your class is the lowest-level class to deal with an unmanaged resource or are managing a pool of scarce resources) then you might consider using GC. Even though you might (read should) implement IDisposable, if a user of your library fails to Dispose your object, that unmanaged resource will leak until, at some non-deterministic (read random) point, the garbage collector runs and that object's finalizer might (read random) be queued and run. If it leaks often enough, your attempt to create additional objects with the unmanaged resource could fail because you have exhausted the available supply.

Rather than fail, you could attempt:

 GC.Collect(0);
 GC.WaitForPendingFinalizers();

and try again. If it works on the retry, you might want to log that for the developer's information. One might argue that this is just encouraging and forgiving sloppiness, but I look at it as a step towards robustness and can actually help the developer diagnose a real problem whereas not doing this would just lead to more random run-time only-on-heavy-load failures.

If you wanted to be really awesome, once you detect that you could recover, flip a bit on to start recording a stacktrace on each create, then in your finalizer, put that stacktrace in a application-wide queue that then gets logged by the next create. Now you've told the dev exactly where to go find the spot where they got your object but didn't dispose it.

Another place is when you are calling something that has an unmanaged resource behind it along with other code that isn't behaving. For example, you are writing a web part in SharePoint that is calling new SPSite and OpenWeb... perhaps you are being a good SPRequest citizen, but another web part on the site that you didn't write isn't being so nice.

You could make auto-recovery wrappers for the stuff you use. Your newSPSite method would attempt to return new SPSite but if that should fail, Collect + WFPF and try again. Ugh, what a pain. But sometimes it beats trying to explain to someone why it is another webpart's fault that your webpart explodes.

Monday, October 19, 2009 9:40:14 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET Internals
# Saturday, October 17, 2009
Disclaimer: I'm a Ruby-n00b and just trying merb.

Did you get this after trying to
gem install merb
?

...
Successfully installed merb-1.0.12
44 gems installed
Installing ri documentation for diff-lcs-1.1.2...
Installing ri documentation for rspec-1.2.9...
Installing ri documentation for addressable-2.0.2...
Installing ri documentation for data_objects-0.9.12...
Installing ri documentation for dm-core-0.9.11...
Installing ri documentation for dm-migrations-0.9.11...
Installing ri documentation for json_pure-1.1.9...
Installing ri documentation for mime-types-1.16...
Installing ri documentation for thor-0.11.7...
Installing ri documentation for merb-core-1.0.12...
Installing ri documentation for merb_datamapper-1.0.12...
Installing ri documentation for ZenTest-4.1.4...
Installing ri documentation for RubyInline-3.8.3...
Installing ri documentation for ParseTree-3.0.4...
Installing ri documentation for merb-action-args-1.0.12...
Installing ri documentation for merb-assets-1.0.12...
Installing ri documentation for merb-slices-1.0.12...
ERROR:  While executing gem ... (Errno::EINVAL)
    Invalid argument - ./</cdesc-<.yaml

Not sure why that is, but it won't stop merb from working. I went ahead a made a for loop to install the other gems again so they'd get their ri documentation.

for %x in (merb-auth-more merb-auth-slice-password merb-auth merb-cache merb-exceptions highline templater merb-gen haml merb-haml merb-helpers mailfactory merb-mailer merb-param-protection merb-more do_sqlite3 dm-timestamps dm-types dm-aggregates dm-validations randexp dm-sweatshop dm-serializer) do gem install %x

Here's what comes from gem install merb-slices -V --debug

ERROR:  While executing gem ... (Errno::EINVAL)
    Invalid argument - ./</cdesc-<.yaml
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/ri/writer.rb:41:in `initialize'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/ri/writer.rb:41:in `open'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/ri/writer.rb:41:in `add_class'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/generator/ri.rb:226:in `update_or_replace'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/generator/ri.rb:89:in `generate_class_info'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/generator/ri.rb:44:in `process_class'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/generator/ri.rb:39:in `generate'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/generator/ri.rb:38:in `each'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/generator/ri.rb:38:in `generate'
        C:/ruby/lib/ruby/gems/1.8/gems/rdoc-2.4.3/lib/rdoc/rdoc.rb:324:in `document'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb:177:in `run_rdoc'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb:149:in `install_ri'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb:109:in `generate_ri'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:144:in `execute'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:143:in `each'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:143:in `execute'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/command.rb:257:in `invoke'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:132:in `process_args'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:102:in `run'
        C:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:in `run'
        C:/Ruby/bin/gem:21

Saturday, October 17, 2009 11:35:46 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
merb | ruby
# Monday, October 05, 2009
Got the BlackBerry VS9 Plugin running in Visual Studio 2008 running in Windows 7 x64.
Not sure what of these steps are really necessary, but this is what I did:

Copied "Research In Motion" directory from "Program Files (x86)" to "Program Files". This gave me a different error.

Discovered using SysInternal's ProcMon that it was trying to launch RIM.Net.Tools.ScriptHost.exe from the root, so I copied that and all the other stuff in the plugin's bin folder to the root, yes, C:\.

That gave me another error, so then I set VS2008 to run in XP SP3 compatibility mode.

Tada!

Monday, October 05, 2009 3:09:27 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
Visual Studio | Windows 7
# Friday, September 04, 2009

Today I was doing some LINQ to objects. I was replacing a pair of nested foreach loops which built a string list and was looking for an elegant way to do it in LINQ. I ran into the problem that I needed to convert a list of lists to a single list. The following extension method works great for that. Works great for merging arrays of arrays without copying anything.

public static class ExtensionMethods
{
    public static IEnumerable<T> UnionAll<T>(this IEnumerable<IEnumerable<T>> eet)
    {
        foreach (var et in eet)
            foreach (var t in et)
                yield return t;
    }
}

Friday, September 04, 2009 4:16:24 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
LINQ
# Monday, August 10, 2009
I mentioned previously that I upgraded the hard drives in my and my wife's Sony VAIO VGN A-190 laptops to WD2500BEVE. Well, mine just died. FAIL! Less than 8 months. Not sure yet the failure mode, but I can read stuff without any reported error, but a lot of stuff appears to be corrupt (by archive testing). Also SpinRite reads along for a while and then stops with some sort of error screen. This is the fifth time I've tried to use this software with zero results. FAIL! I've taken the drive out (look [here] for disassembly instructions with pictures - I need to add pictures for HDD removal), hooked it up to another machine and copied off what I could. Warranties for WDC drives are usually 3yrs, so I'm sending it in to be replaced. I wish I could pay a bit extra to get the new WD3200BEVE which, to my amazement, is now the new capacity king in the PATA 9.5mm laptop drive kingdom -- I didn't expect any manufacturer would continue to develop new hardware for this interface. My really big complaint is with Windows security. When attaching a foreign drive the security prevents you from reading many directories, but, of course, this is a twist-tie security measure because you can simply take ownership and grant yourself rights to these directories, but this means writing to the drive -- FAIL -- a big no-no on a failing drive. I did it anyway, and I recovered what I needed to recover and I'm running again on my old stock 80GB drive, but I think the world needs a solution to this problem, so I intend to figure it out. I'll follow up when I find it.

Monday, August 10, 2009 10:21:09 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
Hardware | Security
# Thursday, July 23, 2009

Take your application's 512x512 icon and make a copy in your ad-hoc's build folder called iTunesArtwork (no extension).

#!/bin/bash
rm -r Payload
mkdir Payload
cp -rp myapp.app Payload
rm myapp.zip
zip -r myapp.zip Payload iTunesArtwork
rm -r Payload
rm myapp.ipa
mv myapp.zip myapp.ipa
Thursday, July 23, 2009 8:11:07 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
iphone
# Monday, June 01, 2009
I'm kinda surprised I haven't run into this situation before. I need to execute two web requests in series (because the second call depended on information from the first) against an array of values. Naturally, I wanted the array to perform in parallel, but how to get the second call to either execute automatically after the first call is done or force execution if requested before the second call is made.

Here's the pattern I came up with:
    Public Class TwoPartRequest
        Private req1, req2 As HttpWebRequest
        Private res1, res2 As IAsyncResult
        Private run1, run2 As Integer
        Private coolResult As CoolObject

        Public Sub New(ByVal url As String)
            req1 = WebRequest.Create(url)
            req1 = req1.BeginGetResponse(AddressOf Part1Complete, Nothing)
        End Sub

        Private Sub Part1Complete(ByVal ar As IAsyncResult)
            If System.Threading.Interlocked.Increment(run1) = 1 Then
                Using resp As HttpWebResponse = req1.EndGetResponse(ar)
                    Dim url As String = FigureOutNextUrlUsingResponse(resp)
                    req2 = WebRequest.Create(url)
                    res1 = req2.BeginGetResponse(AddressOf Part2Complete, Nothing)
                End Using
            End If
        End Sub

        Private Sub Part2Complete(ByVal ar As IAsyncResult)
            If System.Threading.Interlocked.Increment(run2) = 1 Then
                Using resp As HttpWebResponse = req2.EndGetResponse(ar)
                    coolResult = BuildResultUsingResponse(resp)
                End Using
            End If
        End Sub

        Public Function Result() As CoolObject
            Part1Complete(res1)
            Part2Complete(res2)
            Return coolResult
        End Function
    End Class
To use this, I have a list of these objects that I new up in a loop. In a second loop, I get all the results. If the target server can process requests in parallel well the number of iterations on the loop shouldn't matter.

Clearly, one could generalize the heck out of this, but I happy with it working.

Monday, June 01, 2009 5:10:03 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -

Archive
<November 2009>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
All Content © 2010, Hafthor Stefansson - Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. - Sign In