I have UWP app that I use Frame.Navigate() method a lot. By default it seems to be performing transitions with an animation that makes next screen appear sliding from bottom. However, for my case it makes more sense if next screen comes from right or left.
So, to change this default behaviour, I used the following code from this MSDN document:
// Navigate to the right, ie. from LeftPage to RightPage
myFrame.Navigate(typeof(RightPage), null, new SlideNavigationTransitionInfo() { SlideNavigationTransitionEffect.FromRight } );
// Navigate to the left, ie. from RightPage to LeftPage
myFrame.Navigate(typeof(LeftPage), null, new SlideNavigationTransitionInfo() { SlideNavigationTransitionEffect.FromLeft } );
but I get this error:
Cannot initialize type 'SlideNavigationTransitionInfo' with a
collection initializer because it does not implement
'System.Collections.IEnumerable'
Changing code like this
myFrame.Navigate(typeof(RightPage), null, new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight } );
causes app to crash by Invalid cast exception.
This was an old app that I'm updating so I suspected that might cause the issue and I updated the target version. Now targetting section looks like:
Target version: 1809 (10.0; Build 17763);
Min version : (10.0; 10240)
but still, problem persists.
Any idea how to solve this?
The first syntax error is quite self-explanatory; while the InvalidCastException seems to be caused by the fact that you are running you code on an OS with a version lower than 1809.
SlideNavigationTransitionEffect Enum was added in 1809. You can compile your code successfully because you have installed the SDK for 1809, but at runtime, if you don’t check beforehand, this code fails if runtime doesn’t support it.
//remove this from your code and it should be running well
Effect = SlideNavigationTransitionEffect.FromRight
In this case, you can set the Min version as 1809, to enforce this app can only be installed on 1809 or higher. Or you can write version adaptive code to check the OS support for the API, in this way, you can keep you Min version as low as desired to target a wider range of devices.
If you prefer , You can simply use XAML page transitions, its also compatible with min version 10240:
just put below lines in your RightPage or LeftPage XAML source.
<Page.Transitions>
<TransitionCollection>
<EdgeUIThemeTransition Edge="Left">
</EdgeUIThemeTransition>
</TransitionCollection>
</Page.Transitions>
Related
Since I switched to VS 2019 (from 2017) I am pretty sure I got a degraded IntelliSense experience. I looked for settings under Tools -> Options... but did not find anything helpful.
The matter is this: suppose I have a variable kvp that has a property Key, I could type "key.", scroll to the "Key" property (if this is not already selected) and then type ";" to complete the statement.
But this does not work anymore. Instead it now ignores what I selected and I get
key.;
The only way to get the selected property is to explicitly hit enter. Same when I type the first character(s) to select the desired option: when pressing ; it just leaves what I already typed and adds the ; immediately behind it, ignoring what I selected in the popup menu.
What happened and how do I get the proper behavior back?
I am using the Preview version but I already had a couple of updates and it does not improve so I guess it is by design or default behavior now.
Here's some of my code for Perry. It is just an example though, the problem (or what I regard to be a problem) occurs with any object variable.
private static void AddBlockNodes(TreeNode node, IDictionary<string, Block> blocks)
{
foreach (KeyValuePair<string, Block> kvp in blocks)
{
string name = kvp.Key;
Block block = kvp.Value;
TreeNode childNode = new TreeNode(name);
childNode.Tag = block;
node.Nodes.Add(childNode);
AddBlockNodes(childNode, block.Subblocks);
}
}
it just leaves what I already typed and adds the ; immediately behind
it, ignoring what I selected in the popup menu.What happened and how
do I get the proper behavior back?
It is quite an abnormal behavior and l have installed Visual Studio 16.6.0 Preview 2.1 and test your code in my side and it works well.
Type variable kvp. and then select property Key and it types as expected. I did not face missing property Key during the process.
You can try these steps to troubleshoot your issue:
Suggestion
1) reset all settings by Tools-->Import and Export Settings-->Reset all settings
2) close VS Instance, enter the project path and delete .vs hidden folder which stores some Intellisense settings, bin, obj folder and then restart your project again. I wonder if you migrate an old project into VS2019 preview version, I think you should complete this step.
3) disable any third party extensions if you have under Extensions-->Manage Extensions in case they cause this behavior.
4) delete all component caches under C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxx(16.0 is VS2019)\ComponentModelCache
5) try to create a new project in VS2019 Preview version and test whether this issue persists in the new platform and if it works, I think it is an issue of your project itself. Or you can try to migrate your project into the new project.
Hope it could help you.
I used to work on an Android/Xamarin project for Android 4.4, API Level 19 that contains an activity with the following code:
private void RadioButtonClick(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
switch (rb.Id)
{
case Resource.Id.radioButton1:
...
The last time I looked at the project a couple of month ago, this used to work just fine. Now I want to continue working on the project for Android 8.0, API Level 26, but when I opened it in Visual Studio 2017 I got the compiler error (field)int ResourceId.RadioButton1 A constant value is expected.
Now this is not a problem in itself, as I can always use if (rb.Id == ...) instead of switch/case, but I would like to know why all of a sudden Resource.Id.radioButton1 is not recognized as a constant anymore, even though it is declared as such in Resource.Designer.cs:
public const int radioButton1 = 2131165244;
Has anyone else encountered something similar?
EDIT: Even stranger is that the project builds without complaint, but deployment is not possible due to the said error.
EDIT: It seems that the build process generates another Resource.Designer.cs file which is put into a folder obj\Debug\designtime. Once the file exists, the activities source code refers for the Id declarations to this new file and not to the original Resource.Designer.cs in the Resources folder.
However, all Ids in the new file are static and not const (which of course is the reason for the compiler error that prompted this question in the first place) and moreover they are all set to zero.
Are there any Android/Xamarin experts out there who can explain what is going on here? Might that even be a bug in Visual Studio 2017/Xamarin?
EDIT: Here is a link shedding some light on this topic: https://forums.xamarin.com/discussion/19369/compiling-resource-ids-static-vs-const
What I don't get is this: Why did the above code work at all considering that this problem is known since 2014?
I am trying to add a MapIcon to my Bing maps control. When I am running the application in my debugging environment on visual studio I don't have any issues. However once I build my app package and run it, adding a map Icon crashes the application and throws this an exception that reads:
"Unable to cast object of type Windows.UI.Xaml.Controls.Maps.MapIcon to type Windows.UI.Xaml.Controls.Maps.IMapElement4"
Here is the simple code that instantiates the MapIcon. It is important to know that I do not have any issues adding these map Icons in debug mode. The problem only exists once the app package has been built and run. I was able to pinpoint the exception using a try/catch to display the exception while the released app is running. If anyone can help me to get rid of this exception, or have any advice for a work around, it would be much appreciated
MapIcon messageicon2_2 = new MapIcon
{
Location = message_position,
NormalizedAnchorPoint = new Point(0.5, 1.0),
ZIndex = 0,
Title = "msg " + count + "(2.2)",
IsEnabled = true,
CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible
};
MyWaypoints.Add(messageicon2_2);
messageLayer.MapElements = MyWaypoints;
[EDIT To Clarify]: I know that this bug is coming specifically from the instantiation of the Mapicon. This code works perfectly fine when it is released and run on a Windows 10 17134 machine.... The machine that I need it to run is Windows 10 16299. This machine can not be updated to a newer version of windows. I am in need of a way to display these map icons on this older release of windows.
The exception points to the IsEnabled property which was added to MapElement for Windows OS Version 1803 (17134). See MapElement.IsEnabled Property.
I know the exception is not the most helpful, but maybe there was some other warning about it that got missed?
For errors like this, you can either remove all uses of the missing API and/or make sure to write version adaptive code that can run on the lowest OS version, while also taking advantage of the selected features that are available only on certain OS versions.
Specifically you can do something like:
var messageicon2_2= new MapIcon
{
Location = message_position,
NormalizedAnchorPoint = new Point(0.5, 1.0),
ZIndex = 0,
Title = "msg " + count + "(2.2)",
CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible
};
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Maps.MapElement", "IsEnabled"))
{
messageicon2_2.IsEnabled = true;
}
MyWaypoints.Add(messageicon2_2);
messageLayer.MapElements = MyWaypoints;
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.
This is my code that throws an exception, it just randomly started today here is the photo :
Here is the whole page code and the error exception :
public frmWFDocumentDetail()
{
InitializeComponent();
NavigationInTransition navigateInTransition = new NavigationInTransition();
navigateInTransition.Backward = new TurnstileTransition { Mode = TurnstileTransitionMode.BackwardIn };
navigateInTransition.Forward = new TurnstileTransition { Mode = TurnstileTransitionMode.ForwardIn };
NavigationOutTransition navigateOutTransition = new NavigationOutTransition();
navigateOutTransition.Backward = new TurnstileTransition { Mode = TurnstileTransitionMode.BackwardOut };
navigateOutTransition.Forward = new TurnstileTransition { Mode = TurnstileTransitionMode.ForwardOut };
TransitionService.SetNavigationInTransition(this, navigateInTransition);
TransitionService.SetNavigationOutTransition(this, navigateOutTransition);
DataContext = App.ViewModel_WFDocumentDetailItems;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//**this is how you pass parameters through to a new page**//
string processID = "-1";
string processName = "";
NavigationContext.QueryString.TryGetValue("processID", out processID);
NavigationContext.QueryString.TryGetValue("processName", out processName);
App.ViewModel_WFDocumentHeaderItems.LoadData("johnny", processID);
App.ViewModel_WFDocumentDetailItems.LoadData("johnny");
}
and the access violation :
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory
is corrupt.
I have read up on it, some people say it is nvidia network manager, and some people say I must set some setting like Suppress JIT optimization , and ignore gpu memory if value isn't changed... but nothing works? Can anyone please please send me in the right direction?
As requested , the full stack
i used the setting taylorjohnl gave me "Debug -> Options and Settings -> Debugging -> General -> Enable Just My Code",and then the error went right to the piece of xaml that was a syntax error, and boom fixed it and app works again :) so violation error for me was basically a reference error, hope this can help other people as well, also use expression blend in silverlight to debug xaml in the UI
I had a similar problem which in the end was resolved by submitting crash dump to MS Tech Support. Here is their response:
The gist is that The crash is a known bug in the version 5.0 of comctl32.dll (Windows Common Controls), which ships with the Windows OS. This bug will not be fixed in version 5.0 of the common controls, because that version was for applications existing prior to Windows XP. It has since been fixed in version 6.0 of comctl32.dll, which is included with Windows XP and later. Note that both versions of comctl32.dll (5.0 and 6.0) are included with every version of Windows since Windows XP. The older one is just there for backwards compatibility purposes for very old applications.
To resolve the problem, you need to change the application to have it opt into version 6.0 of comctl32.dll. Within a Windows Forms application, this is done by calling into the Application.EnableVisualStyles method at startup of the application. If you are developing within a C# project, then you can do this by adding the call prior to your Application.Run call within your application's entry point. For example:
[STAThread]
static void Main()
{
Application.EnableVisualStyles(); //Add this line
Application.Run(new Form1());
}
If you are in a Visual Basic .Net project, you can opt into this by going to your project properties, and then selecting the "Enable Application Framework" and "Enable XP Visual Styles" checkboxes on the Application property page.
Once you do this, it should resolve this particular access violation.
what is code in the InitializeComponent()? there is some class refer to null in it, (mostly is a event handler). once it is trigger, it will report AccessViolation.