Archive for the ‘.Net’ Category

all unit tests failing! debug won’t step in!

April 26, 2017

the sky is falling!

really, not being able to debug/step into is a shock to someone who uses visual studio day in / day out

what I had done yesterday to cause this was to change the copy local to “false” on the dll being tested.

that did it.

the exception message was “System.IO.FileNotFoundException: Could not load file or assembly”


webapi debugging fail? on simple GET?

March 15, 2017

the situation:
* web api 2
* simple project built from template – the Value controller works as expected

I added a controller … and I’m still learning. (aren’t we all)

I tried calling action methods from my controller … I won’t show my apiconfig, because it’s not relevant to my point.

My point is, I got to a situation where it appeared that the debugger would not step into my controller methods.

Or would it?

One thing I learned is that if I put [HttpGet] attribute tags on multiple methods in the controller, then the original “Get” method may not be called. After I removed those attributes, then the default Get method was again called.

a good read:

Telerik radGrid -ItemTemplate,EditTemplate

August 22, 2016


  • Browser side: Use normal controls – a lot like gridview (label, hidden, etc)
  • Server side a little different
  • Must grab control[1]. Control[0] is a literal – I suppose the start of the <td>.

Browser Side:

<telerik:GridTemplateColumn Display=”false” UniqueName=”ReceiptItemID”>


<asp:HiddenField ID=”hdnReceiptItemID” runat=”server” Value=”<%# Item.ParkedReceiptItemID %>” />



<asp:HiddenField ID=”hdnReceiptItemID” runat=”server” Value=”<%# Item.ParkedReceiptItemID %>” />




<telerik:GridTemplateColumn HeaderText=”AccountNumber” UniqueName=”AccountNumber” >


<asp:Label ID=”lblAccountNumber” runat=”server” Text='<%# Item.AccountNumber %>’ ></asp:Label>



<uc1:ctlCombo ID=”cboAccountNumber” ClientIDMode=”Static” runat=”server” Text='<%# Item.AccountNumber %>’ />




Server side:

//Get all the new values of the edited row.

GridEditableItem rgEditedItem = (GridEditableItem) e.Item;



// Label lbl = (Label) rgEditedItem[“ReceiptItemID”].Controls[1];

HiddenField hdn = (HiddenField)rgEditedItem[“ReceiptItemID”].Controls[1];


// int ReceiptItemID = lbl.Text.toInt(0);

int ReceiptItemID = hdn.Value.toInt(0);


// update account number if it changed

ctlCombo cbo = (ctlCombo)rgEditedItem[“AccountNumber”].Controls[1];

if (cbo.PreviousValue != cbo.Text && ReceiptItemID > 0)


int iret = _parkedReceiptItem.update_Account(ReceiptItemID, cbo.Text, globals.StaffID, ref iError, ref strErrorShort, ref strErrorLong);

if (iError < 0) globals.lblError = globals.ErrorMessage(strErrorShort, strErrorLong, “Problem with account”, “rgItems_UpdateCommand.account”, -2223);



Telerik radgrid inline editing command not firing

August 19, 2016

oops – my problem was old school .net

in my OnLoad, I was reloading and rebinding the radGrid

that blew away all events

shades of .Net 2003!


Mutex – single instance of program – VB – Winforms

February 19, 2015

Three ways to use mutexes to guarantee that your VB.Net winforms application only runs one instance at a time on a given host.
I don’t know why I redid this three times yesterday – I must have made some mistake that led me to believe that the first two tries weren’t working!

Public Class globals

Public Shared unique_mutex As Mutex

' flavor: TryOpenExisting
Public Shared Function guarantee_unique_instance_of_program() As String
Dim sMutexName As String = "Global\VcProcessPaymentsMutex"
Dim bAlreadyExisting As Boolean = False
Dim bFirstTimeCreated As Boolean = False


bAlreadyExisting = Mutex.TryOpenExisting(sMutexName, globals.unique_mutex)

Select Case bAlreadyExisting
Case True
Return "FAILURE Instance already running"
Case False
globals.unique_mutex = New Mutex(False, sMutexName, bFirstTimeCreated)
Return "SUCCESS"
End Select

