Author Archives: cincura.net

Seznam klávesových zkratek z mé přednášky “Visual Studio 2010/2012 tips and tricks” na Gopas TechEd 2013

Na letošním Gopas TechEdu jsem měl kromě standardních technických přednášek i jednu oddychovou, netechnickou. Konkrétně “Visual Studio 2010/2012 tips and tricks”. Což byl její pracovní název, ale probublal až na oficiální. No a tato přednáška neměla moc slajdů. Zato jsem prošel plno zajímavých – podle mě – klávesových zkratek, které ovládají běžné funkce Visual Studia (možná proto jsou již předdefinované). Prezentace z této, i ostatních, přednášek budou dostupné na oficiálním webu. Nicméně byla by škoda vás ochudit o všechny ty klávesové zkratky, které jsem prošel (nepředpokládám, že by si je někdo všechny zapisoval).

Původně jsem myslel, že je sem dám i s popisem. Aby to bylo úplně bez práce. Ale pak jsem si to rozmyslel. :) Dám sem pouze seznam a kdo chce, může vyzkoušet a zjistit co dělá. Většina z nich není destruktivní a funguje přímo v editoru. Ty pro debuggování jsou označené. Komentáře jsou případně otevřené (i proto, že některé věci byly “ukazovací” a nejsou o klávesové zkratce), kdyby se někdo chtěl zeptat. Rád vysvětlím.

Win-<number>
Win-Alt-<number>
Win-Shift-<number>
Ctrl-Alt-Down
Ctrl-dblclick
Ctrl-Q
Alt-Enter
Ctrl-.
Ctrl--
Ctrl-G
Alt-Shift-C
Ctrl-R-M
Ctrl-M-H/Ctrl-M-U
Ctrl-M-M
Ctrl-M-O
Ctrl-Space
Ctrl-Shift-Space
Ctrl
Ctrl-Alt-Space
Ctrl-Z
Ctrl-ů (Ctrl-;)
F7
Ctrl-, 
Ctrl-E-C/Ctrl-E-U
Ctrl-E-D
Tab
Ctrl-Up/Ctrl-Down
Alt
Ctrl-Shift-Up/Ctrl-Shift-Down
Ctrl-) (Ctrl-], Ctrl-})
Ctrl-Shift-) 
F8/Shift-F8
Ctrl-C
Ctrl-X
Ctrl-Shift-L
Ctrl-Shift-V
Ctrl-K-X
Tab-Tab
Ctrl-K-S
Ctrl-F, F3, Ctrl-H, Ctrl-I/Ctrl-Shift-I

Debugging:

F10, F11, Shift-F11, Shift-F5  
Ctrl-F10
Ctrl-Shift-F5
F9
Ctrl-S
Ctrl-Shift-F10
Shift-Alt-F11
>

MailAddress class is driving me crazy

I’m not working a lot with emails and email addresses. Loading, parsing and so on. Because of that I’m also using a MailAddress class a lot. And I hate it. The class, even simple, makes ma wanna scream.

Consider simple code like this.

var mail1 = new MailAddress("mail@example.com");
var mail2 = new MailAddress("MAIL@example.com");
Console.WriteLine("Equals?:\t{0}", mail1.Equals(mail2));
Console.WriteLine("Equals?:\t{0}", mail2.Equals(mail1));
Console.WriteLine("GetHashCode1:\t{0}", mail1.GetHashCode());
Console.WriteLine("GetHashCode2:\t{0}", mail2.GetHashCode());

What do you think the output be? Drum roll please…

Equals?:        True
Equals?:        True
GetHashCode1:   582340455
GetHashCode2:   1045083261

Why the hell somebody did the work overriding the Equals and not providing the implementation of GetHashCode that aligns with that?

I think it’s time to implement my own. 8-)

Gopas TechEd 2013

Rok se s rokem sešel a máme tu další ročník Gopas TechEd-u. Nejprve doporučuji prostudovat samozřejmě program, protože obsahu je opravdu mraky.

