Xamarin build error : No valid iPhone code signing keys found in keychain

if getting the error “No valid iPhone code signing keys found in keychain” when building your Xamarin IOS project, check that you are building against an ios simulator.

Visual Studio defaults to Device as a build target when creating a new project so this could be what is causing your error.

visual studio set to Device build target

Change to a simulator instead and try again.

Build target set to a simulator

If you do intend to deploy to a Device though, then the error is telling you that you haven’t set up a Device properly.

In order to do that you have to sign up to the Apple developer programme and follow the instructions.

Calling a method within a Linq-To-Entities or Linq-To-Sql query

You may puzzled at why you cannot something as simple as this when working with Linq-To-Sql or Linq-To-Entities:

public void Spike()
{ customers.Where(c => IsRegistered(c)); }

public bool IsRegistered(Customer customer) { return customer.IsRegistered == true; }

Obviously for this to be of any use you’d need a reason for needing to centralize that logic for reuse, otherwise it’s pointless and you might as well code it inline your linq query.

What’s surprising is that this actually doesn’t work. You will get a System.NotSupportedException. What the hell? a boolean method is not supported? what’s this playing at?

well, the key is in the premise. You are not dealing with Linq-To-Objects, you are dealing with Linq-To-Sql or Linq-To-Entities or any Linq-To-Anything-Which-Is-A-Data-Store supported by IQueryable. You are connecting to an underlying data source not just filtering on an IEnumerable in-memory collection of objections.

Anything that goes in IQueryable is actually treated as what’s called an Expression which is code that is parsed and translated into SQL statements. So from that perspective, indeed, IsRegistered(Customer customer) means nothing to the SQL translator. what can it do with that? it doesn’t map to any SQL syntax it knows. Yes, it could always look inside and parse code recursively, however, that’s not how the engine works and if that happened you’d most likely notice a big degradation in performance rapidly since it’d have to compile and execute code until it found what it actually just needed to translate. who knows, maybe in the future, but not for now.

So if you are really inclined in centralizing that logic, what do you do then? Easy, just get rid of the IsRegistered method and implement your logic as an Expression instead, like this:

Expression<Func<Customer,bool>> IsRegistered = c => c.IsRegistered == true;

Obviously like said before you can stuff as much logic as you want inside that expression.

then you use it like this:

public void Spike()
{ customers.Where(IsRegistered); }

nifty, eh?

Word of caution, before you celebrate too much: you cannot add anything else to the Where statement now by using && or ||. the reason for this is a whole new other post though. This gives a good insight into it if you wanna delve that deep : http://tomasp.net/articles/dynamic-linq-queries.aspx

ModalPopUpExtender – Multiple controls And One Modal

Although the idea behind the modalpopupextender is a very good one, unfortunately this control’s usage is not as straight-forward as its designers would’ve hoped. Whilst in most cases it is true that you can just drop the extender on the page and set its declarative properties to point to the right panel and button triggers, in the more complex cases, such as when the extender inside a GridView, you have to apply some workarounds.

Apparently the ability of setting multiple targets for the modalpopupextender existed at one point in time in one of the beta Atlas releases, however, the team deemed it too complex and didn’t include it in the final release when it became ASP.Net Ajax. So how to work around it?

There are a couple of ways to do this, but the solution is forcibly the same: you gotta use javascript.

What I do is set the modalpopupextender to one of the controls and then any other controls that need to use the same modal I add some javascript to the OnClientClick property which finds the extender control and calls the show() method on it.

<asp:LinkButton
runat=”LinkButton1″
runat=”server”></asp:LinkButton>

<asp:LinkButton
runat=”LinkButton2″
runat=”server”
OnClientClick=”$find(‘DisplayPurchaseInfoModalPopupExtender’).show();return false;”></asp:LinkButton><cc1:ModalPopupExtender
ID=”ModalPopupExtender1″
runat=”server”

TargetControlID=” LinkButton1″
PopupControlID=”PanelModalWindow”></cc1:ModalPopupExtender>

 

If the modalpopupextender control is inside a template in a GridView, you will have to do this in the DataBound event, since otherwise you won’t be able to find out the real name of the extender control.

So, when using a GridView you’d set the OnClientClick property of whatever controls that are going to use the modalpopupextender by doing something like this:

LinkButton linkButton2 = (LinkButton) e.Item.FindControl(“LinkButton2”);
linkButton2.OnClientClick = string.Format(“$find(‘{0}’).show();return false; e.Item.FindControl(“DisplayPurchaseInfoModalPopupExtender”).ClientID);

