'AuthenticationBuilder' does not contain a definition for 'AddMicrosoftIdentityWebApp' - azure-active-directory

I'm attempting to add support for Graph into a .Net 6 application. I've previously used Graph in a .Net 5 application but I'm having some trouble understanding how to wire things up using the .Net 6 "simplified" startup.
I've included both:
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
in the header of Program.cs but I'm getting an error with AddMicrosoftIdentityWebApp in the following:
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
The error I'm getting is:
Error CS1061 'AuthenticationBuilder' does not contain a definition for 'AddMicrosoftIdentityWebApp' and no accessible extension method 'AddMicrosoftIdentityWebApp' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)
I'm fairly sure that I'm overlooking something pretty simple, but I cannot find it.
Any suggestions are much appreciated.

Thanks for the response.
As it turns out, I found that the problem was with an incorrect package being installed. I had included Decos.Microsoft.Indentity.Web in the packages for the solution. I suspect that there were some collisions occurring here. Once I removed the package the error no longer manifests itself.

"Error CS1061 'AuthenticationBuilder' does not contain a definition for 'AddMicrosoftIdentityWebApp' and no accessible extension method 'AddMicrosoftIdentityWebApp' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)"
To resolve the above error, please try the below suggestions if helpful:
When you are including Microsoft.Identity.Web, Microsoft.Identity.Web.UI packages, these libraries are used to simplify the process of signing-in a user and acquiring tokens for Microsoft Graph.
Try modifying your configured services method by removing the prefix builder like below:
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
To sign-in a user for your application with Microsoft identity platform endpoint AddMicrosoftIdentityWebApp() is used.
EnableTokenAcquisitionToCallDownstreamApi() and AddMicrosoftGraph adds support to call Microsoft Graph.
Otherwise, If you want to use builder, make sure to add the package using Microsoft.AspNetCore.Identity and define the builder as below:
var builder = WebApplication.CreateBuilder(args);
For more in detail, please refer below links:
active-directory-aspnetcore-webapp-openidconnect-v2/README.md at master · Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2 · GitHub.
Configure ASP.NET Core Identity | Microsoft Docs.

Related

Unable to generate flows from RAML in Anypoint Studio

I am getting an error when I attempt to import a local RAML API definition into Mulesoft, it gives a very vague error that the API definition file exists and that API Kit is pointing to it.
This is the error message I get
The project is targeting Mule 4.3.0, and the version of Anypoint Studio is 7.11.1.
In order to get this error I am right-clicking and selecting Mule > Generate Flows from Local REST API, I have also tried Mule > Generate flows from RAML. Both give the same error result.
The XML for the APIKit is as follows
<apikit:config outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" doc:name="Router" doc:id="daffbcd4-325c-4911-a042-ca6e74e73970" name="ve-sys-moviesinformation-config" raml="ve-sys-moviesinformation.raml" api="api\ve-sys-moviesinformation.raml">
<apikit:flow-mappings >
<apikit:flow-mapping resource="/media/{movieId}" action="get" content-type="application/json" flow-ref="get:\media\(mediaId):ve-sys-moviesinformation-config" />
<apikit:flow-mapping resource="/media/{movieId}" action="post" content-type="multipart/form-data" flow-ref="post:\media\(mediaId):multipart\form-data:ve-sys-moviesinformation-config" />
</apikit:flow-mappings>
</apikit:config>
I have no idea how to resolve this issue, any help would be much appreciated.
I suspect that the problem is related to the APIKit configurations having manual mappings (ie <apikit:flow-mappings>), which is very unusual in my experience. The normal usage that the mappings are dynamically generated at runtime and are not explicit in the configuration. Unless there is a very specific reason there is no need for manual mappings.
Also some configurations seem to be deprecated. Maybe the configuration was created with an older version of APIKit, or even carried from the Mule 3 version which is not recommended.
Try commenting or removing the APIKit configuration and repeat the Generate Flows action in Anypoint Studio. It should automatically create a sane APIKit configuration along with the flows. You may need to do some refactoring of the existing flows, but seeing it is using only two flows it is not probably a significant effort.

Outlook Mobile Add-in manifest sample?

