Got this error, “Could not find a part of the path … bin\roslyn\csc.exe“. I guess the answer is to just do a REBUILD, maybe a clean solution first but REBUILD solution works.
That easy š
Leave a CommentGot this error, “Could not find a part of the path … bin\roslyn\csc.exe“. I guess the answer is to just do a REBUILD, maybe a clean solution first but REBUILD solution works.
That easy š
Leave a CommentI had to write some code to ingest a CSV file, and this made it so much simpler. This nuget package is open source as well https://github.com/JoshClose/CsvHelper.
https://joshclose.github.io/CsvHelper/
Leave a CommentThese are the steps I used to install dotnet core on Ubuntu 22.04, both the SDK and the runtime.
apt update
apt install -y apt-transport-https
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
apt update
apt install -y dotnet-sdk-7.0
apt update
apt install -y aspnetcore-runtime-7.0
To verify installation run the following commands. If the below doesn’t work try to open a new ssh session or terminal.
dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
dotnet --list-sdks
7.0.102 [/usr/share/dotnet/sdk]
root@srv4311:~#
If you tried previously to install version 7.0 make sure you remove/purge the old version from the system. Something like below.
apt remove --purge dotnet-sdk-6.0 dotnet-runtime-6.0
apt auto-remove
Also maybe delete the .dotnet folder in your home directory.
Leave a CommentI deleted all the CSS from site.css and replaced it with mine of course but after that, I started receiving the following error “Getting error An unhandled exception has occurred. See browser dev tools for details. Reload”. It looks like this occurs because blazor needs at least 2 styles to display errors.
Found my answer here.
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}
Leave a Comment Built a .net core api using swagger, dnsclient.net, and rollbar. Have a look here https://github.com/xavier-hernandez/dnsclient-api .
Here is the README:
I created a YAML file built on OpenAPI 3.0 standards for my endpoints(paths) and models. I generated the stub code onĀ https://editor.swagger.io/Ā then tweaked, fixed, and updated the code. Creating the stub code really gives a great head start.
I kept authentication simple, itās using an API key sent in the header request. Currently the API key is hardcoded to “1” but maybe later I’ll use a database or something to store API keys. I might host this somewhere if itās something I find interesting to host. Tie it maybe to a MySQL/MariaDB database.
The library being used to retrieve DNS information is called DnsClient.NET https://github.com/MichaCo/DnsClient.NET and available as a nuget package.
I’m also using https://rollbar.com/ which is an easy way to log errors and information. Maybe if I host it on Azure I’ll use Application Insights.
Leave a CommentNeed to hide properties in your JSON result for a .net core API. Add the following line in your Startup.cs file. Just like below.
opts.SerializerSettings.NullValueHandling = NullValueHandling.Ignore
services.AddMvc(options =>
{
options.InputFormatters.RemoveType<Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonInputFormatter>();
options.OutputFormatters.RemoveType<Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter>();
})
.AddNewtonsoftJson(opts =>
{
opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));
opts.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
})
.AddXmlSerializerFormatters();
Leave a Comment I got this error today and was causing me a headache. I stopped all apps running in IIS Express, tried switching releases, etc. But seems like this is a bug in Visual Studio 2019.
Stop your application, close the solution, delete the .vs folder in the solution, open it back up and it should work.
Leave a CommentIf your working with other developers this file should not be ignored within your .gitignore file. Its useful for environmental and other settings.
I’m not sure why the template I downloaded had it ignored. Seems like its been an issue for a while and has been corrected a few times.
https://github.com/github/VisualStudio/issues/1405
Leave a CommentAdding app_offline.htm to the root of your .net application automatically shuts it down. Very nice for putting up a quick maintenance page.
Leave a CommentRegex.Replace(filePath, ".txt", ".zip", RegexOptions.IgnoreCase);
Leave a Comment All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies. You can use the following access modifiers to specify the accessibility of a type or member when you declare it:
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can be accessed only by code in the same class or struct.
protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
protected internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.
http://msdn.microsoft.com/en-us/library/ms173121.aspx
Leave a CommentThe only way I found to change the HtmlEncode property on a bound column when auto-generating the grid-view.
protected void grFeedHistoryView_RowDataBound(object sender, GridViewRowEventArgs e) { BoundField field = (BoundField)((DataControlFieldCell)e.Row.Cells[2]).ContainingField; field.HtmlEncode = false; }
Leave a Comment
private void InsertAndUpdate() { NorthwindDataContext db = new NorthwindDataContext(); //Insert a record Customer newCus = new Customer(); newCus.CustomerID = "YYYZZ"; newCus.CompanyName = "Company_Z"; db.Customers.InsertOnSubmit(newCus); db.SubmitChanges(); //Update a record Customer record = (from p in db.Customers where p.CustomerID == "12345" select p).SingleOrDefault(); Console.WriteLine(default(Customer)); if (record != default(Customer)) { record.CompanyName = "Company_A"; } db.SubmitChanges(); }
Leave a Comment
This code project helped me out a lot.
http://www.codeproject.com/Articles/19639/Implementing-IHierarchy-Support-Into-Your-Custom-C
Leave a Comment
Don’t recall where I found this but converts List to DataTable.
public static System.Data.DataTable ToDataTable<T>(this IList<T> data) { System.ComponentModel.PropertyDescriptorCollection props = System.ComponentModel.TypeDescriptor.GetProperties(typeof(T)); System.Data.DataTable table = new System.Data.DataTable(); for (int i = 0; i < props.Count; i++) { System.ComponentModel.PropertyDescriptor prop = props[i]; table.Columns.Add(prop.Name); //table.Columns.Add(prop.Name, prop.PropertyType); } object[] values = new object[props.Count]; foreach (T item in data) { for (int i = 0; i < values.Length; i++) { values[i] = props[i].GetValue(item); } table.Rows.Add(values); } return table; }
Leave a Comment
Pieced this together from stackoverflow… http://stackoverflow.com/questions/2912476/using-c-sharp-to-check-if-string-contains-a-string-in-string-array/2912541#2912541
string stringToCheck = "text1"; string[] stringArray = { "text1", "testtest", "test1test2", "test2text1" };
This checks if stringToCheck contains any one of substrings from stringArray.
if(stringArray.Any(stringToCheck.Contains))
If you want to ensure that it contains all the substrings, change Any to All:
if(stringArray.All(s => stringToCheck.Contains(s)))
Leave a Comment
Here is a regular expression for credit card numbers.
string ccRegEx = @"^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$";Leave a Comment
Below is the regex code for U.S. and Canadian zip codes. I’m don’t remember where I found these but hopefully someone finds them useful.
string _usZipRegEx = @"^\d{5}(?:[-\s]\d{4})?$"; string _caZipRegEx = @"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$";Leave a Comment