webview document.getElementsByName() not implemented - c#

I'm currently working in c# on universal app for w10, and I'm working with webview.
I'm trying to run script over webview.Invoke()
string functionString = "document.getElementsByName('name').Value = 'jmeno';";
webView1.InvokeScript("eval", new string[] { functionString });
But I'm getting exception: The method or operation is not implemented.
Any ideas, or experiences about this issue?

It looks like your javascript is invalid, though I'm unsure if that'd throw the exception you're seeing.
Specify the index (i.e. [0]) of the element to set the "value" of:
string functionString = "document.getElementsByName('name')[0].value = 'jmeno';";

As the documentation says:
InvokeScript may be altered or unavailable for releases after Windows
8.1. Instead, use InvokeScriptAsync.
So on Windows 10 you should use InvokeScriptAsync.

Related

C# handlebars error in Handlebars.Compile() function

I am trying to use handlebars with C# in universal windows platform (UWP) using Handlebars.Net in this GitHub link (https://github.com/Handlebars-Net/Handlebars.Net)
I used simple code used in the usage section in the link above and even though it didn't work always stop at handlebars.compile() function and throws error.
My code is a very basic simple one just when I press a button in the application, I enter debug mode to see the result but I got this exception message.
This is the error message.
and this is the code I used.
try
{
string source = "{{title}} and This Is body : {{body}}";
var template = Handlebars.Compile(source);
var data = new
{
title = "My new post",
body = "This is my first post!"
};
var result = template(data);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
I tried installing Linq express and Linq itself but nothing changed.
Handlebars.Net uses Expression Trees to compile templates.
MissingMethodException means that platform you're trying to compile the template on does not support required Expression Trees features. It's known issue on iOS. I may assume that the same might be true for UWP.

How to get ExpandEnvironmentVariables to return custom variables?

I have added a custom environment variable and I'm unable to get it to return in the ExpandEnvironmentVariables.
These 2 calls work fine:
string s = Environment.GetEnvironmentVariable("TEST", EnvironmentVariableTarget.Machine);
// s = "D:\Temp2"
string path = Environment.ExpandEnvironmentVariables(#"%windir%\Temp1");
// path = "C:\Windows\Temp1"
However, this call returns the same input string:
var path = Environment.ExpandEnvironmentVariables(#"%TEST%\Temp1");
// path = "%TEST%\\Temp1"
I expect to get D:\Temp2\Temp1
What am I missing to correctly get the custom EnvironmentVariable in this last call?
Hans and Evk were correct in their comments. Since no one wanted to add an answer I'll close this question out.
For whatever reason ExpandEnvironmentVariables will not get any keys which were added after an application started. I also tested this with a running Windows Service. It was only after I restarted the service that new keys were found and populated.
This behavior is not documented in the Microsoft Documentation.

Windows 8.1 WPF application mixerSetControlDetails returns MMSYSERR_ERROR

Edit
After modifying the NAudio source code and a little debugging, I found that the mixerSetControlDetails function, which is called when I set the Value property, returns MMSYSERR_ERROR.
Is there a way to get further information about why mixerSetControlDetails failed?
I'm also open to other ways to accomplish same thing on C#.
Original
I have some code that computes energy in voice and sets the microphone boost level according to this computed value using NAudio. I have no problem reading audio samples but when I try to set microphone boost, the program gets stuck.
I have checked the issue on Windows 7, 8, and 8.1. The problem occurs only on Windows 8.1. Interestingly when I run the program on a virtual machine with Windows 8.1 it works as expected. Can this be a permission problem?
Here is the code for setting the boost value
foreach (MixerControl mixerControl in MixerLine.Controls)
{
if (mixerControl.ControlType == MixerControlType.Volume)
{
UnsignedMixerControl volumeControl = (UnsignedMixerControl)mixerControl;
volumeControl.Value = (uint) value;
}
}
Where MixerLine is created beforehand with this code.
MixerLine = new MixerLine((IntPtr) deviceID, 0, MixerFlags.WaveIn);
It seems the mixerSetControlDetails function returns MMSYSERR_ERROR randomly (at least I couldn't find a pattern). Actually it does set the new value, just ignore the exception, or if it does not set try setting the value again. The stuck behavior was about my program, irrelevant to this error.

Application.Current Null exception in Xamarin.Forms

In a Xamarin.Forms app I'm using Application.Current.Properties to save settings. When my LoginPage loads I want to see if settings exist but I'm getting an exception saying Application.Current is Null. This is the (sanitized) code, which is in the LoginPage:
private bool AuthTokenExists()
{
// The following line throws the exception
if (Application.Current.Properties.ContainsKey("First") && Application.Current.Properties.ContainsKey("Second"))
{
if (Application.Current.Properties["First"] as string != null &&
Application.Current.Properties["Second"] as string != null)
return true;
}
else
{
return false;
}
}
I've read you can't call Application.Current.Properties in the App constructor, but this is in a ContentPage. Any thoughts why I'm getting the exception? Thanks in advance!
It's null until you call LoadApplication () from your platform projects.
Just wirte LoadApplication( new App() ); in MainActivity.cs and your App class in PCL or Shaired must be a Applciation not a content Page.
Then you can use your exsisting code any where in application (including content page as you mention) , It will not give Null exception.
Right now, there is a (one more :-) bug in the Xamarin-VS extension, so that the application-object is not visible in the debugger.
Therefore, I have filled a bug in bugzilla.
But at RunTime (without debugger) it should run (at least with the newer XF-Versions).
Additionally there are some problems with some devices (e.g. my Android tablet SM-T900), so that the Properties are not stored properly (sounds good:-)
In one of the last XF-Versions, there is now possible, to store the properties explicitly (new method).
So, I suggest you, to:
- Update to the version that allow the explicit store (if not already in use)
- Set default values by app-start
- Save it with the new method
- Deploy to device
- Retest, if it works then (e.g. show a DisplayAlert with the Property-value)
If not, you should fill a bug in BugZilla.
Hope this helps...

DotNetCharting exception thrown

I am using DotNetCharting version 4.2. I am trying to create a chart, save it to disk and return the path as a string. Here is a simplified version of my code thus far.
Chart aChart = new Chart();
aChart aChart.Title = "Some Title";
aChart aChart.ChartArea.Background = new Background(Color.White);
aChart.TempDirectory = "C:\\temp\\"
aChart.Width = chartWidth;
aChart.Height = chartHeight;
imageName = aChart.FileManager.SaveImage();
I got this from this dotnetCharting support page. It is very straightforward code.
Here is the problem: The code above actually DOES create an image in the appropriate directory. This is NOT a directory permissions issue. When I add my actual data to the aChart, it actually DOES add it and an image is created. However, the SaveImage() method always throws an exception of "Failed to map the path '/'." The SaveImage() method is supposed to return a String, however, it always returns "" and the exception is thrown.
More Info: I am doing this in a WCF Service. Is it possible that since it's in a service the dotNetCharting DLL is having trouble with some internal MapPath?
I just upgraded the DotNetCharting to the latest version (7.0) and now it works fine. I believe that it was an issue with the old version of the DLL. I'll leave this here in case anyone else has this issue.

Categories

Resources