I am currently looking to build a console app to interact with a .NET webservice and insert AspNetUsers into my database.
I'm currently using this: https://www.codepoc.io/blog/net-core/5291/create-aspnetcore-identity-users-using-console-application
As a guide. However, I'm a little confused when it comes to the various dependencies required to successfully run the aforementioned code.
My workspace currently looks like this:
Am I correct in assuming that I may have the wrong version of AspNetCore? Am I missing something else or is this blog post out of date now? What would the best way be to insert .NET Identity users into the database using a .NET core console app - I'm equally not opposed to keeping it as a .NET Framework? Console app.
Any guidance appreciated.
I think Microsoft.AspNetCore.Identity.dll is its own dll which you can download via nuget from here. Please add that nuget package to your solution. Microsoft.AspNetCore is a different dll that does not contain the Microsoft.AspNetCore.Identity namespace which is why you are getting the error and not able to resolve the reference.
Related
I'm developing a Blazor PWA project where the WASM client needs to generate PDFs. My employer had already purchased an Xfinium license, thus I have been using it in our project. I have just recently ported the project from .NET Core 3.1 to .NET5 and have begun encountering issues with the Xfinium library. First of all, I am using the Xfinium.Pdf.NET library, as it supposedly supports .NET5. Upon attempting to initialize any object from this library (i.e. PdfFlowDocument test = new();) I am immediately greeted with the following error: Assertion at /__w/1/s/src/mono/mono/mini/interp/transform.c:3592, condition <disabled> not met, which causes my application to crash. To further pinpoint this issue, I created two separate Blazor PWA WASM projects, one with .NET5 and one with .NET6, installed the Xfinium.Pdf.NET library, and attempted to use it. Both resulted in the exact same error as above. I then recreated this on a separate machine as well.
I have reached out to Xfinium support in regards to this issue, and have yet to hear back. Wondering if anyone else has experience a problem similar to this one. For the time being I will simply keep the project on .NET Core 3.1 (the upgrade was to fix another issue where we couldn't read more than 2mb at a time from indexed db database).
Any help is much appreciated!
Upon receiving a helpful workaround from the Microsoft Forums and a response from the Xfinium support team, I can answer my own question.
The Xfinium support team was able to recreate my issue with the obfuscated NET version of their Xfinium.Pdf library. Upon testing the non-obfuscated assemblies of the same library, the problem was non-existant. Therefore, they believe the obfuscation tool is the source of the problem and have notified me that they have reached out to their obfuscation tool vendor. I will be alerted by their support team when the issue is fixed.
As for a workaround, a user named Bruce on the Microsoft Q&A Forums suggested I try the NetStandard version of the library in my NET5 project. This solved my problem. I then alerted the Xfinium support of this solution and they told me that the NetStandard assemblies for this library are in fact obfuscated using a separate tool.
Thus, for the time being, I will be going forward using the NetStandard version of the library. I will update this post when Xfinium support alerts me that a fix has been shipped.
I am following a tutorial (this one in particular https://www.twilio.com/docs/usage/tutorials/how-to-secure-your-csharp-aspnet-web-api-app-by-validating-incoming-twilio-requests) in order to create an attribute for securing my Web API webhook. I am using .NET 6 preview 7 and it seems to me that in the tutorial they are using somewhat outdated libraries (correct me if I'm wrong), such as Microsoft.AspNet.WebApi.Core and System.Web.Http. I added these libraries to my project and after several hours I got it to work and my endpoint is seemingly secured. Now, as mentioned I added the Microsoft.AspNet.WebApi.Core library as a reference and Visual Studio 2022 even gives me an warning saying it might not be able to fetch the correct version of it due to version mismatching.
My question is: can this outdated library (or dependencies) interfere with my other .NET 6 API's/Web API Controllers and web infrastructure in ASP.NET Core? Typically to load other code, making me unable to leverage new functionalities, performance boosts and other improvements of .NET 6. There are a lot of DI going on and I feel like I do not have a full understanding of how everything is loaded and which libraries are actually used when I deploy my app to IIS. Ideally I would like to port this attribute class to use the latest .NET 6 libs but many of these objects and properties are handled differently in the newer libraries as I understood.
Thanks Daniel A. White for the help. My problem was that my endpoint is hosted on sub path and therefore the RequestRawUrl method in the example fetched slightly wrong URL.
I am following this guide on how to create a Web API with ASP.NET Core and MongoDB. I have followed every step successfully up until the Add a configuration model section. In the guide, I need to locate appsettings.json and add database configuration values to my project. The problem is that the file they mention appsettings.json does not exist in my project.
In the guide, its implied that the file should already exist and should even already have content in it, so I don't know if I should just create it.
I have looked online and all over my project but nothing seems to be definitive on what is the right thing to do (some guides contradict each other, etc.).
Apart from the default ones, I explicitly installed have the following NuGet packages:
Microsoft.Extensions.Configuration (I thought this might help, but it didn't)
MongoDB.Driver (the instructions on the guide said to)
My setup is the following:
Microsoft Visual Studio Community 2019 Version 16.4.6
Microsoft .NET Framework Version 4.8.03752
ASP.NET and Web Tools 2019 16.4.462.24200
ASP.NET Web Frameworks and Tools 2019 16.4.462.24200
I have closed and re-opened VS but that didn't change anything.
This is my solution explorer:
Should I just create the file? In the guide, it already has content in it. What about that?
Is there a new/different way of add database configuration values to my project?
Is the guide outdated? If it is completely unusable, can you point me to a newer guide on how to Create a web API with ASP.NET Core and MongoDB?
Thank you very much!
The app exists for ASP.NET core projects. You mistakenly created, I believe, an ASP.NET framewok project. The tutorial is about the ASP.NET core.
I have a self-contained .net core app on Mac, and it contains another .net core app as a plugin.
The structure is somewhat like this:
MyApp.app
|---Content
|----MacOS
|---self-contained runtime *dlls and assemblies
|----Resources
|---MyPlugin.app
Once MyApp is running, a user may start MyPlugin. I am hoping to share the runtimes under MacOS. What's the best way to do this?
Here is what I have tried based on what I read and tested, they could be all wrong...:
Since MyPlugin is using apphost, one way seems working is to set dotnet_root to MyApp/Content/MacOS. Then it will look for something like $DOTNET_ROOT/shared/$name/$version, but since MyApp is self-contained, it doesn't have this structure, which means I would need to make this structure myself.
I think nethost is made for non .netcore apps to start .netcore runtime, even I use this, it will face the same problem as the first way, I think.
Since Docker will isolate my app's environment, if I built my app using the .net core docker image, maybe both MyApp and MyPlguin would find the right .NetCore libraries. But I cannot assume users could run Docker.
Is there an easier or official way to do this? Since MyApp is already running when I start MyPlugin, is it possible to just reuse the already started runtime?
Someone asked a similar question on github here, and a .net team member confirmed it's not currently possible, and a workaround is using the 1st way described in the question.
Credit goes to Vitek Karas:
What you could do instead is build the apps as framework dependent.
Then when installing:
Get the "zip" download for the specific runtime version/target
Unzip it to some location - can be in "runtime" subfolder to your main folder
Install the apps as shown above (but really anywhere, it doesn't matter)
Run the apps via a "script" - all you need to do is set DOTNET_ROOT=path env. variable > to point to the runtime folder and then run the app from that environment. On Windows you may also want to set DOTNET_MULTILEVEL_LOOKUP=0 to make sure the apps will not use the globally installed .NET Core (if there's any).
I am trying to build a read only .net rest api using the following tutorial on Microsoft Docs-(https://learn.microsoft.com/en-us/aspnet/web-api/overview/older-versions/build-restful-apis-with-aspnet-web-api)
According to the tutorial when i add a controller the following error popup.
I have tried other solutions on stackoverflow like
Clearing ComponentModelCache
Also deleting .vs folder in solution
But nothing helped
Try changing your project to .NET Framework instead of .NET Core and make sure you are able to create a solution with .NET Framework. If the issue still persists please provide some additional log details of VisualStudio when creating with .NET Core