Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

IsEditable ComboBox LostFocus called initially instead of GotFocus event while focus ComboBox WPF

$
0
0

I have checked WPF ComboBox with IsEditable as true. 

While focus ComboBox, LostFocus event called first time, then GotFocus have called. 

How to resolve this?

Code :

XAML:

<Grid><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions><StackPanel><ComboBox Height="40" Width="200"
                      Margin="10"
                      GotFocus="ComboBox_GotFocus"
                  LostFocus="ComboBox_LostFocus" IsEditable="True"/><TextBox Text="TextBox" Height="30" 
                     Margin="10"
                     Width="200" /></StackPanel><StackPanel Grid.Column="1"><Button Content="Clear" Width="100" Height="50" Margin="10"
                    Click="Button_Click"/><ListView x:Name="listview"  Margin="10" Height="300"></ListView></StackPanel></Grid>

 C#:

  private void ComboBox_GotFocus(object sender, RoutedEventArgs e)
        {
            listview.Items.Add("GotFocus");
        }

        private void ComboBox_LostFocus(object sender, RoutedEventArgs e)
        {
            listview.Items.Add("LostFocus");
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            listview.Items.Clear();
        }




Thanks, Muneesh.


Console app with generic host, strange message order

$
0
0

.Net Core 3.1

Console app with generic host and serilog.

"Application started" message is shown after messages from my hosted service and it looks a bit "messy".
Possible to finish the "app pipeline" before starting the service?

How to speed up DataGrid or can I implement my image grid in ListViews

$
0
0

greetings!

I created a simple program, for inserting the selected pictures into cells, for the implementation of the grid with cells, I chose DataGrid, it was difficult enough, this is my first application. but in the end a surprise was waiting for me, the DataGrid turned out to be difficult to scale when the cells are 100x100, the grid is drawn for 5 seconds, it’s not so important, the important thing is that when I click on the cell the value changes

<Image Source="{Binding}"/>

so that I immediately see a change I have to do

MyDataGrid.Items.Refresh();

Which causes a delay of 5 seconds if the cells are 100x100.
Question:
How can I speed up updating a DataGrid or can I bypass DataGrid.Items.Refresh?

I tried to implement a grid on a ListView but I could not create a dynamic grid.

I don’t care what class draw the grid.

Code  github.com    /Devoleksiy/KnitEditor

I can not post a link

Are ICryptoTransform.TransformBlock() and SHA256.ComputeHash() methods thread-safe?

$
0
0

Are ICryptoTransform.TransformBlock() and SHA256.ComputeHash() methods thread-safe?

I call System.Security.Cryptography.Aes.Create() to create an instance, then I call CreateEncryptor() / CreateDecryptor(). Can I use these ICryptoTransform Encryptor and Decryptor by multiple threads? Do I need mutual exclusive access? I see that creating of these objects is expensive.

The same question is about System.Security.Cryptography.SHA256.ComputeHash() method. Is it thread-safe?



How MMC snap-in bind to specified registry value like GPO

$
0
0

I used the example codes mentioned at https://docs.microsoft.com/en-us/previous-versions/windows/desktop/mmc/mmc-3.0/ms692749(v=vs.85)

to create a snap in with a self-defined UI, which provide a textout for inputting some data from user, after user finish data input, I store this data into a registry under HKLM\SOFTWARE\Policies\***  with multi-string type.

But I found the data is just stored on the local machine,  like the normal registry setting, l need it store the registry like GPO process

search some references from website, found IGroupPolicyObject can saves the specified registry policy settings to disk and updates the revision number of the GPO, but it can only apply to the existed GPO registry item, how can I apply to a new one? 


how to create a registry based policy as the .admx does with program

SortedSet(IComparer) c++ where T already has a tertiary compare

$
0
0
If <T^> already has a function int Compare(<T^>Ta, <T^>Tb), how to use that in a SortedSet (IComparer<T^>)? 

Cannot connect to a FTPS(SSL/TLS) server

$
0
0

Hello all. I have spent a day long trying to figure out why I could not connect to a FTPS server but to no avail. I always got this error.

System.Security.Authentication.AuthenticationException
a call to SSPI failed, see inner exception

I set up a connection in FileZilla, with protocal=FTP and encription=any of the three TLS choices. It works well. I can download, upload and delete files in the server. But it just doesn't work with C# code.

Does anyone have any ideas ?

