Facebook RSS
 
 
formats

Messing around with Exceptions

Published on December 14th, 2011 by in C#, General

Today I’ve found an awesome listing of how to mess around with exceptions in C#:
http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx

 
formats

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)
 
formats

SHA1-Encrypting

Published on October 28th, 2011 by in C#, Snippets

There is only some slow blogging going on recently… So here’s something to fill the Lazyness-Gaps :)

  1.         /// <summary>
  2.         /// Encrypts the specified Text to SHA1
  3.         /// </summary>
  4.         /// <param name="text">The Text to encrypt</param>
  5.         /// <returns>The SHA1-Encrypted text</returns>
  6.         public static string EncryptToSHA1(this string text)
  7.         {
  8.             SHA1 sha1 = new SHA1CryptoServiceProvider();
  9.  
  10.             byte[] arrayData = Encoding.ASCII.GetBytes(text);
  11.             byte[] arrayResult = sha1.ComputeHash(arrayData);
  12.  
  13.             string result = string.Empty;
  14.             string temp = string.Empty;
  15.  
  16.             for (int i = 0; i < arrayResult.Length; i++)
  17.             {
  18.                 temp = Convert.ToString(arrayResult[i], 16);
  19.                 if (temp.Length == 1)
  20.                     temp = "0" + temp;
  21.                 result += temp;
  22.             }
  23.  
  24.             return result;
  25.         }
 
formats

List of CultureCodes in C#

Published on October 19th, 2011 by 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.

(more…)

 
formats

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.

 
formats

Convert Image to Byte[]

Published on September 15th, 2011 by in C#, Snippets, WPF

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.

  1.         /// <summary>
  2.         /// Converts the specified Image to a byte[]
  3.         /// </summary>
  4.         /// <param name="imageToConvert">The Image you wish to convert</param>
  5.         /// <returns>A Byte[], containing the images Information</returns>
  6.         public byte[] ConvertImageToByteArray(Image imageToConvert)
  7.         {
  8.             BitmapImage bmp = imageToConvert.Source as BitmapImage;
  9.  
  10.             if (bmp != null)
  11.             {
  12.                 int height = bmp.PixelHeight;
  13.                 int width = bmp.PixelWidth;
  14.                 int stride = width * ((bmp.Format.BitsPerPixel + 7) / 8);
  15.  
  16.                 byte[] bits = new byte[height * stride];
  17.                 bmp.CopyPixels(bits, stride, 0);
  18.  
  19.                 return bits;
  20.             }
  21.             else
  22.             {
  23.                 return null;
  24.             }
  25.         }
 
formats

Creating a Nice-Looking Filesize in C#

Published on September 13th, 2011 by in C#, Snippets

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…

  1. 		/// <summary>
  2. 		/// Creates a nicer FileSize from bytes
  3. 		/// </summary>
  4. 		/// <param name="size">The Size to Parse</param>
  5. 		/// <returns>The converted FileSize, including the SizeType (KB, MB, ...)</returns>
  6. 		public static string CreateNiceFileSize(double size)
  7. 		{
  8. 			int run = 0;
  9. 			string[] sizes = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
  10. 			while (size >= 1024)
  11. 			{
  12. 				size /= 1024;
  13. 				run++;
  14. 			}
  15.  
  16. 			return (Math.Round(size, 2) + " " + sizes[run]);
  17. 		}
 
Tags:
formats

Console.WriteLine(“Hello World!”);

Published on August 12th, 2011 by in General

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…

 
 
© Yari-Serve.de
credit