invalidoperationexception

HttpContext.Current.Request.Form.AllKeys in ASP.NET CORE version

廉价感情. 提交于 2020-12-05 06:38:57
问题 foreach (string key in HttpContext.Current.Request.Form.AllKeys) { string value = HttpContext.Current.Request.Form[key]; } What is the .net core version of the above code? Seems like .net core took out AllKeys and replaced it with Keys instead. I tried to convert the above code to the .net core way, but it throws an invalid operation exception. HttpContext.Request.Form = 'HttpContext.Request.Form' threw an exception of type 'System.InvalidOperationException' Converted code: foreach (string

Highlight Search TextBlock

心已入冬 提交于 2020-03-18 15:38:57
问题 My goal is to create a custom TextBlock control that has a new dependency property, SearchText. This property will contain a regular expression. All occurrences of this regular expression in the text of the TextBlock will be highlighted using a custom style (another DP). My current implementation involves clearing all of the Inline objects in the TextBlock's InlineCollection. I then fill the TextBlock with runs for unhighlighted text and runs for highlighted text with the style applied (this

Bitmap region is already locked

南笙酒味 提交于 2020-01-25 12:02:50
问题 string pathFile = @"C:\Users\user\Downloads\CaptchaCollection\Small\Sorted\"; var files = Directory.GetFiles(pathFile).Select(nameWithExtension => Path.GetFileNameWithoutExtension(nameWithExtension)).Where(name => { int number; return int.TryParse(name, out number); }).Select(name => int.Parse(name)).OrderBy(number => number).ToArray(); List<int> fileList = files.ToList(); image1 = new Bitmap(pathFile + fileList[0].ToString() + ".png"); image2 = new Bitmap(pathFile + fileList[1].ToString() +

Why does ControlCollection NOT throw InvalidOperationException?

安稳与你 提交于 2020-01-23 04:39:07
问题 Following this question Foreach loop for disposing controls skipping iterations it bugged me that iteration was allowed over a changing collection: For example, the following: List<Control> items = new List<Control> { new TextBox {Text = "A", Top = 10}, new TextBox {Text = "B", Top = 20}, new TextBox {Text = "C", Top = 30}, new TextBox {Text = "D", Top = 40}, }; foreach (var item in items) { items.Remove(item); } throws InvalidOperationException: Collection was modified; enumeration operation

Starting and Forgetting an Async task in MVC Action

落花浮王杯 提交于 2020-01-22 12:26:25
问题 I have a standard, non-async action like: [HttpPost] public JsonResult StartGeneratePdf(int id) { PdfGenerator.Current.GenerateAsync(id); return Json(null); } The idea being that I know this PDF generation could take a long time, so I just start the task and return, not caring about the result of the async operation. In a default ASP.Net MVC 4 app this gives me this nice exception: System.InvalidOperationException: An asynchronous operation cannot be started at this time. Asynchronous

InvalidOperationException when multithreading in WPF

牧云@^-^@ 提交于 2020-01-16 13:15:13
问题 So I'm working on my first multithreaded WPF app. Please bear in mind I have little to no understanding of how to implement multithreading - I've done it in a few apps and always work off the existing code. This is my first attempt at it in WPF which is apparently quite different to Windows Forms... So basically I'm working on this example which oddly enough doesn't mention that you have to instantiate a new thread and start it - I guess the author felt that was self evident even to newbies

Why is XmlSerializer throwing an InvalidOperationException?

 ̄綄美尐妖づ 提交于 2020-01-14 07:19:27
问题 public void Save() { XmlSerializer Serializer = new XmlSerializer(typeof(DatabaseInformation)); /* A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll */ // .... } This is the whole class if you need it: public class DatabaseInformation { /* Create new database */

Why is XmlSerializer throwing an InvalidOperationException?

最后都变了- 提交于 2020-01-14 07:18:00
问题 public void Save() { XmlSerializer Serializer = new XmlSerializer(typeof(DatabaseInformation)); /* A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll */ // .... } This is the whole class if you need it: public class DatabaseInformation { /* Create new database */

Control a service on a remote server from IIS

不想你离开。 提交于 2020-01-06 02:54:06
问题 Please note: In each step I describe below I'm logged in as the same domain user account. I have a web application that controls a service on a remote machine (via ServiceController). When I connect to the website remotely and attempt to control the service, I get an InvalidOperationException: Access is denied. I know it CAN work, because when I connect to the website from the web server (remote desktop in, login as my domain user, then open the webpage), it works as expected. I have

The ConnectionString property has not been initialized error

随声附和 提交于 2020-01-03 05:52:05
问题 I'm using an asp.net web application with a MySql DB, with the following connetcion string the web.config: <add name="techConnectionString" connectionString="server=vm-tmysql01;User Id=user;database=tech;password=pass" providerName="MySql.Data.MySqlClient"/> And this is the code I'm using the get the connection string from the web.config: System.configuration.configurationmanaget.connectionstrings["techConnectionString"].connectionstring; For some reason I get the error: The ConnectionString