CS0433: Ambiguous Reference System.Net.Http.HttpRequestMessageExtensions - c#

I am using VS2015 with Resharper for WebAPI 2.0 project. Trying to use System.Net.Http.HttpRequestMessageExtensions.GetRequestContext gives me an error saying
Error CS0433 The type 'HttpRequestMessageExtensions' exists in both 'System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
I've tried editing web.config to read
<compilation debug="true" targetFramework="4.5.1" batch="false" />
Also as suggested in numerous posts - restarted visual studio, clear resharper cache, rebuild the solution.
Nothing helps and I am still seeing this error. Any other suggestions?

You need to use a “extern alias” to manage two classes with the same namespace.
First, define de name of your custom alias in the properties of the assembly:
Then, in the code:
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
extern alias Alias1;
extern alias Alias2;
using namespace1 = Alias1::System.Net.Http.HttpRequestMessageExtensions;
using namespace2 = Alias2::System.Net.Http.HttpRequestMessageExtensions;
public class HomeController : Controller
{
public void Test()
{
// ...
namespace1.GetRequestContext(request);
//namespace2.GetRequestContext(request); // error
}

Related

Dnspy compilation error without editing the code

The 'ConnectionState' exists in both 'System.Data.Common, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
bool flag2 = this.sqlite_conn.State != ConnectionState.Open;
if (flag2)
{
this.sqlite_conn.Close();
this.sqlite_conn.Open();
}
Getting above error in this line of code while using dnspy.
Error code is CS0433 from main.cs
Check your project references and using statements and remove any unused ones.
Try to explicitly put the proper namespace in front of your enum, like:
System.Data.ConnectionState.Open;

Xamarin error cs0263 partial declarations must not specify base classes

I have already looked to similar answers and I don't know why I am still have this error:
Severity Code Description Project File Line Suppression State
Error CS0263 Partial declarations of 'MainPage' must not specify different base classes MyNavDraw.Android (my path ...)\MainPage.xaml.cs 13 Active
MainPage.xaml.cs:
namespace MyNavDraw
{
public partial class MainPage : MasterDetailPage
{
...
MainPage.xaml
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyNavDraw"
x:Class="MyNavDraw.MasterDetailPage">
<MasterDetailPage.Master>
...
What I tried so far:
In xaml I have replaced the tag to:
<we:MainPage ...
I checked "x:Class" and I think is correct the syntax, I have restarted the VS and I built again the solution.
I use Xamarin with VS 2017.
After a day (from this post question) I tried to put in comments the code of "MainPage.xaml" file. Then I saved it, I removed comments, saved it again and built the solution. I have a new error in built:
No way to resolve conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Choosing "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" arbitrarily.
I have an other problem when I debug the app to my physical phone (android).
In My.Nav.Draw.Droid.MainPage.xaml.g.cs I have an exception Unhandled error.
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(MainPage));
What can be wrong?
Try adding your project name before the namespace name, also update your xmlns:local line too:
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyProjectName.MyNavDraw;assembly:MyProjectName"
x:Class="MyProjectName.MyNavDraw.MasterDetailPage">

The type 'Expando' is defined in an assembly that is not referenced

I'm getting the following compile error:
The type 'Expando' is defined in an assembly that is not referenced.
You must add a reference to assembly 'Westwind.Utilities, Version=2.64.0.0,
Culture=neutral, PublicKeyToken=6f7d66a3bb7de652'.
The thing is, I have a reference to that version of the assembly... I think the problem is due to a class library.
My ClassLibrary has the following class:
public class Generic_AnswerFile : Expando { ... }
and my Test Console has the following class:
public class Specific_AnswerFile : Generic_AnswerFile { ... }
The Specific_AnswerFile will not compile. Any ideas why? Both projects are .Net 4.0 and have references to the correct .Net 4.0 version of Westwind.Utilities 2.64
The type Expando is defined in his assembly
that means only in the GAC. though you have reference to it.. but it would fail to load. To load it properly you need to define it in your config file under assembly tag
<add assembly="Expando, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]"/>

SQLite3 Connection Causes Confusing Compile Error

I am attempting to compile my Xamarin project and I am getting a compiler error that I dont understand. What does the following error mean and how can i fix this?
Data\SQLiteClient.cs(4,4): Error CS0012: The type 'System.Threading.Tasks.TaskScheduler' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (CS0012) (DtoToVm.Droid)
Relevant information:
Xamarin Forms blank project PCL
Project set to .NET 4.5 or later
Profile: PCL 4.5 - Profile78
Alot of references are not happy but I haven't manually setup or editted these. Maybe a nuget package conflict?
using Xamarin.Forms;
using DtoToVm.Droid.Data;
[assembly: Dependency (typeof(SQLiteClient))]
namespace DtoToVm.Droid.Data
{
using System;
using DtoToVm.Data;
using SQLite.Net.Async;
using System.IO;
using SQLite.Net.Platform.XamarinAndroid;
using SQLite.Net;
public class SQLiteClient : ISQLite
{
public SQLiteAsyncConnection GetConnection ()
{
var sqliteFilename = "Conferences.db3";
var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var path = Path.Combine (documentsPath, sqliteFilename);
var platform = new SQLitePlatformAndroid ();
var connectionWithLock = new SQLiteConnectionWithLock (
platform,
new SQLiteConnectionString (path, true));
// The below line causes the compile error
var connection = new SQLiteAsyncConnection (() => connectionWithLock);
return connection;
}
}
}
Edit:
According to this thread I shd change the profile to 7. I've done this and it got rid of all errors but produced a new one:
DtoToVm\packages\Microsoft.Net.Http.2.2.29\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll: Error CS1703: An assembly with the same identity 'System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' has already been imported. Try removing one of the duplicate references. (CS1703) (DtoToVm)
What file could this duplicate reference be in?
I don't really know if System.Threading.Tasks namespace exists in Xamarin or not, If it's exists then reference it, If not then use the regular SqliteConnection and don't use Async one.

Is the combination of ADO.NET Entity Framework and ASP.MVC wrong by any chance?

I have one solution with three projects.
DomainModel (C# Library with ADO.NET Entity Framework)
DomainModelTest (Unit Testing for Business Logic)
WebApp (Using DomainModel)
For some reason, I cannot even bring the view if I pass any of the objects in the DomainModel, not even simple. I get the error below:
Any ideas?
Compiler Error Message: CS0012: The
type
'System.Data.Objects.DataClasses.EntityObject'
is defined in an assembly that is not
referenced. You must add a reference
to assembly 'System.Data.Entity,
Version=3.5.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
Source Error:
Line 146: Line 147:
[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 148: public class
views_home_index_aspx :
System.Web.Mvc.ViewPage,
System.Web.SessionState.IRequiresSessionState,
System.Web.IHttpHandler { Line 149:
Line 150: private static bool
#__initialized;
I thought this might be helpful, the actual error comes up on the Default.aspx file in the line pointed below:
public partial class _Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
// Change the current path so that the Routing handler can correctly interpret
// the request, then restore the original path so that the OutputCache module
// can correctly process the response (if caching is enabled).
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current); //**HERE**
HttpContext.Current.RewritePath(originalPath, false);
}
}
Try adding the reference in your web.config, in the < assemblies > section.
In web.config Add this
<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
</system.web>
</configuration>
You can also add an empty ADO.NET Entity Data Model to your web-project, and then delete it. It will add the necessary references for you.

Categories

Resources