2

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.

6
  • Can you enable verbose xcode output and paste it somewhere? Mar 25, 2011 at 1:40
  • Will do - what level of verbosity are you after? Mar 26, 2011 at 3:20
  • Enough to contain the full commandline args for the C# compiler. Mar 27, 2011 at 4:16
  • @mhutch - here it is: lexim.com.au/downloads/shimms/build.txt Mar 27, 2011 at 7:38
  • Unrelated to this issue, I re-installed OS X on a new drive yesterday. After installing 2.10.1 and a MD head build, the same code checkout builds without issue. I'm wondering if this had something to do with a few different versions of Mono being installed/uninstalled/upgraded/downgraded over time. Mar 27, 2011 at 23:51

2 Answers 2

6
+150

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.

1
  • 1
    Thanks - sometimes the most obvious things are the most elusive. Mar 28, 2011 at 23:36
1

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.