MetadataException: Unable to load the specified metadata resource

This means that the application is unable to load the EDMX. There are several things which can cause this. You might have changed the MetadataArtifactProcessing property of the model to Copy to Output Directory. The connection string could be wrong. I know you say you haven’t changed it, but if you have changed other things … Read more

What is the correct way to create a single-instance WPF application?

Here is a very good article regarding the Mutex solution. The approach described by the article is advantageous for two reasons. First, it does not require a dependency on the Microsoft.VisualBasic assembly. If my project already had a dependency on that assembly, I would probably advocate using the approach shown in another answer. But as … Read more

How to get the list of properties of a class?

Reflection; for an instance: obj.GetType().GetProperties(); for a type: typeof(Foo).GetProperties(); for example: class Foo { public int A {get;set;} public string B {get;set;} } … Foo foo = new Foo {A = 1, B = “abc”}; foreach(var prop in foo.GetType().GetProperties()) { Console.WriteLine(“{0}={1}”, prop.Name, prop.GetValue(foo, null)); } Following feedback… To get the value of static properties, pass … Read more

Run Command Prompt Commands

this is all you have to do run shell commands from C# string strCmdText; strCmdText= “/C copy /b Image1.jpg + Archive.rar Image2.jpg”; System.Diagnostics.Process.Start(“CMD.exe”,strCmdText); EDIT: This is to hide the cmd window. System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = “cmd.exe”; startInfo.Arguments = “/C copy /b Image1.jpg + Archive.rar … Read more

Implementing INotifyPropertyChanged – does a better way exist?

Without using something like postsharp, the minimal version I use uses something like: public class Data : INotifyPropertyChanged { // boiler-plate public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } protected bool SetField<T>(ref T field, T value, string propertyName) { if (EqualityComparer<T>.Default.Equals(field, … Read more

Best way to parse command line arguments in C#? [closed]

I would strongly suggest using NDesk.Options (Documentation) and/or Mono.Options (same API, different namespace). An example from the documentation: bool show_help = false; List<string> names = new List<string> (); int repeat = 1; var p = new OptionSet () { { “n|name=”, “the {NAME} of someone to greet.”, v => names.Add (v) }, { “r|repeat=”, “the … Read more

How do I convert an enum to a list in C#? [duplicate]

This will return an IEnumerable<SomeEnum> of all the values of an Enum. Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>(); If you want that to be a List<SomeEnum>, just add .ToList() after .Cast<SomeEnum>(). To use the Cast function on an Array you need to have the System.Linq in your using section.

Encrypt and decrypt a string in C#? [closed]

EDIT 2013-Oct: Although I’ve edited this answer over time to address shortcomings, please see jbtule’s answer for a more robust, informed solution. https://stackoverflow.com/a/10366194/188474 Original Answer: Here’s a working example derived from the “RijndaelManaged Class” documentation and the MCTS Training Kit. EDIT 2012-April: This answer was edited to pre-pend the IV per jbtule’s suggestion and as … Read more

Using LINQ to remove elements from a List

Well, it would be easier to exclude them in the first place: authorsList = authorsList.Where(x => x.FirstName != “Bob”).ToList(); However, that would just change the value of authorsList instead of removing the authors from the previous collection. Alternatively, you can use RemoveAll: authorsList.RemoveAll(x => x.FirstName == “Bob”); If you really need to do it based … Read more

Order of items in classes: Fields, Properties, Constructors, Methods

According to the StyleCop Rules Documentation the ordering is as follows. Within a class, struct or interface: (SA1201 and SA1203) Constant Fields Fields Constructors Finalizers (Destructors) Delegates Events Enums Interfaces (interface implementations) Properties Indexers Methods Structs Classes Within each of these groups order by access: (SA1202) public internal protected internal protected private Within each of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)