Xamaria.form InitializeComponent does not exist in this context - xamarin.forms

Mainpage.xaml.cs
Mainpage.xaml
Anytime i run the application i got error code
The name 'InitializeComponent' does not exist in the current context

Related

ContentPage constructor called before AppStart

I thought AppStart would be a good place to put some app initialization, particularly for HttpClient, so that it would execute before any app views were created.
However, in the debugger, I see that my view ContentPage constructor is called before AppStart.
Where should I be doing global initialization, such as this?

Visual Studio 2019 cannot view static variables defined at App level in Watch window

I have a Xamarin Forms app in Visual Studio 2019 and I have several static class variables defined in the App.xaml.cs file. I use these variables through out my application. However, when I am on a page of my app and add a property of the Static Class variable to the watch window, I receive the error message:
Watch Window Entry:
App.gvm_WaitingList
Error:
error CS0103: The name 'App' does not exist in the current context.
This makes it very hard to debug when I cannot see the values of properties in these static classes. Here is how the variable is defined in the App.xaml.cs
public static VM_WaitingList gvm_WaitingList;
and then I initialize it in the App constructor as follows:
gvm_WaitingList = new VM_WaitingList();
In searching for a solution I did find talk about the immediate window and adding global:: before the item I want to watch. However, when I do that I get the following error:
Watch Window Entry:
global::App.gvm_WaitingList
Error:
error CS0400: The type or namespace name 'App' could not be found in the global namespace (are you missing an assembly reference?)
Any ideas how to get this to work?
I finally found a way to see these variables. If I prefix the variable in the watch window with the namespace, it will resolve the variable in the watch window. Here is the solution that fixed my problem:
(NOTE my namespace is UniversalCheckInHost)
Watch Window Entry:
UniversalCheckInHost.App.gvm_WaitingList
I hope this helps someone else.

"WebSecurity" does not exist in the current context error in _AppStart.cshtml

I am getting the following compilation error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'WebSecurity' does not exist in the current context
Source Error:
Line 1: #{
Line 2: if (!WebSecurity.Initialized)
Line 3: {
Line 4: WebSecurity.InitializeDatabaseConnection("AreaProject", "User", "UserId", "EmailAddress", autoCreateTables: true);
Source File: c:\Projects\area\trunk\dotNet\area.Web\area.Web\_AppStart.cshtml Line: 2
enter code here
My project is correctly referencing to "System.Web" and my other files that are using " System.Web.Security" are compiling fine.
The problem started when I added the references System.Web, System.Web.Pages and System.Web.Razor to my application. But I didn't make any change to WebMatrix.WebData or WebMatrix.Data.
The WebSecurity class that is being referenced here is apart of WebMatrix.WebData and not System.Web or System.Web.Security. You probably need to add a reference to WebMatrix.WebData.dll and things should at least get past the runtime compiler error.
You get the compiler error at runtime because views are normally compiled when the application starts up for the first time, instead of when the assemblies are complied.
I'm assuming you are trying to run the MVC4 application first time.
MVC4 adds boatload of assembilies for Internet Application template. It becomes PIA to remove them if you do not use it.
Basically, if you do not use WebMatrix or OAuth to authenticate, you can just comment out everything inside SimpleMembershipInitializer class.
private class SimpleMembershipInitializer
{
// Comment out everything
}
Just for testing, you can also comment out every line inside AccountController that throw exception.
Old thread, but just in case it helps someone down the road. I am not sure why it works this way, but sometimes installing packages like WebMatrix.WebData, WebMatrix.Data is not enough. When I look at the Reference section of my application after these assemblies were installed, WebMatrix.WebData, WebMatrix.Data were still not showing up there, although they were in the BIN folder of the application. I had to literally use Add Reference to make them. Only then, they shown up and everything started working.

eventlog not working in an asp.net application

from an ASP.Net 3.5 web application, I'm trying to log messages to the Windows EventLog.
I first tried with the EntLib Logginh block, but when this failed I tried with the EventLog class directly. It failed too. They do not throw any exception... the just don't write the message. EntLib did write the message to a file, but not to the Windows EventLog.
Here is my code:
public static void LogMessage(string title, string message){
//EventLog log = new EventLog();
//log.Source = LOG_SOURCE;
//log.WriteEntry(message, EventLogEntryType.Error);
//EventLog.WriteEntry(LOG_SOURCE, message);
LogWriter writer = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
writer.Write(message);
}
I create the log & source in an installer class. Let me know if I should place that code here. The log is created correctly, since I can see it in the EventViewer. The source is created correctly, since I can see it in the "EventLog\MyLog" folder at the regedit.
I've been reading and there is an article stating following line could help:
EventLogPermission perm = new EventLogPermission(EventLogPermissionAccess.Administer, ".");
perm.PermitOnly();
but it didn't.
If it helps, my code structure is as follows:
Class library project (here is the LogMessage method)
Class Library project (here are the methods which catch exceptions and call LogMessage)
ASP Net web application project (web pages. This layer calls layer #2. Here is my installer class too)
Web setup project (this has custom actions pointing to web setup project output)
Could you please help to figure out what's happening???
Thanks
I found the following resource: "http://www.netframeworkdev.com/net-base-class-library/trouble-writing-to-eventlog-16723.shtml", so it seems it is not possibly to create custom logs from ASP... still investigating
Try giving the Network Service account the appropriate permissions

WPF XAML namespace refactoring

Consider a ViewModel and a View that uses it, where the DataContext is set to the VM in the code behind file.
When they are both at the project namespace, the view runs without exceptions with binding statements along the lines of:
ItemsSource="{Binding Path=PrefixFilterChoices}"
where PrefixFilterChoices is a property on the VM.
When I refactor the project so that ViewModels and Views are each in their own namespace within the project, I now get a runtime error:
(System.IO.IOException' occurred in PresentationFramework.dll, cannot find the resource projectView.xaml).
1) I can't figure out who is looking for the resource though, so I'm not sure what the fix is. The code behind is still setting the DataContext and it has the new namespace for the ViewModel. Must I add it to the XAML also? Must I alias it and now qualify the Path for all of the bindings?
2) I use resharper, which has always been spot on the money at refactoring namespace changes; but it isn't helping even a little with the XAML. Are there any tools that do better XAML refactorings?
Cheers,
Berryl
Part of the answer is that refactoring the namespace affected the application StartupUri. I couldn't get the format right in the xaml so I just set the MainWindow in an application startup event.

Resources