Thứ Sáu, 4 tháng 8, 2023

Fix the issue Unity android 12, 13 can not start the game

When build unity game that target android 12, 13, the game can not start. 
There are two things to fix this: 
1. In Unity Player Settings, publish settings: 
- Check custom main manifest + Add property android:exported="true" to activity 
- Check custom main gradle template 
+ If using admob, add this to dependencies setting: implementation 'com.google.android.gms:play-services-ads:20.4.0' // For apps targeting Android 12, add WorkManager dependency. constraints { implementation('androidx.work:work-runtime:2.7.0') { because '''androidx.work:work-runtime:2.1.0 pulled from play-services-ads has a bug using PendingIntent without FLAG_IMMUTABLE or FLAG_MUTABLE and will fail in Apps targeting S+.''' } 
 + If not using admob, just add implementation('androidx.work:work-runtime:2.7.0') to dependencies setting 
- check Custom gradle properties template Add those settings: android.useAndroidX=true android.enableJetifier=true android.enableR8=true
2. In Other settings: 
+ Uncheck Auto Graphic API, then move OpenGLES3 to the top of the list
Read More »

Thứ Bảy, 25 tháng 3, 2023

Could not load type 'CKFinder.Connector.Connector'

Could not load type 'CKFinder.Connector.Connector' Make sure that CKFinder.dll file is located straight inside of "bin" folder. By default CKFinder's bin folder contains subfolders "Release" and "Debug".
Read More »

Thứ Năm, 23 tháng 3, 2023

403 Forbidden when adding nuget package from github

When trying add a nuget package from github "dotnet add package 'your package' --version 'your version'", catch 403 forbidden error: Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured. It maybe because you do not authorize your github token sso (if you are working in a company using sso):
Go to token setting and choose to config sso as above then you can add that nuget package.
Read More »

Thứ Sáu, 8 tháng 7, 2022

Music Festival Part 2 MindMap - Effortless English - Learn Real English

Music Festival Part 2 MindMiap - Effortless English - Learn Real English
Read More »

Thứ Sáu, 30 tháng 7, 2021

Transaction SQL

Add a try/catch block, if the transaction succeeds it will commit the changes, if the transaction fails the transaction is rolled back:
 BEGIN TRANSACTION [Tran1]  
  BEGIN TRY  
    INSERT INTO [Test].[dbo].[T1] ([Title], [AVG])  
    VALUES ('Tidd130', 130), ('Tidd230', 230)  
    UPDATE [Test].[dbo].[T1]  
    SET [Title] = N'az2' ,[AVG] = 1  
    WHERE [dbo].[T1].[Title] = N'az'  
    COMMIT TRANSACTION [Tran1]  
  END TRY  
  BEGIN CATCH  
    ROLLBACK TRANSACTION [Tran1]  
    SELECT @ErrorMessage = 'Lỗi: ' + ERROR_MESSAGE()
    RAISERROR(@ErrorMessage, 16, 1)
  END CATCH   
Read More »

Move connection string into code

Firstly I had to create myself a new class in my DB ORM assembly Then I had to add a reference to the System.Data.Entity assembly. Then added this static method to my static class (including the namespaces required)
 using System.Data.SqlClient;  
 using System.Data.EntityClient;  
 namespace MY_DB_ORM  
 {  
   static class MY_DB  
   {  
     public static string ConnectionString()  
     {  
       SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();  
       // Set the properties for the data source.  
       sqlBuilder.DataSource = "MY_SERVER_IP,1433";  
       sqlBuilder.InitialCatalog = "MY_DB_NAME";  
       sqlBuilder.UserID = "MY_USERID";  
       sqlBuilder.Password = "MY_PASSWORD";  
       sqlBuilder.IntegratedSecurity = false;  
       // Build the SqlConnection connection string.  
       string providerString = sqlBuilder.ToString();  
       // Initialize the EntityConnectionStringBuilder.  
       EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();  
       //Set the provider name.  
       entityBuilder.Provider = "System.Data.SqlClient";  
       // Set the provider-specific connection string.  
       entityBuilder.ProviderConnectionString = providerString;  
       // Set the Metadata location.  
       entityBuilder.Metadata = @"res://*/MY_CONTEXT_CLASS_NAME.csdl|  
                         res://*/MY_CONTEXT_CLASS_NAME.ssdl|  
                         res://*/MY_CONTEXT_CLASS_NAME.msl";  
       return entityBuilder.ToString();  
     }  
   }  
 }  
Then in my context class I could alter the constructor to use this method..
 public partial class MY_CONTEXT_CLASS_NAME : DbContext  
   {  
     public MY_CONTEXT_CLASS_NAME_CONSTRUCTOR()  
       : base(MY_DB.ConnectionString())  
     {  
     }  
Now I am able to remove the connection string to my model from the app.config file where it was held in clear text for all to see! https://community.spiceworks.com/topic/815431-ef-can-t-get-it-to-work
Read More »

Thứ Ba, 27 tháng 7, 2021

The difference between break and yield break

Using yield break as opposed to break might not be as obvious as one may think. There are lot of bad examples on the Internet where the usage of the two is interchangeable and doesn't really demonstrate the difference. The confusing part is that both of the keywords (or key phrases) make sense only within loops (foreach, while...) So when to choose one over the other? It's important to realize that once you use the yield keyword in a method you effectively turn the method into an iterator. The only purpose of the such method is then to iterate over a finite or infinite collection and yield (output) its elements. Once the purpose is fulfilled, there's no reason to continue method's execution. Sometimes, it happens naturally with the last closing bracket of the method }. But sometimes, you want to end the method prematurely. In a normal (non-iterating) method you would use the return keyword. But you can't use return in an iterator, you have to use yield break. In other words, yield break for an iterator is the same as return for a standard method. Whereas, the break statement just terminates the closest loop. Let's see some examples: /// /// Yields numbers from 0 to 9 /// /// {0,1,2,3,4,5,6,7,8,9} public static IEnumerable YieldBreak() { for (int i = 0; ; i++) { if (i < 10) { // Yields a number yield return i; } else { // Indicates that the iteration has ended, everything // from this line on will be ignored yield break; } } yield return 10; // This will never get executed } /// /// Yields numbers from 0 to 10 /// /// {0,1,2,3,4,5,6,7,8,9,10} public static IEnumerable Break() { for (int i = 0; ; i++) { if (i < 10) { // Yields a number yield return i; } else { // Terminates just the loop break; } } // Execution continues yield return 10; } Source: https://riptutorial.com/csharp/example/29811/the-difference-between-break-and-yield-break
Read More »