Nakonec doufám, že vás zaujmou i moje přednášky: Visual Studio 2010/2012 tips and tricks (st 10:30 – 11:45), Entity Framework verze 4, 5 a dál (6, …) – co máme, co nás čeká (a nemine) (st 14:15 – 15:30), Async/await – základy základů a chytáky (pá 9:00 – 10:15).

Budu se na vás těšit.

Hunting “EntityType ‘Image’ has no key defined. Define the key for this EntityType.” problem

Few weeks back I was hired to debug the above mentioned problem. The application was using Entity Framework 5 and Firebird as a database. The message says clearly what’s wrong. How hard can it be to fix the problem, right? I was thinking the same. And how wrong I was.

After receiving the sources and quickly extracting the bare metal with error I started looking for Image type. And there it was. The class had Id property, so the key was kind of there. The default convention should be able to find. Let’s look at configuration, if there’s something suspicious. And even better, the HasKey call is there. OK, maybe there’s some magic in OnModelCreating. Nope. Everything as expected.

By the way, the exact error was:

ModelValidationException: One or more validation errors were detected during model generation:

	System.Data.Entity.Edm.EdmEntityType: : EntityType 'Image' has no key defined. Define the key for this EntityType.
	System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Images' is based on type 'Image' that has no keys defined.

That’s the overview. Next two hours I was trying to changes something here and there and make it fail, so I knew it’s doing what it should do. Removing some stuff that might break something. And still no luck. But then something caught my eye. The error is talking about “Image” type. My type from database is “IMAGE” (the mapping and classes were generated by Entity Framework Power Tools and because of how SQL standard defines non-quoted names, it’s by default all uppercase). Yes, there was a property added to some entity that had a type Image, I mean System.Drawing.Image.

So quickly adding Ignore into OnModelCreating and I was done. Lesson learned.

Understanding (some) Firebird’s nbackup error messages (“Error (xxx) opening database file”)

Because on the server where the application is running I’m unable to do backup using regular gbak tool, I turned my attention to nbackup. In fact I’m doing just file copy and using alter database begin backup/alter database end backup (more info). But doing the backup is only part of the story. You have also know you know how to restore it and whether you can restore it (aka whether the backup is not corrupted).

If you have done backup using process described above and you have the file, you can’t just start using it. You need to “restore it”, which means changing a flag inside the database file. This is where the nbackup‘s -F switch comes to play. But no matter what I was doing, I was getting:

Failure: Error (5) opening database file: <some>.fdb

This error message is, well, completely utterly useless. While waiting for reply from firebird-support list I played with Process Monitor (of course) to see what’s wrong. But I haven’t seen any disk activity with errors. Changing paths, trying invalid paths (this produced just error 3), running 32bit version of nbackup, using one from Firebird 2.1, … And nothing. Then I decided to have a look into the ultimate documentation aka sources. It was not difficult to find piece of code:

b_error::raise(uSvc, "Error (%d) opening database file: %s", GetLastError(), dbname.c_str());

Great GetLastError. Time to jump into System Error Codes. And in no time I know it’s ERROR_ACCESS_DENIED. That’s a progress. Quick check of permissions and yes; the user I was running under had no permission to write to the file. Quickly changing that and everything was working fine.

Hope it helps somebody.

Entity Framework is open source, why not SqlClient?

If you’re watching at least a little what’s going on in .NET world you noticed that Entity Framework is open source for couple months now. That’s a good thing.

On the other had there are still some pieces of the complete stack that are not open source. The one that I’m missing most is SqlClient. I’m writing provider for Firebird and although the MSDN documentation contains a lot of content sometimes it’s not obvious how things should behave. Then the SqlClient‘s behavior is (at least by me) taken as de-facto standard. I think everybody expects behavior that adheres to it. Over the last few years I’ve spent maybe thousands of hours trying things with SqlClient and ILDASM-ing into internals. But it could be easier if you could just step into the code and see the behavior, variables, … Also other people might look at the code and instead of just reporting bug posting also related info where to find the proper implementation or how it differs internally.

I wish to go back to this post in the foreseeable future and happily strike-though the complete text and just say that SqlClient is open source too.