Pergunta

Having an issue where compiling some code that makes use of HttpContextBase is throwing the compile error:

UserService.cs(13,26): error CS0433: The imported type `System.Web.HttpContextBase' is defined multiple times

The offending line is:

private readonly HttpContextBase httpContext;

If I take that line of code out, or comment it, the error goes away and the assembly compiles.

In another project (the test project for this one) the same error occurs when trying to declare a HttpContextBase to pass to the constructor of this object. So it appears to be a cross-project issue.

Is this a project file issue? (Can't find more than one reference to System.Web in there). It was compiling before I made some changes to the AfterBuild step, so I'm concerned I've messed something up in the csproj file.

This is building with Mono 2.10.1, using monodevelop trunk build set to use xbuild to compile.

Compiling using the default Monodevelop build behaviour does not produce this error.

Foi útil?

Solução

Tthe type System.Web.HttpContextBase was defined in System.Web.Abstractions.dll in .NET 3.5 SP1, but in System.Web.dll in .NET 4.0. That means that compiled dlls with references to the type in System.Web.Abstractions.dll would be "type forwarded" to System.Web.dll.

You seem to have a local copy of System.Web.Abstractions.dll in /Users/shimms/Development/convergence/lib/System.Web.Abstractions.dll, probably the .NET 3.5 version, which would conflict with the 4.0 System.Web.dll.

Outras dicas

This issue happens when you are referencing a type which is defined in multiple classes. To fix this you can edit your reference and uncheck one of the dll's which is causing the issue.

When you hover over the error in Visual Studio/Xamarin, it will display the multiple references name in which this type exist. Just check and include only one reference or class.

Below are the screenshot for your reference.

enter image description here

After fixing the issue:

enter image description here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top