public bool CheckConnection(string RemoteHost, string UserName, string Password)
{
     try
     {
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(RemoteHost);
        request.EnableSsl = true;
        request.Method = WebRequestMethods.Ftp.ListDirectory;
        request.Credentials = new NetworkCredential(UserName, Password);             
        request.GetResponse();
      }
        catch (WebException ex)
      {
         MessageBox.Show("Fail:" + ex.ToString());
          return false;
      }
       return true;
}




Get Product String from USB COM port

$
0
0
Can anyone tell me how to do this?  I can get the product string using the USBView example project but I don't know how to get the COM port name for that USB device.  I can also get all the COM port names using SetupDiEnumDeviceInterfaces but there is no DEVPKEY that lets me get the product string using SetupDiGetDeviceProperty.

How to do google Authentication web api using ASP.net framework from scratch?

$
0
0

I created an empty web api project (without authentication) and made my controllers and Database.

Now i want to make google authentication, what should i do? All the data online shows how to do google authentication if u created a project with authorization ticked

How can I compare the first row of my excel file to the values stored in a variable to see if they are matched or not?

$
0
0

I need to open pre-existing excel file and compare the first row of my excel file under columns name to the some test values stored in variables (how to store those values too) to see if they are matched or not. What i did is open excel. Here is the code:

usingExcel =Microsoft.Office.Interop.Excel;

usingXceed.Wpf.Toolkit;

namespaceFirst_Program

{

   public class Program

   {

       public void exceldownload()

       {

           string str;

           int rCnt;

           int cCnt;

           int rw = 0;

           int cl = 0;

// Create a new excel application instance

           Excel.Application xlApp = new Excel.Application();

           xlApp.Visible = true;

           xlApp.DisplayAlerts = false;

//Open demo sheet

           Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\TestData.xlsx" ,0, true, 5, "", "", true,     Excel.XlPlatform.xlWindows,"", false, false, 0, true, false, false);

                   xlApp.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized;

//select the first sheet in demo.xlsx

           Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];

//Find the range of cells used

           Excel.Range xlRange = xlWorksheet.UsedRange;

           rw = xlRange.Rows.Count;

           cl = xlRange.Columns.Count;

for (rCnt = 1; rCnt <= 2; rCnt++)

           {

               for (cCnt = 1; cCnt <= cl; cCnt++)

               {

                   str = (string)(xlRange.Cells[rCnt, cCnt] as Excel.Range).Value2;

                   MessageBox.Show(str);

               }

           }

xlWorkbook.Close(0);

           xlApp.Quit();

       }

   }

}

Desired input is : My input in excel's first row with column name is

ColumnName: name,class, rollnoValues:Abc,10th,88990

1) I want to compare each cell in first row( that are 3) against 3 different variables. 2) Desired output will be Match Abc to the first Variable value and if they are matches then compare the second value that is 10th to the second variable and so on until complete first row is verified 

SortedSet(IComparer) c++ where T already has a tertiary compare

$
0
0
If <T^> already has a function int Compare(<T^>Ta, <T^>Tb), how to use that in a SortedSet (IComparer<T^>)? 

migration of 4.5 to 4.8 framework

$
0
0

Hi Team,

I am doing migration asp.net project 4.5 framework 4.8

While giving build observed that reference  missing system.runtime.dll and if i add this dll to all class library build is success

what system.runtime.dll does exactly

any suggestion and help will be highly appreciated on how to proceed further on this.
Regards

SortedSet(IComparer) c++ where T already has a tertiary compare

$
0
0
If <T^> already has a function int Compare(<T^>Ta, <T^>Tb), how to use that in a SortedSet (IComparer<T^>)? 

Alternate for ApplicationBlocks.ExceptionManager in .NET Core

$
0
0

I am migrating code from .net 4.6.2 to .net core/.net standard 2.2.

I am trying to find alternate for ExceptionManager.Publish() in .net core.

My current code is like below :

using Microsoft.ApplicationBlocks.ExceptionManagement;

          Exception e = new Exception(strMessage);

         ExceptionManager.Publish(e, objLogInfo);

And in Config we are specifying where exactly to log the event

<publishermode="on"assembly="Microsoft.ApplicationBlocks.ExceptionManagement"type="Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher"     logname="myLog"applicationname="myasmx" />

I used  nugets like - EnterpriseLibrary.ExceptionHandling 6.0.1.3  & EnterpriseLibrary.ExceptionHandling.netcore 6.3.0

