2

When using the Request.ToHttpRequestData() method that SustainsSys defines as an extension method on HttpRequestBase, I get the following compilation error:

error CS0121: The call is ambiguous between the following methods or properties: 'Sustainsys.Saml2.HttpModule.HttpRequestBaseExtensions.ToHttpRequestData(System.Web.HttpRequestBase)' and 'Sustainsys.Saml2.HttpModule.HttpRequestBaseExtensions.ToHttpRequestData(System.Web.HttpRequestBase)

Why is this happening and how can I fix it?

Elroy Flynn
  • 3,032
  • 1
  • 24
  • 33

1 Answers1

2

You'll see this error if your project references both the Saml2.Mvc assembly and the Saml2.HttpModule assembly. That's because both assemblies define the same extension methods. This is an invalid condition - C# (dotnet) doesn't support multiple in-scope definitions of the same extension method. You are apparently not meant to use both Saml2 assemblies in one project.

I had an additional problem because I thought that I could only use the extension method from Saml2.HttpModule. If I didn't reference the Saml2.HttpModule, it seemed that the extension method was not available. (No autocompletion, would not compile.)

The reason for that problem is that even though the Saml2.Mvc module generally uses the namespace "Sustainsys.Saml2.Mvc", it defines the extension methods in namespace "Sustainsys.Saml2.HttpModule". That's because it's actually including the same source code file, "HttpRequestBaseExtensions.cs", that is used in the HttpModule project. So, inside the Saml2.Mvc assembly, you have a bit of Saml2.HttpModule namespace. Therefore, you need

using Sustainsys.Saml2.HttpModule;

even though you aren't including HttpModule as an assembly reference. Without that using statement, .net doesn't expose the extension methods.

Confusing, but it all works out once you know.

Addition (by library author)

Inititally the MVC package referenced the HttpModule. That turned out to be confusing because people where adding the MVC package and then loading the HttpModule causing conflicts. So I changed it into a simple source-file-reference. Since the intention is that those two libraries should never be used together. But obviously this is also confusing.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
Elroy Flynn
  • 3,032
  • 1
  • 24
  • 33