I was trying to add in the mobile part for the Outlook Add-in.
I have search the information in https://dev.office.com/docs/add-ins/outlook/manifests/add-mobile-support for the manifest to update for mobile.
However, for that, I am getting the following issue in return when trying to install from the Manage Add-in.
This app can't be installed.
The manifest file doesn't conform to the schema definition. The element 'OfficeApp' in namespace 'http://schemas.microsoft.com/office/appforoffice/1.1' has invalid child element 'VersionOverrides' in namespace 'http://schemas.microsoft.com/office/mailappversionoverrides/1.1'.
List of possible elements expected: 'DisableEntityHighlighting' in namespace 'http://schemas.microsoft.com/office/appforoffice/1.1' as well as 'VersionOverrides' in namespace 'http://schemas.microsoft.com/office/mailappversionoverrides' as well as any element in namespace 'http://www.w3.org/2000/09/xmldsig#'...
Since it does not really show us the manifest part for the OfficeApp tag or any other parts.
I wonder if there is any sample which shows the whole manifest for the mobile; I could only find the one for the Desktop.
I tried just update the VersionOverrides to newer version
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
and it failed too.
Is it even complete yet?
I tried just update the VersionOverrides to newer version
This is not what documentation says to do. I quote: "The MobileFormFactor element is defined in the VersionOverrides v1.1 schema, so you will need to include a VersionOverrides element both for v1.0 and v1.1." Please have a look on command-demo-manifest.xml eample.

What is the correct way to configure App.Config files when using wcf services

Let's say that I have a simple WPF or Winforms solution. To that solution I add a new project (based on a class library template , which I then reference in the main project) which is intended to be a data layer containing an entity framework data model. When I create the data model in the new project the connection string that it uses gets added to the app.config file of the main project in the solution.
Now let us say that I want to add two more projects to the solution (both of which will again be based on class libraries) to contain details of WCF services that I wish to use. In each case I add the WCF service by using the ADD Service Reference option from the right click context menu of the projects.
Unlike the data model project though the bindings for the service model get added to the local projects app.config file ass opposed to the app.config file of the main start-up project.
Should I simply copy those bindings to the start-up project's app.config file, or should I copy and then delete, or in fact should I be doing something completely different. Thus far trying combination of the first two suggestions I get error messages connected with endpoint configuration, however my knowledge of WCF is not really sufficiently good to fully understand the MSDN articles that the error list points me to.
Note that if the service references are added to the main project I get no errors whatsoever, so I figure this must be a configuration problem of some description.
Would anyone be able to provide the correct procedure for adding projects that essentially contain no more than a WCF service reference to an existing visual studio solution.
Edit
The screenshot below shows my main app.cofig file after having copied over the bindings configurations from the two service contracts. I'm not sure whether I should have commented out the bit that I did or not, I had thought that by doing so I might get rid of the blue squiggly underlines telling me the following (which I must admit to not understanding):
Warning The 'contract' attribute is invalid - The value 'ErsLiveService.IERSAPIService' is invalid according to its datatype 'clientContractType' - The Enumeration constraint failed.
You're likely getting the blue squigglies because the namespace ErsTestService is defined within the project in which you created the service reference. If the root namespace of that project is MyServiceReferenceProject then try changing the namespace to MyServiceReferenceProject.ErsTestService.IERSAPIService.

asp.net pages can use class library but site won't compile