is there any support for ApplicationBlocks.ExceptionManager .net core? Please help me out in fixing it.


System.Web.Security.CookielessHelperClass NullReferenceException Error

$
0
0

I have an ASP.NET MVC 4.7.1 project and it's been working fine for months but now I'm getting this error whenever I try to debug it on my local machine using IIS Express on Windows 10:

[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.Security.CookielessHelperClass.UseCookieless(HttpContext context, Boolean doRedirect, HttpCookieMode cookieMode) +9828485
   System.Web.Security.FormsAuthenticationModule.ExtractTicketFromCookie(HttpContext context, String name, Boolean& cookielessTicket) +1995
   System.Web.Security.FormsAuthenticationModule.OnAuthenticate(FormsAuthenticationEventArgs e) +110
   System.Web.Security.FormsAuthenticationModule.OnEnter(Object source, EventArgs eventArgs) +84
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +144
   System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +26
   System.Web.StepInvoker.Invoke(Action executionStep) +107
   System.Web.<>c__DisplayClass4_0.<Invoke>b__0() +23
   Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.OnExecuteRequestStep(HttpContextBase context, Action step) +64
   System.Web.<>c__DisplayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction) +56
   System.Web.StepInvoker.Invoke(Action executionStep) +91
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +9972006
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

The whole stack trace is .NET, not my code. The debugger in VS starts but no breakpoint or exception gets hit. 

It runs fine on the test server and production server which is a good thing but debugging remotely to the test server sucks and very time consuming.

All of my other ASP.NET projects are still working.

I've tried repairing my installation of Visual Studio 2017 which didn't help.

What's this 'CookielessHelperClass' class? I wasn't able to find much on it.

Any ideas? Maybe it's coming from a Nuget package that I don't need?

Json configuration with polymorphic array

$
0
0

Is it possible to have a polymorphic array setup by json configuration?

E.g. the following code (all in one file only for the demo of course):

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Threading;
using System.Threading.Tasks;

namespace PolymorphicConfigurationArray
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureServices((hostContext, services) =>
                {
                    services.Configure<ApplicationOptions>(hostContext.Configuration.GetSection("Application"));
                    services.AddHostedService<Worker>();
                });
    }
    public class Worker : BackgroundService
    {
        private readonly ILogger<Worker> _logger;

        public Worker(ILogger<Worker> logger, IOptions<ApplicationOptions> options)
        {
            _logger = logger;
            logger.LogInformation($"Configuration Description {options.Value.Description}");
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                //_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                await Task.Delay(1000, stoppingToken);
            }
        }
    }
    public class ApplicationOptions
    {
        public string Description { get; set; }
        public ConfigItem[] Items { get; set; }
    }
    public class ConfigItem
    {
        public string ItemName { get; set; }
    }
    public class ConfigItemWithValue : ConfigItem
    {
        public double ItemValue { get; set; }
    }
}

The json file below may be used to intantiate the ApplicationOptions class with some ConfigItems in the Items array, however, I cannot see any way to get the derived ConfigItemWithValue class from configuration and thus having the Items array as a polymorphic array.
Is this simply the limitation of json (key/value)?

I know that newtonsoft.json may serialize/deserialize such a graph by some typename options, is this possible to use in any way for configuration (without a lot of custom code of course)

{"Logging": {"LogLevel": {"Default": "Information","Microsoft": "Warning","Microsoft.Hosting.Lifetime": "Information"
    }
  },"Application": {"Description": "Wondering how to achieve polymorphic array with json configuration","Items": [
      { "ItemName": "Name1" },
      { "ItemName": "Name2" }
    ]
  }
}

Migrating .NET Framework 4.6.2 to .NET Standard 2.0

$
0
0

Hi All,

We have a set of class libraries which are created under.NET Framework 4.6.2, we want to move these libraries into .NET Core 2.0 or .NET Core standard 2.0

We have the following ways,

  1. Create a new project and copy over the code.
  2. Convert your existing project by editing the CSPROJ  file.

Which one is better to migrate the libraries and will dot net standard impact on performance over the the.NET core.

Is there any alternatives to migrate these collections.



SrinivasReddyVelpula


system.web in .net core

$
0
0

Hi Team,

How to add system.web reference in .net core 3.1

Is wcf suported in .net core 3.1

$
0
0
Is wcf suported in .net core 3.1
Viewing all 8156 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>