|
Hi
I need to read xml values using Key in power shell
|
|
|
|
|
Go ahead then, you have our permission.
|
|
|
|
|
I am using webapi in my mvc project and when ever I made a request from browser to api call I am getting the following error:
And i am using the .netFramework 4.0
Exception Details:
Server Error in '/' Application.
The format of value 'application/json; charset=utf-8' is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The format of value 'application/json; charset=utf-8' is invalid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[FormatException: The format of value 'application/json; charset=utf-8' is invalid.]
System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(String mediaType, String parameterName) +119919
System.Net.Http.Headers.MediaTypeHeaderValue..ctor(String mediaType) +23
System.Net.Http.ObjectContent.BuildHeaderValue(String mediaType) +63
System.Net.Http.ObjectContent`1..ctor(T value, MediaTypeFormatter formatter, String mediaType) +66
System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value, HttpConfiguration configuration) +892
System.Net.Http.HttpRequestMessageExtensions.CreateResponse(HttpRequestMessage request, HttpStatusCode statusCode, T value) +104
System.Web.Http.Dispatcher.HttpControllerDispatcher.HandleException(HttpRequestMessage request, Exception exception, HttpConfiguration configuration) +191
System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +284
System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +41
System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +347
System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) +55
System.Web.Http.WebHost.HttpControllerHandler.BeginProcessRequest(HttpContextBase httpContextBase, AsyncCallback callback, Object state) +316
System.Web.Http.WebHost.HttpControllerHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +77
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I searched in google but can't find the proper solution.
Please help me
|
|
|
|
|
You need to check the server to see why it cannot handle your request. And it would help if you showed the actual request that you sent, in your question.
|
|
|
|
|
Sorry but how can i check the server to verify the requests
|
|
|
|
|
No idea, it's your server.
|
|
|
|
|
Where are you hosting your Web API services? Are they on Azure, IIS etc? How are they configured?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
|
There isn't enough information here. Giving us the error message tells us very little.
- What parameters are you passing to the Web API?
- Is this a GET, POST etc
It would be useful to see the code that calls the Web API (the client code) and the Web API code itself (the server code).
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Home | LinkedIn | Google+ | Twitter
|
|
|
|
|
Hello everyone, back to coding after a long absence so excuse my rustiness
When doing database apps ibe allways done the wrong thing & validated user input on the form, via simple checks against the controls .text property. Now i want to do it the right way, and concentrate all validation closer to the data side of things, in this case the data tables.
So i decided to do it via the RowChanging event:
On my table...
public override void EndInit()
{
base.EndInit();
customersRowChanging += customersRowChangeEvent;
}
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)
{
if (e.Row.Name.Length == 0)
{
e.Row.SetColumnError("name", "Customer name cannot be empty");
}
else
{
e.Row.SetColumnError("name", "");
}
}
On my app, in a form the textboxes & other input are bound to a BindingSource, wich in turn is bound to the datatable in the dataset (100% as per visual studio designer).
To add a record,
I call the BindingSource.AddNew(), and allow the user to enter the data and then on my handler for the "Save" button...
try
{
Validate();
customersBindingSource.EndEdit();
customersTableAdapter.Update(samDataSet.customers);
}
catch(Exception ex)
{
}
Even without handling the rowChange event, This works when a datatable or database constraint is violated, e.g. if the name is NULL or not unique (as specified in the data table constraints), an exception occurs, and the record is not saved.
However, Even with the RowChangeEvent implemented as above, if a record with an empty (not null, empty string) name is in the record, no exception is thrown, the datatable gladly accepts the new record, and the table adapter saves it (the MySQL database does not enforce empty string values).
Ibe checked, and the handler does get called, and the call to SetColumnError is made, but it doesnt prevent the table from accepting the new row.
I read to use this method from here: Validate data in datasets[^]
And i was under the impression that when i call SetColumnError() with a non empty string for error, the table would not accept the new row. Evidently i got it wrong.
Ibe also tried throwing an exception myself if the data fails the validation requirements, like this:
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)
{
if (e.Row.Name.Length == 0)
{
e.Row.SetColumnError("name", "Customer name cannot be empty");
throw new System.Exception("Customer Name cannot be empty");
}
else
{
e.Row.SetColumnError("name", "");
}
}
But the Binding source does not catch & (re) throw the exception to my own code when it tries to commit the new record, because i end up with an unhandled exception.
Of course there are 101 ways i could enforce data validation on the form, or creating specific bool ValidateThis(DataRow theData) methods, but i would depend on calling such methods every time, and i would prefeer the tables to enforce their own rules automatically.
Can anyone see why its not working?
If calling the SetColumnError doesnt prevent the table from accepting the row, then whats the point of calling it to set errors?
Maybe im doing it the wrong way?
Any input much appreciated!
modified 9-Nov-17 0:27am.
|
|
|
|
|
I've never had input-validation on a DataTable ; usually there is a (generated) validation in the UI, and another one in the database itself. Yes, they partially overlap.
If your DataTable HasErrors , you could try to RejectChanges[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the reply Eddy.
I just found out whats wrong...
This:
public void customersRowChangeEvent(object sender, customersRowChangeEvent e)
{
if (e.Row.Name.Length == 0)
{
e.Row.SetColumnError("name", "Customer name cannot be empty");
throw new System.Exception("Customer Name cannot be empty");
}
else
{
e.Row.SetColumnError("name", "");
}
}
Does work as intended. The unhandled exception i was getting was a First chance exception. If i hit continue and let the code continue to run, it does get handled properly on my own try / catch statements on the Save button handler i posted above.
Now i feel embarassed. i guess im rustier than i tought i was. I completely forgot about first chance exceptions and how the debuger handles them.
|
|
|
|
|
Hehe, I recognize those days
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I would like to use the circle progress bar in my form application
but it is nothing on my tool box.
could you help me where I can get this add on?
|
|
|
|
|
In less time than you spent typing the question in here, you could have performed the following Google search[^]. Being able to do your own research is one of the most valuable abilities you can develop as a programmer. I suggest that you take the time to learn it.
This space for rent
|
|
|
|
|
The bigger question is: What posseses you to use VS2008 when you could be using any one of 4 or 5 more recent versions?
Maybe you should just use a stick and some string.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Done
I create some class in user control
Thanks for your concern Brother.
|
|
|
|
|
Hi everybody,
I'm trying to figure out how to call windows camera UI from a windows form.
I did this and it does compile:
Public Function ShootPicture() As StorageFile
Dim captureUI As New CameraCaptureUI
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg
captureUI.PhotoSettings.AllowCropping = False
Dim GetPhotoTask As Task(Of StorageFile) = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo)
GetPhotoTask.Wait()
Dim result As StorageFile = GetPhotoTask.Result
Return result
End Function
But there is a 'System.InvalidCastException' execution error on .capturefileAsync() : type 'System._ComObject' cannot be casted as 'System.threading.tasks.task'
The idea of wait instead of await was to make the function Synchronous because I would rather to call it from a Protected Overrides Function. However I tried with the classic Async declaration and I don't have a better result (does not compile).
Dim GetPhotoTask As Task(Of StorageFile) = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo)
Dim Photo As StorageFile = Await GetPhotoTask
Would anyone have any idea on how to fix this? Thanks
If it can help here is the c# code translation:
public StorageFile ShootPicture()
{
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.AllowCropping = false;
Task<StorageFile> GetPhotoTask = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
GetPhotoTask.Wait();
StorageFile result = GetPhotoTask.Result;
return result;
}
|
|
|
|
|
The message is perfectly clear, you cannot cast the returned type to something completely different.
|
|
|
|
|
|
Thanks Richard it seems to be the right solution.
I managed to add WindowsRuntimeSystemExtensions to the project following these instructions: [^]
And I imported it to the module with:
Imports System.WindowsRuntimeSystemExtensions
But IAsyncOperation still don't have
.AsTask()
Any idea?
|
|
|
|
|
Hi,
I've finally manage to compile and execute the code as suggested:
Private Async Sub MassPointImageBox_Click(sender As Object, e As EventArgs) Handles MassPointImageBox.Click
MsgBox("Take a Picture")
Dim capture = New CameraCaptureUI()
capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg
capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable
Dim GetPhotoTask As Task(Of StorageFile) = capture.CaptureFileAsync(CameraCaptureUIMode.Photo).AsTask
Dim Photo As StorageFile = Await GetPhotoTask
If Photo Is Nothing Then
MsgBox("No picture taken")
Else
MsgBox(Photo.Path)
End If
End Sub
However, the camera app does not open, and photo is always nothing. AnyOne ever had this kind of issue with .CaptureFileAsync ?
Thanks
|
|
|
|
|
I am trying to let a user type in a textbox and process input as the typing occurs - but also want to make sure that the last characters typed (when the user finished typing) are processed - I want to have only 1 processing task running at any time - so I would probably need something like the below with an async semaphore, right?
Does someone have a hint towards the correct code snippet?
MainWindow XAML:
<Window x:Class="InputTaskQueue.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:behav="clr-namespace:InputTaskQueue.Behaviors"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Vertical">
<TextBox Name="tbInput"
behav:TextChangedCommand.ChangedCommand="{Binding SearchCommand}"
HorizontalAlignment="Left" VerticalAlignment="Bottom"
Width="100" Height="20"/>
<TextBlock Text="{Binding SearchStringResult,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}" Width="100" Height="100" />
</StackPanel>
</Window>
Text KeyUp Behavior Triggera command via binding:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
public static class TextChangedCommand
{
private static readonly DependencyProperty ChangedCommandProperty = DependencyProperty.RegisterAttached(
"ChangedCommand",
typeof(ICommand),
typeof(TextChangedCommand),
new PropertyMetadata(null, OnTextChangedCommandChange));
public static void SetChangedCommand(DependencyObject source, ICommand value)
{
source.SetValue(ChangedCommandProperty, value);
}
public static ICommand GetChangedCommand(DependencyObject source)
{
return (ICommand)source.GetValue(ChangedCommandProperty);
}
private static void OnTextChangedCommandChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TextBox uiElement = d as TextBox;
if (uiElement != null)
{
uiElement.TextChanged -= OnText_Changed;
var command = e.NewValue as ICommand;
if (command != null)
{
uiElement.TextChanged += OnText_Changed;
}
}
}
private static void OnText_Changed(object sender, TextChangedEventArgs e)
{
TextBox uiElement = sender as TextBox;
if (uiElement == null)
return;
if (uiElement.IsEnabled == false)
return;
ICommand changedCommand = TextChangedCommand.GetChangedCommand(uiElement);
if (changedCommand == null)
return;
var item = uiElement.Text;
if (changedCommand is RoutedCommand)
{
(changedCommand as RoutedCommand).Execute(item, uiElement);
}
else
{
changedCommand.Execute(item);
}
}
}
ViewModel bond to MainWindow:
private string _SearchStrinResult;
public string SearchStringResult
{
get { return _SearchStrinResult; }
private set
{
if (_SearchStrinResult != value)
{
_SearchStrinResult = value;
NotifyPropertyChanged(() => SearchStringResult);
}
}
}
#endregion properties
#region methods
public ICommand SearchCommand
{
get
{
if (_SearchCommand == null)
{
_SearchCommand = new RelayCommand<object>((p) =>
{
string findThis = p as string;
if (string.IsNullOrEmpty(findThis) == true)
return;
SearchCommand_ExecutedAsync(findThis);
},
(p =>
{
return true;
})
);
}
return _SearchCommand;
}
}
private List<string> _Queue = new List<string>();
private static SemaphoreSlim SlowStuffSemaphore = new SemaphoreSlim(1, 1);
private async void SearchCommand_ExecutedAsync(string input)
{
_Queue.Add(input);
await SlowStuffSemaphore.WaitAsync();
try
{
if (_Queue.Count > 1)
{
_Queue.Remove(input);
return;
}
else
{
Console.WriteLine("Queue Count: {0}", _Queue.Count);
}
await createTask(input);
_Queue.Remove(input);
this.SearchStringResult = input;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
finally
{
SlowStuffSemaphore.Release();
}
}
private Task createTask(string input)
{
return Task.Run(() =>
{
Console.WriteLine("searching:" + input);
System.Threading.Thread.Sleep(5000);
})
.ContinueWith((p) =>
{
});
}
modified 13-Oct-17 16:45pm.
|
|
|
|
|
The easier way is for the user to finish typing, and not run a new thread until he/she finished editing. I don't see any data being presented to the user during processing, so in effect it would be the same as simply waiting for the focus-change and start processing then.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The statement System.Threading.Thread.Sleep(5000); is a mockup for the background processing - it might in reality be 1 second or half a econd long but should definetly be done while typing not after - I know it would be easier otherwise - but anyone can do easy 
|
|
|
|
|