I am using VS2012 Update 3 and have a solution containing three visual basic projects a class library, a conosole app, and an IIS website.
The website has a reference to the library project. The library compiles fine and automatically places the latest dll in the bin folder of the website.
This was all working without issue before this week.
My web pages are able to import and use the class library. I get proper intellisense and the pages browse or eventually browse showing they are using the library. This week sometimes I get a type not defined error with browsing but after waiting it works. But the compile is always a fail now.
When compiling sometimes the errors show in the error list then eventually disappear but at ALL times when building the errors show up in the output tab as:
SomeCodeBehindFile.aspx.vb(#,#) error BC30002: Type 'SomeTypeInMyLibrary' is not defined.
Error BC30002 - Type XXX is not defined did not help. I tried using fully qualified variable types versus using the import. I tried changing the identity on the app pool to Network Service which has read permission on the whole site.
I've also tried Visual Studio's build > Clean Solution and deleting all files from windows' framework Temporary ASP.NET Files.
The only thing I may have done to irritate VS would have been renaming one of my asp files and its class names/page directive attributes manually but I have done this before without issue. I got paranoid and deleted that file and re-added it also. I also have 3 pages complaining about types not being defined now.
Was really perplexed for awhile. It also got worse with the pages using the library permanently refusing to browse. Though if I copied the library and erroring pages in another web app it would work! Not knowing what went off the rails I started a fresh VB web site and was back in business for awhile but then it started again. I did not connect what I did that actually caused the grief in my 2nd site. For a 3rd time I started a fresh web site this time using C#. Going great again up until that point I kept shooting myself. Thankfully the C# compiler gave a more helpful error message: "A using namespace directive can only be applied to namespaces; 'StaffPlusLibrary' is a type not a namespace". Grrr the problem was I kept adding a help page to the site related to the class library and called the page StaffPlusLibrary.aspx. I am careful not to name pages the same as existing classes but it did not register in my mind I was about to create a page using the same name as my library's root namespace. So the page created a class using the same name as the namespace. The ambiguity I introduced was not apparent until C#.

What does this WCF error mean: "Custom tool warning: Cannot import wsdl:portType"

I created a WCF service library project in my solution, and have service references to this. I use the services from a class library, so I have references from my WPF application project in addition to the class library. Services are set up straight forward - only changed to get async service functions.
Everything was working fine - until I wanted to update my service references. It failed, so I eventually rolled back and retried, but it failed even then! So - updating the service references fails without doing any changes to it. Why?!
The error I get is this one:
Custom tool error: Failed to generate code for the service reference
'MyServiceReference'. Please check other error and warning messages for details.
The warning gives more information:
Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: List of referenced types contains more than one type with data contract name 'Patient' in
namespace 'http://schemas.datacontract.org/2004/07/MyApp.Model'. Need to exclude all but one of the
following types. Only matching types can be valid references:
"MyApp.Dashboard.MyServiceReference.Patient, Medski.Dashboard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
"MyApp.Model.Patient, MyApp.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" (matching)
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='ISomeService']
There are two similar warnings too saying:
Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='ISomeService']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='WSHttpBinding_ISomeService']
And the same for:
Custom tool warning: Cannot import wsdl:port ..
I find this all confusing.. I don't have a Patient class on the client side Dashboard except the one I got through the service reference. So what does it mean? And why does it suddenly show? Remember: I didn't even change anything!
Now, the solution to this was found here, but without an explanation to what this means. So; in the "Configure service reference" for the service I uncheck the "Reuse types in the referenced assemblies" checkbox. Rebuilding now it all works fine without problems. But what did I really change? Will this make an impact on my application? And when should one uncheck this? I do want to reuse the types I've set up DataContract on, but no more. Will I still get access to those without this checked?
I found my answer here: http://www.lukepuplett.com/2010/07/note-to-self-don-let-wcf-svcutil-reuse.html
Long story short: I unchecked Reuse types in reference assemblies from the Advanced menu.
I don't know if this matters but i'm not using MVC, but Web Forms.
When you add a service reference, there are two ways the types that are used by the service can be handled:
The types are stored in a dll, and that dll is referenced from both the client and the server application.
The types are not in a dll referenced by the client. In that case the tool that creates the service reference, will create the types in the references.cs file.
There are many things that can go wrong. We have found that if the tool crashes, it is sometimes faster to delete the service reference and start again.
We have stopped using service reference. For projects where we have control of the client and the service, we use the method described in this screencast.
I also had this issue Today. It took me one entire day to find my mistake. Hope it helps.
My class that weren't able to be imported has a cutom enum type property. This property is marked as DataMember and the Enum is also marked as DataContract. Everything fine so far.
I just forgot to mark every enum member as EnumMember.
So i changed
[DataContract]
public enum SortMethodType
{
Default = 0,
Popularity = 1,
ReleaseDate = 2,
PublishedDate = 3,
TranslatedTitle = 4,
OriginalTitle = 5,
UserRating = 6,
Duration = 7
}
To this:
[DataContract]
public enum SortMethodType
{
[EnumMember]
Default = 0,
[EnumMember]
Popularity = 1,
[EnumMember]
ReleaseDate = 2,
[EnumMember]
PublishedDate = 3,
[EnumMember]
TranslatedTitle = 4,
[EnumMember]
OriginalTitle = 5,
[EnumMember]
UserRating = 6,
[EnumMember]
Duration = 7
}
And it finally worked!
Go to Advanced properties while adding reference and remove "System.Window.Browser" from the checklist, It solves the problem.
that might sound weird, but I got it fixed by deleting the references, then closing Visual Studio, and reopening it again, and finally adding the references again.
I think the custom tool thing needed to be restarted or something.
I constantly run across this error while it works on another developers machine. Even though I'm a full admin everywhere in my virtual machine, I tried closing Visual Studio, and re-opening with 'Run As Administrator' and it magically worked.
Good luck.
I got the warning after upgrading my solution from Visual Studio (VS) 2010 to 2013 and changing each project's .NET Framework from 4 to 4.5.1. I closed VS and re-opened and the warnings went away.
One downside of turning off 'reuse types in referenced assemblies' is that it can cause issues with ambiguous references. This is due to the service reference creating those objects again in the reference .cs file, and your code implementing the service may be referencing them from the original namespace.
When this scenario occurs I find it useful to check the 'reuse types in specified referenced assemblies' which allows me to choose the ones with ambiguous references only, which resolves the issue quickly that way.
Hope it helps someone else.
My interfaces of the WCF service are in an assembly, the implementation is in an another and the service reference is in yet another assembly, separate from the clients of the service reference. I got the error message right after I applied the DataContract to an enum. After I applied EnumMember to the fields of the enum, the issue resolved.
If in doubt that your service doesn't have any problems (such as problems with enums, or non-serializable classes as mentioned by others) then try to create a new project with a new reference.
I am using Silverlight 5 and I had tried to delete and recreate the reference several times. The reference.cs file just came up completely empty each time and it had been literally years since I'd created it so trying to figure out what had changed in the service was out of the question.
I noticed that the error contained references to 2.0.5.0. Now I don't even know if this is actually relevant to the Silverlight version, but it made me think of just creating a brand new project and then suddenly everything worked.
Warning 2 Custom tool warning: Cannot import wsdl:portType Detail: An
exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load file or assembly 'System.Xml, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its
dependencies. The system cannot find the file specified. XPath to
Error Source: //wsdl:definitions[#targetNamespace='']/wsdl:port
Type[#name='IShoppingCart']
I was looking over my project and I was having this same issue. It turned out to be different versions of the same DLL on the WCF vs. Web Site.
Web site had a newer version of the DLL and the service was referencing an older version of the DLL. Once they were all in sync all worked well.
I experienced the same error. I struggled for almost a day trying to find out what was going wrong. The clue for me were the warnings that VS was throwing. It was trying to do some kind of mapping to Yahoo.Yui.Compressor.dll, a library I had added and removed (because I decided not to use it) a couple of days before. It was shocking because the library wasn't there, but somehow it was trying to reference it.
Finally, I restore this dll from the Trash, and then I could update my service reference successfully.
For anyone here in the future, I had the same error but caused by version issues, in two different ways.
I have two WCF services and two client applications that talk via the service references. I updated a nuget package on both sides and tried to update the service reference and got this error.
Deleting didn't help. Unchecking "reuse assemblies" is not desired as I need to reuse them - that's the whole point.
In the end, there were two separate issues:
1) The first issue, I believe, was a visual studio caching issue. I meticulously went over all of the references and found no issues but it still reported being unable to find the previous version of the file. I uninstalled all of the nuget packages, restarted visual studio, and reinstalled them. Updating the service reference worked.
2) The second issue was caused by a dependency issue. I updated the nuget package on both sides and everything appeared correct, but an unmarked dependency was out of sync. Example:
Package Foo v1 references Bar v1.
It is possible to update Foo and Bar to v2 independently without updating the reference.
If you install both Foo and Bar v2 the service reference tool will scan Foo v2, see the reference to Bar v1, and fail because it can't find the older version.
This is only reported correctly if you update the version numbers of your dll for every package.
Visual Studio and MSBuild will have no problem building the application but the service reference will have a terrible time trying to resolve everything.
I hope this helps someone.

Resources