End Function

' I think this is the ScottGu method (more or less)
Public Shared Function guarantee_unique_instance_of_program_GOOD3() As String
Dim bFirstTimeCreated As Boolean = False
globals.unique_mutex = New Mutex(False, "Global\VcProcessPaymentsMutex")
If (Not unique_mutex.WaitOne(0, False)) Then
Return "FAILURE Instance already running"
Return "SUCCESS"
End If
End Function

Public Shared Sub release_mutex()
End Sub

' this is the "FirstTimeCreated" flavor
' ALSO GOOD (why did I redo this yesterday?)
' flavor: TryOpenExisting
Public Shared Function guarantee_unique_instance_of_program_GOOD2() As String

'1) try to open one that is existing
Dim bTryToOpenExisting As Boolean = False
bTryToOpenExisting = Mutex.TryOpenExisting("Global\VcProcessPaymentsMutex", unique_mutex)
If (bTryToOpenExisting) Then
Return "FAILURE Instance already running"
End If

' 2) if it didn't exist yet, then create it
Dim bFirstTimeCreated As Boolean = False
Using unique_mutex As New Mutex(False, "Global\VcProcessPaymentsMutex", bFirstTimeCreated)

If (Not bFirstTimeCreated) Then ' this should never be hit
Return "FAILURE Instance already running"
End If

End Using

Return "SUCCESS"

End Function


mvc – feel my pain – view model is null on postback

January 17, 2015

I just spent two to three hours because I forgot to put get/set on the public members of my ViewModel.

The “etiology” (symptoms, bad behavior) was that my form posted back but the view model was always null.


public int logkey { get; set;}
public string logtitle { get; set;}
public string bywhom { get; set;}
public string slogdate { get; set;}
public DateTime logdate { get; set;}
public string logentry { get; set;}

I had been copying some working code, but not this part!

dynamically select StateServer based on machinename (for PROD,QA,DEV selection)

December 4, 2014

First go have a look at Maartens post.

My purpose – to use one line in web config, but use the correct stateserver ip address when deployed.
And I tested this to make sure it worked.

web config entry

VB version (I’m running)

Imports System

' purpose - dynamically return a state server ip address based on DEV/PROD/QA deployment
' ref
Public Class WebConfigSessionStateServer
Implements System.Web.IPartitionResolver

Private Shared m_DynamicStateServerAddress As String = ""
Private ReadOnly Property DynamicStateServerAddress As String
If (String.IsNullOrEmpty(m_DynamicStateServerAddress)) Then Initialize()

Return m_DynamicStateServerAddress
End Get
End Property

Public Function ResolvePartition(key As Object) As String Implements IPartitionResolver.ResolvePartition

Return DynamicStateServerAddress

End Function

Private Sub Initialize() Implements IPartitionResolver.Initialize
Dim sDEV As String = "tcpip=666.666.238.252:42424"
Dim sPROD As String = "tcpip=666.666.79.176:42424"
Dim sQA As String = "tcpip=666.666.238.249:42424"

Select Case DeploymentType
Case "QA"
m_DynamicStateServerAddress = sQA
Case "DEV"
m_DynamicStateServerAddress = sDEV
Case "PROD"
m_DynamicStateServerAddress = sPROD
Case Else
m_DynamicStateServerAddress = sPROD
End Select

End Sub

Private Shared m_DeploymentType As String = ""
Public Shared ReadOnly Property DeploymentType As String
If (m_DeploymentType = "") Then
Dim sname As String = Environment.MachineName 'utils_SysNetInfo.machinename
m_DeploymentType = "PROD"
If (sname.ToUpper().IndexOf("DEV") > -1) Then m_DeploymentType = "DEV"
If (sname.ToUpper().IndexOf("QA") > -1) Then m_DeploymentType = "QA"
End If

Return m_DeploymentType

End Get
End Property

End Class

C# version (translated by Telerik. Bless them. Buy things from them What a great service.)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace utils_lib

// purpose - dynamically return a state server ip address based on DEV/PROD/QA deployment
// ref
public class utils_SessionStateServer_Dynamic : System.Web.IPartitionResolver

