Using PostgreSQL from ASP.Net vNext - c#

I have installed Visual Studio 2015 Preview and created an ASP.Net 5 Empty Project.
I 'll use PostgreSQL in my application, so I added "Npgsql" NuGet Package in my project.
I added "using Npgsql" and tried to write a simple SQL connection test method but I get the error below :
Error CS0246 The type or namespace name 'Npgsql' could not be found
(are you missing a using directive or an assembly
reference?) WebApplication3.ASP.NET Core 5.0 AccountsController.cs
My project.json file :
"dependencies"
: {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta1",
"EnterpriseLibrary.Data": "6.0.1304.0",
"Npgsql": "2.2.3.0",
"Microsoft.AspNet.Mvc": "6.0.0-beta1",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta1",
"System.Data.Common": "1.0.0-beta1"
},
"frameworks": {
"aspnet50": {},
"aspnetcore50": { }
}
Is there any mistake or is it not possible to connect Postgres using asp.net-vnext right now ?
Besides, we want to develope code on Visual Studio and run on Ubuntu and we will have to use some third parties. Is it right time to go on with asp.net-vNext or choose some other open source language?
It feels like asp.net-vnext needs time to use in a project like that..

Just move whole "dependency" block under "aspnet50". Here is complete example of using PostgreSQL from ASP.NET 5

