While I was working on some code today and found that some NuGet packages where out of date. So I went to update tab in Manage NuGet packages window and updated all of them. MySql.Data package (not important which package, just an example) was also updated in that from version 6.7.8 to current / latest (6.9.6). I tried to run the application to test the updates made in referring packages. I encountered following error: TypeInitializationException was unhandled An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module. Additional information: The type initializer for '[Application Name]' threw an exception. Looking at this exception, it doesn't seems to be obvious what is going wrong here. There isn't even option for "View details". Many of you may get stuck on this and spent hours before you figure out that the AssemblyBinding.dependentAssembly.bindingRedirect are » Read more
Microsoft OS (XP or later) and .NET provides finest way to secure your data for storage and in-memory. This can be accomplished using following classes from Data Protectection API ProtectedData ProtectedMemory Above mentioned classes can be found in System.Security.Cryptography namespace. Also known as part of DPAPI, they are available since .NET 2.0 ProtectedData ProtectedData can encrypt and decrypt your data symmetrically. To encrypt data following code is used: ProtectedData.Protect(byteArrayOfOriginalData, additionalEntropyOrSalt, DataProtectionScopeValue); To decrypt data following code is used: ProtectedData.Unprotect(byteArrayOfEncryptedData, additionalEntropyOrSalt, DataProtectionScopeValue); In above code snippets additionalEntropyOrSalt can be some custom key / salt value / entropy data that you can add to the encryption / decryption process to increase security strength. DataProtectionScope in above code snippets can have any of the two values: CurrentUser - Allows decryption of encrypted data in current user context only. LocalMachine - Allows decryption of encrypted data in current machine context » Read more
Drag and drop and one of the UI interaction every user loves to have. I gave it a whip in something I was playing with at home. There might be better ways to bring Drag N' Drop interaction in WPF application but I choose to use GongSolution for WPF Drag Drop One reason for using this library for drag and drop interaction is that the library supports MVVM way to do it and does not require much integration to get started. You can add Gong WPF DragDrop library from Nuget into your MVVM enabled WPF application. Add enable a UI element for drag - drop support add following properties to it: DragDrop.IsDropTarget="True" and DragDrop.DropHandler="{Binding}" Here is how my sample XAML file looks like after adding above mentioned properties. <Window x:Class="GongDragAndDropSample.MainWindow" xmlns="http://schemas.microsoft.com/ » Read more
So someday you might need to create shortcut of or in your application programatically. Here is how you can do it: A shortcut is basically a LINK to the original file / executable that will be called when the link / shortcut is clicked. To create shortcut pro-grammatically, first you need add reference to Windows Script Host Object Model COM library in your project. Next add this using to your class - using IWshRuntimeLibrary; Next code snippet to create shortcut: var startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var shell = new WshShell(); var shortCutLinkFilePath = Path.Combine(startupFolderPath, @"\CreateShortcutSample.lnk"); var windowsApplicationShortcut = (IWshShortcut)shell.CreateShortcut(shortCutLinkFilePath); windowsApplicationShortcut.Description = "How to create short for application example"; windowsApplicationShortcut.WorkingDirectory = Application.StartupPath; windowsApplicationShortcut.TargetPath = Application.ExecutablePath; windowsApplicationShortcut.Save(); Using above code, I create shortcut on my user's desktop. First line gives me the path to the desktop of my user - using Environment. » Read more