How to ignore whitespace formatting in merge conflicts in TFS in Visual Studio 2010.
Posted by Brian Seekford in C# on December 2, 2011
Hate when you see all Blue because someone reformatted the code?
Fix it.
In Visual Studio, select Tools / Options / Source Control / Visual Studio Team Foundation System and click the Configure User Tools button.
In the dialog, Add an item with the following settings.
- Extension : .*
- Operation : Compare
- Command : C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
- Arguments : %1 %2 %6 %7 %5 /ignorespace
If you are 64 bit,
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe
Happy Coding!
How do I cancel a databinding property set in WPF?
Posted by Brian Seekford in WPF on November 30, 2011
I have a combobox in WPF that I am using the SelectedItem property with a DataBinding and sometimes certain items shouldn’t be selected based on certain criteria. Mine was that two comboboxes couldn’t have the same value.
Yes, there are other ways, such as removing invalid values from other boxes, but here was my solution for preventing the invalid property set by cancelling the selection/property set.
WPF sucks in this manner as there isn’t an easy way to update it. You can’t raise the property updated event since the binding ignores those when setting, to avoid recursion issue I suppose. (Yes, developers could defend by not raising the events if the property doesn’t change)
Anyway, the solution is simply to raise the property changed after the operation, by simply posting it to the work queue on the UI thread right afterward.
Code: in C#
public MyHeaderType SelectedHeader
{
get { return this.selectedHeader; }
set
{
bool resetMe= validateValue(value);
var origVal = selectedHeader;//store for reset
selectedHeader = value;
RaisePropertyChanged(() => SelectedHeader);
if (resetMe)//Why do I need to set the value above? No idea. Doesn’t work unless I do it that way. Yes. I tried.
{
Application.Current.Dispatcher.BeginInvoke( //force a reenter to put it back……
new Action(() =>
{
SelectedHeader = origVal;//put me back to the correct value.
}),
DispatcherPriority.ContextIdle,
null
);
}
}
}
Happy Coding!
Free RedBox DVD rental coupon. Enjoy
Posted by Brian Seekford in Personal on November 4, 2011
Here is a free RedBox DVD rental coupon for you to use by ordering one online. Makes it easy to order it and pick up.
Regards,
Brian
“Unable to load one or more of the requested types.” when using EntityDataSource with Entity Framework in ASP.NET
Posted by Brian Seekford in .NET Development on August 1, 2011
I always love pushing something out that fails miserably and randomly. Especially when using straight Microsoft technologies. It seems these folks don’t eat their own dog food, or we wouldn’t encounter this crap.
Anyway, it took quite a while to figure out the resolution to this issue, but it all lies in the fact that their control is “trying” to be intelligent, and really only needed a little direction.
Let me explain, when the EntityDataSource loads, it looks for the Context. Where may you ask? Well, it actually uses reflection and attempts to load all types from the assembly to resolve the entities. If there is any error in this at all, it blows up. There are a number of reasons this can fail. Dependency mismatches, bad references, and other things that may not break your application but break this feature.
How can I fix this? I am sure you are asking this right now. “Damn it Brian, Get to the freaking point and the fix!” Fine.
It’s pretty simple.
Set this property on the EntityDataSource in your .aspx file. ContextTypeName .
The value? Well, the full namespace and class of your context. Example. Seekford.Data.MyEntityContext
More detailed example:
<asp:EntityDataSource … ContextTypeName="Seekford.Data.MyEntityContext" />
Happy coding!
A new guard page for the stack cannot be created
Posted by Brian Seekford in .NET Development on July 27, 2011
You get a nice error that says, “A new guard page for the stack cannot be created”, well easy fix. I could be long winded, but the issue is simply this, you caused a stack overflow.
How you say? Well, check to see if you are using a Server.Transfer that transfers you to a page that then Transfers you back and forth, or even to yourself.
Have login code that checks to see if you are logged in? If not, then it bounces you to a login page. Maybe you put it in a master page. Well, if the login page uses the master page, it will just keep transferring itself to itself and you blow the stack.
Response.Redirect will give you a different error as the browser only jumps a low number of redirects before giving up. Server.Transfer uses the internal stack, so it blows up on the server itself.
Happy coding!
Updated my WCF Data Contract but client doesn’t receive the property values….
Posted by Brian Seekford in .NET Development on July 15, 2011
I spent about ten minutes wondering why I wasn’t getting the data I expected from my WCF service. I had just changed my data contract to have one more property/field and the data wasn’t being received by my client application. The client is in javascript, so it’s happy with whatever it receives. So no errors there, just an undefined property.
I looked at fiddler and noticed it didn’t come through there either. Now I chalked it up to a stale build and rebuilt again. Hmm…. Still undefined…wtf?
Well, simple issue with a simple fix. It turns out I , DUH, forget to tag the property as a DataMember. So the serializer ignored it thinking it was just an internal variable. No need to serialize or expose. Geez.
My fault but it was pretty funny when I started going back through my entities and contracts and started comparing them.
So, in short, if your client for your WCF service is not receiving the property you expect on the data contract, make sure you marked them properly. Easy to overlook when you are updating the DAL DTO’s, Business Entities, and then your Contract Entity.
Example:
/// <summary>
/// Gets or sets the reference.
/// </summary>
/// <value>
/// The reference.
/// </value>
[DataMember(Name= "Reference")]
public string Reference { get; set; }
Happy coding!
HRESULT: 0×80131515 when running installutil to install a .NET Service
Posted by Brian Seekford in .NET Development on July 13, 2011
So you write your nice and fancy service and are all excited to distribute it to your client. You don’t feel like creating an installer for it, that seems like overkill. You just send a zip file with a batch file that calls installutil to register the service. Easy right?
Well, your client calls and complains that get the following error when running installutil aka your batch file:
Exception occurred while initializing the installation:
System.IO.FileLoadException: Could not load file or assembly ‘file:///D:\services\myservicehost.exe’ or one of its dependencies. Operation is not support. (Exception from HRESULT: 0×80131515).
I am sure you will start scratching your head and immediately blame them missing a dll or maybe the client ran it wrong. Maybe they have it in the wrong directory? Seems feasible, right? Wrong.
It turns out that Windows was protecting them. Windows doesn’t like files from other computers very much, especially not executables. They get a special stay away from me flag.
So, how do I fix this? Easy. Just open the properties dialog on the exe/service you extracted and hit the UNBLOCK button. Now installutil will work great!
Happy Coding!
How To Fix:Error 39 The type or namespace name ‘Contracts’ does not exist in the namespace ‘XXX’ (are you missing an assembly reference?)
Posted by Brian Seekford in .NET Development, C# on June 6, 2011
So….Just got done mentally disintegrating my computer and various items around it. This lovely error kept appearing to tell me ABSOLUTELY NOTHING.
I checked my references, of course they were included. It’s how I had intellisense, and every other feature that leads me to believe everything is A OK. That is, until you actually compile. You then get the awesomely descriptive error above.
Oh, It appears descriptive right? You say, oh, I must have done something wrong and somehow removed the assembly reference. Let me check it? Nope, it’s there.
Well, it turns out the answer is simple and the stupid compiler could have added one more suggestion. Here is how I would write it.
The type or namespace name ‘Contracts’ does not exist in the namespace ‘XXX’ (are you missing an assembly reference? Are the assemblies built using the same .NET Runtime Profile?)
Yup! One assembly was using the .NET 4.0 CLIENT profile and the other the .NET 4 Full profile. Awesome huh!!!
So, if you come across this with one eye bleeding because you stabbed yourself and missing hair, now you know the simple resolution.
Happy Coding!
How to fix SqlError: FILESTREAM feature is disabled.
Posted by Brian Seekford in SQL on May 17, 2011
I was trying to restore a database and got the error “System.Data.SqlClient.SqlError: FILESTREAM feature is disabled. (Microsoft.SqlServer.Smo) from the Restore Wizard.
This baffled me a bit as I know I went into the DB Server setting in Sql Manager and specifically set that value to Allow it. Well, after smacking the computer around a bit, she finally confessed that there is another place you have to enable that setting. Go figure.
You need to go to the Sql Configuration Manager (Not SQL Server Management Studio) and also enable the settings.
Here is the original error:
Here is me checking the settings on the DB:
Look, I think it’s set:
But really, no. Check the Running Values to see it laugh at you.
So, resolution? Go to Sql Configuration Manager. Open the properties window of your Server.
Check the boxes. Hit OK. Now right click your server instance and hit Restart. Watch the progress bar and ponder great thoughts.
Now, go to SQL Management Studio.
Connect to your server and run this simple command.
EXEC sp_configure filestream_access_level, 2
RECONFIGURE
Now restart your Sql instance once more. You are done. Repeat whatever miserable operation you were doing before you got this error and repeat to yourself. “When I design software, I will never make someone set an option in two programs ever….ever….never ever…”
Happy Coding!