private static string m_DynamicStateServerAddress = "";
private string DynamicStateServerAddress
if ((string.IsNullOrEmpty(m_DynamicStateServerAddress)))

return m_DynamicStateServerAddress;

// ************************************************************
public string ResolvePartition(object key)

return DynamicStateServerAddress;


// ************************************************************
public void Initialize()
string sDEV = "tcpip=666.666.238.252:42424";
string sPROD = "tcpip=666.666.79.176:42424";
string sQA = "tcpip=666.666.238.249:42424";

switch (DeploymentType)
case "QA":
m_DynamicStateServerAddress = sQA;
case "DEV":
m_DynamicStateServerAddress = sDEV;
case "PROD":
m_DynamicStateServerAddress = sPROD;
m_DynamicStateServerAddress = sPROD;


// ************************************************************
// use machine name to decide PROD DEV QA
private static string m_DeploymentType = "";
public static string DeploymentType
if ((string.IsNullOrEmpty(m_DeploymentType)))
string sname = Environment.MachineName;
m_DeploymentType = "PROD";
if ((sname.ToUpper().IndexOf("DEV") > -1))
m_DeploymentType = "DEV";
if ((sname.ToUpper().IndexOf("QA") > -1))
m_DeploymentType = "QA";

return m_DeploymentType;


} // class


//Service provided by Telerik (
//Conversion powered by NRefactory.
//Twitter: @telerik

stateless unit testing (when I wanted several to run together) … MemoryCache

July 15, 2014

Unit Testing – wow, I spent two days and the issue seems to have been just my misunderstanding of how stateless each unit test is.
I was trying to test a push and a pull from a local cache storage (instead of using web application cache, I switched to MemoryCache (.Net 4).

The problem was that I was saving in one test and trying to read in another test. And it’s an unfortunately long story, but when I finally just made one test method which saved and then read, it all worked.

I knew that I couldn’t count on tests being run in a certain order, but I was trying to run things by hand from Test Explorer. Sometimes it would work, but I just shot at least 12 hours trying to get something to work that I should have just spent 3 minutes on doing it the easy way.

oracle connection from visual studio 2012 problem

January 7, 2014

I’ve been connecting to three or four oracle databases off and on for about 5 years.

In a new project, I added a new entry to TNSNames and tried to connect to a new database, and I spent close to 12 hours trying to get it to work.

I may have had a problem with my tnsnames entry … but what seemed to do it finally was this:

Oracle looks for the tnsnames.ora file in the directory defined in the TNS_ADMIN environment variable – If you are running as different users, then maybe the TNS_ADMIN environment variable is not set, and therefore it cannot find the file?

could we live without stack overflow?

also, in the process I made sure to install the ODAC stuff downloaded from

But the fact that visual studio server and also my programs could connect to other oracle databases also defined in the same tnsnames.ora file is something I may not ever understand.

generic list in vb

December 18, 2013

here’s a good link for reference:
and I also used:

1) we have a generic list: Private Shared m_ListLDAP As List(Of PersonPermission)

2) the class
Public Class PersonPermission
Public netid As String
Public campus As String
Public usertype As String

Public Sub New(snetid As String, slocation As String, stype As String)
netid = snetid
campus = slocation
usertype = stype
End Sub

Public Sub New()
End Sub

End Class

3) we load the list from a datatable
4) then later in the code, we find an element in the list based on the user netid, and return some values. Frankly, I don’t understand the syntax. To me, it looks like LINQ, but I guess the Find function of the generic list is calling my little inline delegate function … or something like that.

' ******************************************************************************************************************
' purpose - search the list on netid, return campus and usertype
Public Shared Sub get_ldap_override_values(ByVal netid As String, ByRef campus As String, ByRef usertype As String)

If (IsNothing(m_ListLDAP)) Then load_user_list()
campus = ""
usertype = ""
Dim myLocatedObject As PersonPermission = m_ListLDAP.Find(Function(p) p.netid = netid)
If (Not IsNothing(myLocatedObject)) Then
campus = myLocatedObject.campus
usertype = myLocatedObject.usertype
End If
End Sub