Error “The row doesn’t belong to the same DataSet as this relation.” when using DataRelation

If you get this error while trying to use DataRelation objects and calling GetChildRows on any given row it is most likely due to the fact that you have not added the DataRelation you created to the DataSet by calling the Add method of the DataSet like so:

C#
DataSet dt = new DataSet();
DataRelation dr = new DataRelation(“test”,dt.Tables[0].Columns[0],dt.Tables[1].Columns[1]);

//now this is probably what you forgot to do
dt.Relations.Add(dr);

Lost Intelllisense in web.config in Visual Studio

If you lost your intellisense in Visual Studio in the web.config file, it is probably because your configuration element, right at the top of the web.config file, has a xmlns attribute, like this:

To restore the Intellisense just delete the namespace declaration so that the configuration element has no attributes, like so:

That namespace declaration can be added by the Web Configuration tool, for example, or any other tool, or developer that might have meddled with the xml on the file.

DAL – SqlHelper.FillDataset() bug

Those of you using the Microsoft.ApplicationBlocks classes for your DAL might already have noticed (or not! which is the point of blogging about this) that the SqlHelper.FillDataset() method has many overloads some of which take a string array, supposedly to be used to automatically name the DataTables on the dataset for multiple recordsets returned.

While this seems handy in theory, it doesn’t actually work cuz the method’s got a bug. No matter how many strings you put into the array, the method will only name the first two tables accoding to what you have entered. After that it will name them as “Table” plus their index on the tables collection.

so, if you have 4 resultsets being returned and you pass in the following array for the tablenames arguments:

new string[] tablenames { “Red”, “Green”, “Blue”, “Yellow”, “Black” }

the tables on the dataset will actually be named : “Red”, “Green”, “Table2”, “Table3” and “Table4”

To get around this, I reccomend looping through the dataset right after the fill so everything is still isolated on the DAL, after all, this is the DAL’s job and it should’ve been done in first place anyway if it wasn’t for Microsoft releasing it with a bug.

so what I do first is set up an array with all the table names . Then right after the fill loop through the tables collection and set every table to their right name.

C#
string[] tablenames { “Red”, “Green”, “Blue”, “Yellow”, “Black” };
for (int i=0;i < dt.Tables.Count; i++) { dt.Tables[i] = tablenames[i]; } 

You might then wonder what to do with the tablenames argument in FillDataset(). Well, you can do whatever you want since it won’t matter, however, just for clarity, I like to make it as if it actually work and properly pass in the same tablenames colletion I use to rename the tables and add a comment flagging the bug.

Compiling VB and C# in ASP.Net 2.0

Anyone who ever had to integrate both C# and Vb.Net code in ASP.Net 1.0/1.1 knows how awkward and time-comsuming it could get sometimes. As much as I love the command prompt and  vbc and csc, it was never much fun guessing in which dll each control was defined.

No worries though for those days are gone! ASP.Net 2.0 makes it really easy to work with mixed code.

The only limitation of working with mixed code is that the files cannot be thrown together on the App_Code folder. You have to separate them into different folders. I think this is actually a good thing cuz it encourages good organization practices.

So, in your App_Code folder, create one folder called C# and another called VB (you can name it anything you want actually). Now, put all code files in their respective folder according to the language you used to program them.

Now all you have left to do is open your Web.Config file (or create one at the root of your web app if you don’t have one in your project yet) and do some (very simple) XML editing.

If you let Visual Studio create your Web.Config root file for you then you should already have a section. If not you’ll need to create one. This is where you can specify folders that need to be compiled separately. You don’t even need to specify the language to use for different folders, the compiler is smart enough to figure it out himself. So, all you need is to use the <codesubdirectories> element and add entries for the VB and the C# folders like this:

 

<compilation>
<codesubdirectories>
<add directoryname=”VB”>
<add directoryname=”C#”>
</codesubdirectories>
</compilation>

Note that the default Web.Config created by Visual Studio already contains a compilation section so just need to change it. Also it probably has an attribute in the compilation element of debug=”true” which is irrelevant here and that’s why it wasn’t included in the code above.

Oh and don’t forget that in ASP.Net you can always have as many Vb.Net and C# web forms as you fancy all mixed in without needing to do a thing.

Now that is a big step towards .Net’s self-imposed objective of language independance!