Cannot build project using Mono for Android - c#

When i try to build and run my project i get the following build errors:
HourScreen.cs(13,13): Error CS0433: The imported type `System.Net.WebRequest' is defined multiple times (CS0433)
HourScreen.cs(17,17): Error CS0433: The imported type `System.Net.WebResponse' is defined multiple times (CS0433)
The lines on which the errors happen look like this:
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
I include the following into the project:
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Text.RegularExpressions;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Preferences;
using Android.Graphics;
I think one of the includes must be playing up but i have no idea which. Removing one causes a huge load of other errors. Can anyone see where im going wrong?
EDIT:
I've included the build log: http://pastebin.com/FrmzfhcY

HourScreen.cs(167,17): error CS0433: The imported type `System.Net.WebResponse' is defined multiple times
/Developer/MonoAndroid/usr/lib/mono/2.1/System.dll (Location of the symbol related to previous error)
/Mono for Android/Bups_Urenverantwoording 1.0/Bups_Urenverantwoording/bin/Debug/System.Net.dll (Location of the symbol related to previous error)
The log has your answer. Mono for Android provides it's own System.Net stack in System.dll but you're also including other assemblies, like System.Net.dll which includes the same type.
Since you also reference System.Windows.dll I assume you're trying to include some code from Silverlight (or Moonlight) and that won't work. At least not for for System.Net.dll (not sure what you're trying to use from System.Windows.dll).

Related

Using Serilog for Blazor Server solution -> "IHostBuilder does not contain a definition for 'UseSerilog'

I am trying to implement Serilog for my Blazorserver project.
First and foremost, i follow the instructions as described in the link https://www.c-sharpcorner.com/article/log-data-into-file-using-serilog-framework-in-blazor-server-app/.
In this instruction the following lines appear in the second code block:
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
Where the line .Useserilog() is newly added. The precompiler now throws the following error message:
"IHostBuilder does not contain a definition for 'UseSerilog'
I have added using Serilog and
using Serilog.Events in the Program.cs file (all "usings" are listed here):
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Serilog.Events;
Does anyone have any idea what could be causing the problem? Thanks!
UseSerilog is an extension method in the Serilog.Extensions.Hosting namespace so you will need to import that:
using Serilog.Extensions.Hosting;
You may also need to add the Serilog.Extensions.Hosting Nuget package.

WPF WebHostBuilder does not contain definition for UseKestrel

I am trying to implement single sign on using OIDC as per GitHub but I keep getting the error:
'WebHostBuilder' does not contain a definition for 'UseKestrel' and no accessible extension method 'UseKestrel' accepting a first argument of type 'WebHostBuilder' could be found (are you missing a using directive or an assembly reference?)
when implementing the SystemBrowser.cs code
using IdentityModel.OidcClient.Browser;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//other code
//simplified code extract below
IWebHost _host = new WebHostBuilder()
.UseKestrel()
.UseUrls(_url)
.Configure(Configure)
.Build();
//other code
According to this it should be part of the Microsoft.AspNetCore.Hosting?
Is there something I'm missing or a NuGet package I need installing? The packages installed so far are:
Any assistance would be appreciated.
The default asp.net core application could work well because the Microsoft.AspNetCore.Hosting package and other related package integrated in the framework.
I test a console application with asp.net core and reproduce your issue.Install the Microsoft.AspNetCore.Hosting together with Microsoft.AspNetCore.Server.Kestrel.
You could download on NuGet Package Manager by searching for the package name or download on Package Manager Console by using the command in the following reference:
https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/2.2.0?_src=template

How to reference Cosmos table API from within azure function?

I'm trying to compile a project I've written in C# script, in the azure portal(can't get any other environment to work).
I'm trying to reference the cosmos table API within my function:
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
#r "Microsoft.Azure.WebJobs"
#r "Microsoft.Azure.WebJobs.Extensions"
#r "Microsoft.Azure.WebJobs.Extensions.Storage"
#r "Microsoft.Azure.Cosmos.Table"
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.Bindings.Runtime;
using Microsoft.Azure.Cosmos.Table;
But it gives me the following error:
[Error] run.csx(6,1): error CS0006: Metadata file 'Microsoft.Azure.Cosmos.Table' could not be found
2019-09-26T13:50:37.115 [Error] run.csx(14,23): error CS0234: The type or namespace name 'Cosmos' does not exist in the namespace 'Microsoft.Azure' (are you missing an assembly reference?)
How can I make azure function find the reference?
This namespace is not included in Azure function. You need to add the dll file to Azure function app by yourself. Refer to this article for the detailed steps.

Parse error in ASP.NET web forms application

Four time in four days in four different projects I have received the following error (except different for project name). The projects all work fine while I am building the first couple of forms and then I go to lunch, go home overnight, etc. and then suddenly they throw this error. This last time, all I did was walk away for five minutes to take a leak.
How do I fix and prevent this? I am very new to ASP.NET, so don't know much on how to fix errors of this sort.
Parser Error
Description: An error occurred during the parsing of a resource
required to service this request. Please review the following specific
parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'PathCertLink.Global'.
Source Error:
Line 1: <%# Application Codebehind="Global.asax.cs"
Inherits="PathCertLink.Global" Language="C#" %>
Source File: /global.asax Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.6.1055.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;
using System.Data.Entity;
using PathCertLink.Models;
using PathCertLink.Logic;
namespace PathCertLink
{
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// Initialize the database.
Database.SetInitializer(new ProductDatabaseInitializer());
// Create the custom role and user.
RoleActions roleActions = new RoleActions();
roleActions.AddUserAndRole();
}
}
}

Why does WebRequestMethods not exist in the current context?

I'm using Visual Studio 2012 and playing around with Windows Phone 7.1 application development. This is a newly-created project.
When I use this code, why do I get this error?
The name 'WebRequestMethods' does not exist in the current context
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
...
public MainPage() {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Method = WebRequestMethods.Http.Post;
}
...
It seems like it can't recognise that WebRequestMethods is a part of System.Net. It also fails if I specify System.Net.WebRequestMethods.Http.Post.
System.Net.WebRequestMethods.Http isn't available in the .NET Profile for Windows Phone, though it may not be readily apparent depending on which documentation page you're looking at. Just set it to the string value "POST".
I have some additional context in my blog article: Windows Runtime-What's supported Where?

Categories

Resources