Have you tried to remove the line "aspnetcore50": { } ?
I'm not sure you'll be able to run it in Ubuntu just yet. Not sure that "EnterpriseLibrary.Data": "6.0.1304.0", is compatible with aspnetcore50.
Also if you use Entity Framework, keep in mind that EF7 still has a lot of features to be implemented.
I also wanted to create an application to be used both in Win and Lin but decided to go with windows only for now an leave it open enough so will be easy to change it later to support both OS. Do let you be mistaken with the false advertize of multiplatform (it's just marketing), this is not fully supported for big enterprise applications, not yet. I truly believe it will be soon, well I hope, I had the chance to go with Python tech but kept with .NET, I hope I haven't made a huge mistake.
Good luck.

Related

The type initializer for 'Amazon.AWSConfigs' threw an exception

I'm trying to log in using AWS Cognito by running the app after building it in Unity.
I couldn't log in properly, and when I tried debugging, I found the phrase "The type initializer for Amazon.AWSConfigs' thread an exception."
This error occurs when executing the following code:
Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient provider =
new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), regionTable[REGION]);
The app itself is built normally, but there seems to be a problem with logging in using AWS.
(I found this error in the PC and oculus environment.)
Some of the answers told me to modify the Config file. But I couldn't find the Config file. The location of this file was also unknown.
I found this answer "https://github.com/aws/aws-sdk-net/issues/310" but I couldn't apply this for me.
I found this Document "https://docs.unity3d.com/kr/2021.1/Manual/upm-config.html#upmconfig" but the Config file didn't exist in this path. My environment is Mac.
additionally,
I use AWS SDK called aws-sdk-net45-3.7.193.0.
UnityInitializer.AttachToGameObject(this.gameObject);
Amazon.AWSConfigs.HttpClient = Amazon.AWSConfigs.HttpClientOption.UnityWebRequest;
In this code, my Project Cannot understand UnityInitializer, HttpClient, and HttpClientOption.
What else changes are needed in order to mitigate the above issue.
I solved this problem.
The problem was that I was using IL2CPP as Script backend.
Simply using Script backend as Mono is one way. But my project had to use IL2CPP.
In order to use IL2CPP and use the Unity project using AWS Cognito, it is recommended that you:
Use .NetStandard2.0.
Use AWS SDK that is compatible with .NetStandard 2.0.
I used Unity 2020.3.19f version to use .NetStandard 2.0.
If you are using a URP project and there is an error in URP due to downgrade of Unity version, it is recommended that you act as follows.
Enter the Package folder for that project
Open Manifest.json and Package-lock.json files
Change the Render Pipeline version to 10.8.1 (for 2020.3.19f1 version. I didn't experiment with other versions.)
Reference found to resolve this issue.
https://forum.unity.com/threads/issue-with-system-configuration-configurationmanager-get_appsettings-on-ios.1026877/#post-6656764
https://docs.aws.amazon.com/ko_kr/mobile/sdkforunity/developerguide/aws-unity-sdk.pdf
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal#10.8/manual/index.html

Stores and C# assembly dll files not being loaded

I have recently tried adding In App Purchase into my Unity project. Unfortunately, it didn't show in the Components drop down menu. I could use the option to create IAP Button and perform code-less IAP configuration but it wasn't there in the menu. So I decided to configure IAP through script. But the script too throws some errors. The error goes like this:
"Assembly 'Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll' will not be loaded due to errors: Reference has errors 'Stores'."
Four errors just like the above one shows up for Assembly-CSharp.dll, Editor.dll and Assembly-CSharp-firstpass.dll
And then this one:
"Assembly 'Assets/Plugins/UnityPurchasing/Bin/Stores.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEngine.UI'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector."
I have tried re-installing In App Purchase package.
I have tried changing the API from .NET Standard 2.0 to .NET 4.x (and did the vice versa and still did not work)
Downgrading unity project isn't really a good idea but anyways I gave it a try but it just added to the already existing errors.
Upgrading to newer Unity version (alpha version) didn't help.
The error occurs whenever I initialize the ConfigurationBuilder referring StandardPurchasingModule.
public void InitializePurchasing()
{
// If we have already connected to Purchasing ...
if (IsInitialized())
{
// ... we are done here.
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(TWO_BOLTS, ProductType.Consumable);
builder.AddProduct(FIVE_BOLTS, ProductType.NonConsumable);
UnityPurchasing.Initialize(this, builder);
}
The worst part is that I am unable to use my scripts after writing the ConfigurationBuilder initialization code. Unity asks me to fix any compiler errors and assign a valid script. I have searched for the answer for so long. I am really stuck in here. Please help.
Your issue seems to be related to verison of Unity you using. You can follow progress of this issue on official Unity issue tracker.
If this issue is showstopper for you than cosider downgrading as you using beta verions of Unity and as official site states:
As with any beta program, you’ll have early access to new features and
will be able to assist in the final steps of their development. That
means you’re likely to experience Unity as less stable than a final
version.

In .NET, DbGeography.PointFromText is throwing a Not Implemented exception, when it should be implemented?

So I'm trying to do some simple Geography stuff in an old .NET 4.6.2 project. I have EF 5 installed (not planning on upgrading to EF 6).
When I try and do some simple DbGeography.PointFromText("POINT 1 1", 4326); I get a Not Implemented Exception thrown.
e.g.
SqlServerTypes.Utilities.LoadNativeAssemblies (AppDomain.CurrentDomain.BaseDirectory);
var xxx = System.Data.Spatial.DbGeography.PointFromText("POINT(1 1)", 4326);
I thought EF 5 has this method in it and it's totally ok to use? (e.g. reference material about using DbGeograpghy).
Am I doing something wrong? Is it possible the wrong (old?) dll is getting used and therefore, thrown?
Update 1 (Possibly not a duplicate).
It was suggested that the issue is because DbGeography requires (from nuget) Microsoft.SqlServer.Types package. So I tried installing that from nuget, then making sure I 'load' these special dll's at the start of my test. Problem still existed.
Update 2
Using NuGet Microsoft.SqlServer.Types version 14.0.314.76 (current version as of the time of this post)

Why WindowsIdentity class is not visible in .NET Core

Having the code below in VisualStudio 2017 .NET Core 2.0 Console App
using System;
using System.Security.Principal;
namespace smallTests
{
class Program
{
static void Main(string[] args)
{
var identity = WindowsIdentity.GetCurrent();
}
}
}
Why am I getting the error:
The name 'WindowsIdentity' does not exist in the current context
If I can see this class in .NET Core 2.0 library in .Net Core docs ?
Same code works in .NET Console app.
[EDIT]
#Will #JohnnyL Commented that I do not refer, System.Security.Principal.Windows.dll, that is true.
But I am curious why it is not working, because
in .NET 4.6.1 project (where class WindowsIdentity is visible) I also do not refer this System.Security.Principal.Windows.dll specifically. However i refer System.dll.
I always thought that it works like namespace hierarchy. For instance, when I refer to
System.Security.Principal.dll
i can use class which is in
System.Security.Principal.Windows.dll.
Am I wrong?
I added System.Security.Principal.dll to .NetCore solution by hand but it still does not work.
[EDIT2]
#Will Thank you a lot for expaining the subject it helped me a lot.
I tried to figure out is WindowsIdentity compatible with Core and it seems that it is please see:
in this apisof.net in Declarations area i can see that WindowsIdentity is in .Net Core 2.0 System.Security.Principal.Windows, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a
but i do not have System.Security.Principal.Windows.dll in references, should I add it? If yes from where?
in .NET Core api reference i see this class in the list (what is the purpose of that listing if it is not compatible with core?
I also find information about that class in that link
Am I looking in wrong places?
Microsoft announced Windows Compatibility Pack for .NET Core a few weeks ago,
https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/
And by analyzing the source code of System.Security.Principal.Windows.csproj and the commit adding it,
https://github.com/dotnet/corefx/blob/master/src/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj
My conclusion is that this is also part of the Windows only compatibility libraries, so can only be used on Windows.
To add that to your project, open your csproj and add a PackageReference tag for System.Security.Principal.Windows manually (or use Visual Studio's NuGet Package Manager).

ASP.NET 5 Process.Start?

I am trying to use Process.Start in an ASP.NET Beta8 project that I would like to be able to run on Linux using .Net core. Visual studio is giving me an error at compile time:
Error CS0103 The name 'Process' does not exist in the current context
Going back and hovering my mouse over Process.Start I can see a message that says "DNX core 5.0 not available". Is there a different way of invoking processes in asp.net 5? Or perhaps this isn't possible yet?
Here is exactly how I am using it:
var p = Process.Start("someprog", "someargs");
p.WaitForExit();
So it was me not really not knowing how the new project system works for .net. I needed to add a dependency to my project.json:
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Diagnostics.Process": "4.1.0-beta-23409"
}
}
},
Adding this made it compile. Although I am not sure if that version number is correct.

Categories