Today I’ve found an awesome listing of how to mess around with exceptions in C#:
http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx
Messing around with Exceptions
Microsoft Visual Studio 2010 SP 1 – Issues
So, after I’ve installed (and deinstalled) SP1 for the first time, I have decided to give it another shot… Regrettably…
Here is, what I’ve experienced so far:
- I’m not seeing “Hidden” Controls in the Designer anymore (I mean.. what the heck?! That my customers aren’t seeing them in a deployed application is perfectly fine, but why (at least) does no option exist to turn this on / off in the Designer?)
- “Debugging-Tooltips” (or what should I call them?) are unstable… Mostly 90% of the time I want to look up a variable or property, no Tooltip opens on mouseover… Here you go, Immediate Window…
- The XAML-Designer loads up way slower than before
- The XAML-Designer occasionally crashes with an InvalidOperationException:
System.InvalidOperationException Operation is not valid due to the current state of the object. at Microsoft.MetadataReader.MetadataOnlyCommonArrayType.GetGenericTypeDefinition() at Microsoft.VisualStudio.Shell.Design.TypeWrapper.GetGenericTypeDefinition() at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.TypesMatch(Type tfpType, Type rtType) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.FindBestRuntimeMethodMatch(MethodBase tfpMethod, List`1 rtMethods) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeMethod(MethodBase method) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkMethodInfo.get_RuntimeMethod() at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeMethod(MethodBase method) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeTypeVariable(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeType(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.TryGetRuntimeType() at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeType(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkProvider.GetRuntimeType(Type reflectionType) at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.VsReflectionResolver.GetRuntimeType(Type reflectionType) at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.CachingReflectionResolver.GetRuntimeType(Type reflectionType) at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.Microsoft.Windows.Design.Metadata.IReflectionResolver.GetRuntimeType(Type reflectionType) at MS.Internal.Metadata.ClrType.get_RuntimeMember() at MS.Internal.Metadata.ClrMember`1.Microsoft.Windows.Design.Metadata.Reflection.IReflectionMember.get_MemberInfo() at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.IsAssignableFrom(ITypeMetadata requesting, ITypeMetadata target) at MS.Internal.Metadata.ClrType.IsAssignableFrom(ITypeMetadata type) at MS.Internal.Design.Metadata.Xaml.AttachableProperty.IsAttachableTo(ITypeMetadata targetType, ParentScope scope) at MS.Internal.Design.Metadata.Xaml.XamlType.d__0.MoveNext() at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.d__7.MoveNext() at MS.Internal.VirtualModel.VirtualModelPropertyCollection.d__0.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at MS.Internal.VirtualModel.VirtualModelPropertyCollection.GetEnumerator() at MS.Internal.VirtualModel.VirtualModelUtilities.WrapProperties(IVirtualModelItem item) at MS.Internal.VirtualModel.VirtualModelItem.System.ComponentModel.ICustomTypeDescriptor.GetProperties() at System.ComponentModel.TypeDescriptor.MergedTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties() at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes) at System.Windows.PropertyPath.ResolvePropertyName(String name, Object item, Type ownerType, Object context, Boolean throwOnError) at MS.Internal.Data.PropertyPathWorker.GetInfo(Int32 k, Object item, SourceValueState& svs) at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent) at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange) at MS.Internal.Data.ClrBindingWorker.AttachDataItem() at System.Windows.Data.BindingExpression.Activate(Object item) at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt) at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp) at System.Windows.Data.MultiBindingExpression.AttachBindingExpression(Int32 i, Boolean replaceExisting) at System.Windows.Data.MultiBindingExpression.AttachOverride(DependencyObject d, DependencyProperty dp) at System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp) at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding) at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, BindingBase binding) at MS.Internal.GridControl.GridRowAdornerBase..ctor(ModelItem gridItem, ModelItem rowItem) at MS.Internal.GridControl.GridRowSelectAdorner..ctor(ModelItem grid, ModelItem row) at MS.Internal.GridControl.GridDesigner.EnsureRowAdorners(ModelItem rowDefModel, Boolean withHandle) at MS.Internal.GridControl.GridDesigner.EnsureAllRowAdorners() at MS.Internal.GridControl.GridDesigner.InitGridDesigner() at MS.Internal.GridControl.GridDesigner.GetDesigner(ModelItem gridItem) at MS.Internal.GridControl.AlwaysVisibleGridAdornerProvider.Activate(ModelItem item) at Microsoft.Windows.Design.Interaction.AdornerProvider.InvokeActivate(EditingContext context, ModelItem item) at MS.Internal.Features.AdornerProviderFeatureConnector.FeatureProvidersAdded(ModelItem item, IEnumerable`1 extensions) at Microsoft.Windows.Design.Policies.PolicyDrivenFeatureConnector`1.UpdateFeatureProviders() at MS.Internal.Features.PolicyDrivenToolFeatureConnector`1.UpdateCurrentTool(Tool newTool) at MS.Internal.Features.PolicyDrivenToolFeatureConnector`1.< .ctor>b__0(Tool newTool) at Microsoft.Windows.Design.ContextItemManager.SubscribeProxy`1.SubscribeContext(ContextItem item) at Microsoft.Windows.Design.SubscribeContextCallback.Invoke(ContextItem item) at Microsoft.Windows.Design.EditingContext.DefaultContextItemManager.OnItemChanged(ContextItem item) at Microsoft.Windows.Design.EditingContext.DefaultContextItemManager.SetValue(ContextItem value) at MS.Internal.Host.ToolSubsystem.ActivateTool(ToolFactory toolFactory) at MS.Internal.Host.ToolSubsystem..ctor(EditingContext editingContext, DesignerContext designerContext) at MS.Internal.Host.Designer.Load() at MS.Internal.Designer.VSDesigner.Load() at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.Load() at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedDesignerFactory.Load(IsolatedView view) at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view) at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view) at MS.Internal.Host.Isolation.IsolatedDesigner.Load() at MS.Internal.Designer.DesignerPane.LoadDesignerView(Boolean isReload)
SHA1-Encrypting
There is only some slow blogging going on recently… So here’s something to fill the Lazyness-Gaps
/// <summary>/// Encrypts the specified Text to SHA1/// </summary>/// <param name="text">The Text to encrypt</param>/// <returns>The SHA1-Encrypted text</returns>public static string EncryptToSHA1(this string text)
{SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] arrayData = Encoding.ASCII.GetBytes(text);
byte[] arrayResult = sha1.ComputeHash(arrayData);
string result = string.Empty;
string temp = string.Empty;
for (int i = 0; i < arrayResult.Length; i++)
{temp = Convert.ToString(arrayResult[i], 16);
if (temp.Length == 1)
temp = "0" + temp;
result += temp;
}return result;
}
List of CultureCodes in C#
A comprehensive list of culture codes used for localising and in conjunction with the CultureInfo class.
The CultureInfo class specifies a unique name for each culture, based on RFC 4646 (Windows Vista and later). The name is a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region.
What programming is all about…
Here are 14 Programming quotes selected from BVK Mohan’s blog (http://bvkm.wordpress.com/2010?/12/16/top-50-programming-quotes/).
Enjoy
1. “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
– Martin Golding
2. “To iterate is human, to recurse divine.”
– L. Peter Deutsch
3. “The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.”
– Seymour Cray
4. “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
– Brian W. Kernighan.
5. “Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves.”
– Alan Kay
6. “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”
– Bill Gates
7. “Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debugging Monday’s code.”
– Christopher Thompson
8. “I don’t care if it works on your machine! We are not shipping your machine!”
– Vidiu Platon.
9. “Walking on water and developing software from a specification are easy if both are frozen.”
– Edward V Berard
10. “Fine, Java MIGHT be a good example of what a programming language should be like. But Java applications are good examples of what applications SHOULDN’T be like.”
– pixadel
11. “I think Microsoft named .NET, so it wouldn’t show up in a Unix directory listing.”
– Oktal
12. “I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.”
– Bjarne Stroustrup
13. “Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.”
– Mosher’s Law of Software Engineering
14. “In the one and only true way. The object-oriented version of ‘Spaghetti code’ is, of course, ‘Lasagna code’. (Too many layers).”
– Roberto Waltman.
Convert Image to Byte[]
Let’s get a bit more advanced – we’re now converting a WPF-Image to a byte[]. You can then store this byte[] in an MS-SQL Database, for example.
/// <summary>/// Converts the specified Image to a byte[]/// </summary>/// <param name="imageToConvert">The Image you wish to convert</param>/// <returns>A Byte[], containing the images Information</returns>public byte[] ConvertImageToByteArray(Image imageToConvert)
{BitmapImage bmp = imageToConvert.Source as BitmapImage;
if (bmp != null)
{int height = bmp.PixelHeight;
int width = bmp.PixelWidth;
int stride = width * ((bmp.Format.BitsPerPixel + 7) / 8);
byte[] bits = new byte[height * stride];
bmp.CopyPixels(bits, stride, 0);
return bits;
}else{return null;
}}
Creating a Nice-Looking Filesize in C#
Let’s go ahead with a little Code-Snippet regarding the FileSize in C#. Sometimes you need to display a “nice file size” – values like 14865343435 Bytes are absolutely useless for Userfriendly Interfaces…
/// <summary>/// Creates a nicer FileSize from bytes/// </summary>/// <param name="size">The Size to Parse</param>/// <returns>The converted FileSize, including the SizeType (KB, MB, ...)</returns>public static string CreateNiceFileSize(double size)
{int run = 0;
string[] sizes = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
while (size >= 1024)
{size /= 1024;
run++;}return (Math.Round(size, 2) + " " + sizes[run]);
}
Console.WriteLine(“Hello World!”);
Welcome to my new blog. I’ve thought for quite a while about starting a blog based on some advice from my friend Felix, but I finally got around to it. I plan to write on topics relevant to Coding, C#, Visual Studio and general Microsoft-Stuff. I’ll try to keep away from strictly technical topics, as there are many good blogs out there already.
Please feel free to send suggestions about topics you would like to hear about and areas, where I can get a little closer to perfection…





No Comments » 