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

.NET core nasted dependancy

$
0
0

Hi,

I have class library created in .NET core. Which have several dependency (DLL and nuget packages).

I am using this .NET core DLL in another .NET core project. I have GAC this DLL and using reference from there only. 

When I run my application I am getting dependency dll not found. If I GAC assembly/nuget packages dll although it is not working. It is giving same error.  But If I am adding all dependency dll in my calling project it is working. 

In .NET project if dependency dlls in GAC then it works. 

Please share your thoughts on it.

Regards,
Sauriin


I create a search functionality where I get List from partial view in asp.net mvc 4, but on the end I recive error in controller

$
0
0

Hi everyone,

I'm beginner in .Net Mvc tehnology and started to work on one project who is ended but should be make additional things how Search area. I make big part of code but appear error on executed. Description on task and my code: I should be make search on list of project who are read from Partial View List. In controller ProjectController I created Action Lista with code: 

, and I add textbox and button in Index Partial View and created ajax script in same Index View.  

  

I call Action from controller in Index View with code:

 and on the end of the view I add ajax script

     

  When I executed this task search textbox and button are ok, I insert data in textbox and click Search button. Then task is executed with message from script "SUCCESS" but list from all Projects remains the same, ie Search not filtered the required project. I debag Action List in Controller and appear this error on the pictures below. I don’t when resolve this error. I think that my problem is in ajax script. Do you anybody known more for scripts?  Please advice. Thanks

How to do TripleDES encryption implementation with three different keys?

$
0
0

Hi Experts,

We have been given three different encryption keys(Key1, key2, key3) and we were asked to implement Triple DES algorithm.

As per .net documentation, Triple DES class constructor only accepts one key where as client mentioned that they need to encrypt it with three keys. 

How to acheive same?


FileSystemWatcher Deleted event

$
0
0

I have learned the hard way that deleting a file in Windows does not necessarily mean that the file gets deleted right away, it will just be marked for deletion until the last handle to the file is closed.

When does FileSystemWatcher raise Deleted event?

Windows Service - Veeam Broker Service

$
0
0

Found an error when start the services 

error :- The veeam broker service service on local computer started and then stopped. some services stop automatically if they are not in use by other services or programs

TcpClient write error

$
0
0

Hi I am following article in Code Project. I am getting error at the point where client tries to send data to server (write() method). this is the server (TcpListener) code. I made change in port number from 8001 the author is using to some other number (44300) because 8001 did not work. When the Listener is started it shows

The server is running at port 8001...
The local End point is  :192.168.56.1:44300
Waiting for a connection.....

When the client is run it shows error after a couple of minutes:

Connecting.....
Connected
Enter the string to be transmitted : hellow server
Transmitting.....
Error.....    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offs
et, Int32 size)
   at clnt.Main() in c:\users\user\Source\Repos\ConsoleApp2\ConsoleApp2\Program.
cs:line 34
Press any key to continue . . .

I need help: any debugging ideas to find the cause of error? I tried to turn off Firewall but it did not help.

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

public class serv
{
    public static void Main()
    {
        try
        {
            IPAddress ipAd = IPAddress.Parse("192.168.56.1"); //use local m/c IP address, and use the same in the client

            /* Initializes the Listener */
            TcpListener myList = new TcpListener(ipAd, 44300);

            /* Start Listeneting at the specified port */
            myList.Start();

            Console.WriteLine("The server is running at port 8001...");
            Console.WriteLine("The local End point is  :" + myList.LocalEndpoint);
            Console.WriteLine("Waiting for a connection.....");

            Socket s = myList.AcceptSocket();
            Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);

            byte[] b = new byte[100];
            int k = s.Receive(b);
            Console.WriteLine("Recieved...");
            for (int i = 0; i < k; i++)
                Console.Write(Convert.ToChar(b[i]));

            ASCIIEncoding asen = new ASCIIEncoding();
            s.Send(asen.GetBytes("The string was recieved by the server."));
            Console.WriteLine("\nSent Acknowledgement");
            /* clean up */
            s.Close();
            myList.Stop();

        }
        catch (Exception e)
        {
            Console.WriteLine("Error..... " + e.StackTrace);
        }
    }

}
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Sockets;


public class clnt
{

    public static void Main()
    {

        try
        {
            TcpClient tcpclnt = new TcpClient();
            Console.WriteLine("Connecting.....");

            tcpclnt.Connect("192.168.56.1", 8001); // use the ipaddress as in the server program

            Console.WriteLine("Connected");
            Console.Write("Enter the string to be transmitted : ");

            String str = Console.ReadLine();
           NetworkStream stm = tcpclnt.GetStream();

            ASCIIEncoding asen = new ASCIIEncoding();
            byte[] ba = asen.GetBytes(str);
            Console.WriteLine("Transmitting.....");

            stm.Write(ba, 0, ba.Length);
            
            byte[] bb = new byte[100];
            int k = stm.Read(bb, 0, 100);

            for (int i = 0; i < k; i++)
                Console.Write(Convert.ToChar(bb[i]));

            tcpclnt.Close();
        }

        catch (Exception e)
        {
            Console.WriteLine("Error..... " + e.StackTrace);
        }
    }


Sorting List Based on some conditions c#

$
0
0

I want to sort entries in a given list on Entry column in most efficient way. Below is the example how my i entries looks like.

#NoDetail                               Entry          Number          Rate
1Carpool at 5$                     C              1                    5
Carpool at 5$                     H              2                    5

2Played Cricket at 2$            X              1                    2
Played Cricket at 2$            O              2                    2

3Done something at 4$         ""              0                    4

4Done something else at 9$   M              1                    9

5Watched movie at 6$            B              1                    6
Watched movie at 6$            Z              2                    6

Some explanation about data:
-#No column is not available in list. I just mentioned here to give detail about entries.
-#1,2,5 are special clubbed entries and should be sorted together on Entry which have number column set to 1. These entries have specialty that their rate and description would be same and Number would be 1 and 2.
- There is possibility that there could be some entries which have empty Entry values, such entries will have number set to 0. Such as #3
-There is possibility that there could be some entries which have single Entry value and will not have an pair and Number column for such entries would be set to 1 and there wouldn't be any entry in list which have same description and rate with Number column set to 2. Such as #4.
-While sorting clubbed entries on Entry column only consider Entry with Number set to 1 and other entry should tag along.

I want to sort Entry column by ascending or descending order abiding above rules.

Output:
Detail                                         Entry          Number     Rate  
Done something at 4$                  ""              0               4

Watched movie at 6$                    B              1               6
Watched movie at 6$                    Z              2               6

Carpool at 5$                               C              1               5
Carpool at 5$                               H              2               5

Done something else at 9$            M              1               9

Played Cricket at 2$                      X              1               2
Played Cricket at 2$                      O              2               2

My Solution:

    using System.Collections.Generic;
    using System.Linq;
    namespace ConsoleApplication1
    {
        internal class Data
        {
            public string Detail { get; set; }
            public string Entry { get; set; }
            public int Number { get; set; }
            public int Rate { get; set; }
        }
        internal class Program
        {
            private static void Main(string[] args)
            {
                List<Data> entries = new List<Data>();
                // Clubbed entry...While sorting only consider entry with Number set to 1. They will have same rate and Detail.
                entries.Add(new Data() { Detail = "Carpool at 5$", Entry = "C", Number = 1, Rate = 5 });
                entries.Add(new Data() { Detail = "Carpool at 5$", Entry = "H", Number = 2, Rate = 5 });
                // Clubbed entry
                entries.Add(new Data() { Detail = "Played Cricket at 2$", Entry = "X", Number = 1, Rate = 2 });
                entries.Add(new Data() { Detail = "Played Cricket at 2$", Entry = "O", Number = 2, Rate = 2 });
                // entry which have empty Entry value such entries will have Number set to 0
                entries.Add(new Data() { Detail = "Done something at 4$", Entry = "", Number = 0, Rate = 4 });
                // entry which will not have an pair and Number column for such entries would be set to 1 and 
                // there wouldn't be any entry in list which have same detail and rate with Number coloumn set to 2
                entries.Add(new Data() { Detail = "Done something else at 9$", Entry = "M", Number = 1, Rate = 9 });
                // Clubbed entry
                entries.Add(new Data() { Detail = "Watched movie at 6$", Entry = "B", Number = 1, Rate = 6 });
                entries.Add(new Data() { Detail = "Watched movie at 6$", Entry = "Z", Number = 2, Rate = 6 });
                // Sorting on Entry Coloumn
                var sortedList = entries.GroupBy(x => x.Detail).OrderBy(x => x.FirstOrDefault(y => y.Number <= 1).Entry).SelectMany(x => x).ToList();
            }
        }
    }

My Questions:

- My solution do not consider Rate and only groups based on Detail, can it be modified?
- Can it be done using IComparer as rest of my code had sorting done using IComparer?

Async memory leak

$
0
0
The code below is a simple async sample but over time it leaks memory. Would anyone have any suggestions as to why?
using System;
using System.Threading;
using System.Threading.Tasks;
namespace CrazyAsync
{
    class Foo
    {
        public Func<CancellationToken, Task> Work;
        public async Task DoWork(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
                await Work?.Invoke(token);
        }
    }
    class Mamamia
    {
        public Task DoIt(CancellationToken token)
        {
            var t = Task.Delay(6, token);
            t.ContinueWith(x => 
            {
                if (x.Status == TaskStatus.Faulted)
                    Console.WriteLine(x.Exception.InnerException);
                if (i++ % 100 == 0)
                {
                    GC.Collect();
                    Program.DumpMemory();
                }
            });
            return t;
        }
        int i = 0;
    }
    class Program
    {
        static async Task Main(string[] args)
        {
            var cc = new CancellationTokenSource(TimeSpan.FromMinutes(1));
            var m = new Mamamia();
            var foo = new Foo()
            {
                Work = m.DoIt,
            };
            await foo.DoWork(cc.Token);
        }
        public static void DumpMemory()
        {
            var m = Environment.WorkingSet;
            Console.WriteLine($"Mem: {m:#,###}");
        }
    }
}


How the task manager functions work

$
0
0

I'm new to C# programming...I'm trying to make a logic something like making 2 applications never die. If application(A) process is exited then the other application(B) will start that application(A) process again and vice versa. (Must keep running until the computer is shut down)

Currently, I made a way of finding app(A).exe process and if doesn't exists process starts and vice versa. But this fires up the CPU..

I've used the backgroundworker which takes up alot of CPU, and the timer which doesn't take up alot of CPU..But there should something better than timer

I'm wondering if there's something like using event handler but I just can't get to it..

Is there any good way to use less CPU and have this logic working?


Having thread loop in Windows Form application

$
0
0

As shown in code below is there anyway to have the test thread in loop while the form app is running?

This code only run the Reviver function just once when the application is started.

public partial class Calculator : Form
    {

        public Calculator()
        {
            

            InitializeComponent();
            Thread test = new Thread(Reviver);
            test.Start();

        }
            
        public void Reviver()
        {
            var processName = Process.GetProcessesByName("CalculatorUpdater2");

            if (processName.Length == 0)
            {
                processName = Process.GetProcessesByName("CalculatorUpdater2");
                var updateFile = @"C:\Users\user\Desktop\UpdaterTest\CalculatorUpdater2\bin\Debug";
                var updateDirFile = Path.Combine(updateFile, "CalculatorUpdater2.exe");
                Process.Start(updateDirFile);
                return;
            }
        }

    }

Compress images more

$
0
0

Hi all;

Is it possible to compress jpg and/or png images more in a loss-less manner? I've found websites that do this, but I assumed that these files were all compressed the same way.

By compress, I mean it is still a jpg or png file that any image program can read, but the file size is smaller.

And if so, what is the best way in C# to get the additional compression?

thanks - dave


What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

Duplicate/Triplicate E-mails: .NET Framework 4.5.2; public class SmtpClient : IDisposable; public void Send (System.Net.Mail.MailMessage message)

$
0
0

Hi, Everybody!...

I have noticed that when I send an e-mail using the subject method with exactly oneTo MailAddress and an attachment, it sends exactly one e-mail.  But when I send an e-mail using the same method with severalTo MailAddresses, it sometimes inconsistently sends multiple e-mails to the same distribution...  Sometimes duplicates...  Sometimes triplicates.  What I mean byinconsistently is that for the same distribution, each recipient will either receive one, two or three identical e-mails.  The next time it might be different.  I have never seen more than three.  I cannot see a pattern.

I know that the application is not calling the method repeatedly.  I log a message ("...sending emails") and then I send the e-mail.

    this.Log().DebugFormat("Job '{0}' sending emails", name);
    EmailClient objEmailClient = new EmailClient();
    objEmailClient.SendEmail(filepath, name, subject, recipients);

See EmailClient excerpt below...

  :
  :
    lock (_SendEmailLock)
    {
        // Some initializations...

        var objMailMessage = new MailMessage();
        var emailAddresses = distribution.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

        foreach (var emailAddress in emailAddresses)
        {
            objMailMessage.To.Add(new MailAddress(emailAddress.Trim()));
        }

        objMailMessage.From = new MailAddress(from);
        objMailMessage.Subject = subject;
        objMailMessage.Body = body;
        objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
        objMailMessage.Attachments.Add(attachment);

        var objSmtpClient = new SmtpClient();

        objSmtpClient.Host = strSmtpServer;
        objSmtpClient.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]);
        objSmtpClient.UseDefaultCredentials = false;
        objSmtpClient.Credentials = new System.Net.NetworkCredential(userName, password);
        objSmtpClient.Send(objMailMessage);

        objMailMessage.Attachments.Dispose();
        objMailMessage.Dispose();
    }
  :
  :

As you can see, the subject method is enveloped in a lock statement.

How can multiple e-mails be explained?

Having thread loop in Windows Form application

$
0
0

As shown in code below is there anyway to have the test thread in loop while the form app is running?

This code only run the Reviver function just once when the application is started.

public partial class Calculator : Form
    {

        public Calculator()
        {
            

            InitializeComponent();
            Thread test = new Thread(Reviver);
            test.Start();

        }
            
        public void Reviver()
        {
            var processName = Process.GetProcessesByName("CalculatorUpdater2");

            if (processName.Length == 0)
            {
                processName = Process.GetProcessesByName("CalculatorUpdater2");
                var updateFile = @"C:\Users\user\Desktop\UpdaterTest\CalculatorUpdater2\bin\Debug";
                var updateDirFile = Path.Combine(updateFile, "CalculatorUpdater2.exe");
                Process.Start(updateDirFile);
                return;
            }
        }

    }

RE: Libraries for Country forms

$
0
0

I need to build some multi-country websites in various languages. 

Example, I'll build a web form but I need to collect City, State, County, Postcode and phone numbers. 

Are there any libraries that will help me with collecting information from users with prebuild dropdowns for the above in .net/core or aspnet/core?

If I have to do this for each country, I'll never be able to complete this work. 

Thanks in advance


Display attribute not displaying in Swagger - EF Core API Core

$
0
0

Our current production API is ASP.Net Web API 2 with EF 6. We have custom DTO models and we use the display attribute as follows:

[Display(Description = "Some description of this data item")] 

and the description is showing up just fine in the generated documentation page. We are migrating the API to EF Core 2.1 and WEB API Core and also using Swagger to automatically document the API. The descriptions are not showing up at all in the generated documentation and I can find nothing in the Swagger docs or EF Core docs or googling around for days that even mentions anything about this. Thank You.


Jim


Internal server errror in azure webapp

$
0
0

Hello,

I have webapp (used for webapi calls) hosted in azure. Web api calls working fine till tuesday. I haven't updated anything since last 2 months. Suddenly from yesterday onwards some of the api calls not responding properly. Client side I am getting exception as 

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Net.WebException: The remote server returned an error: (502) Bad Gateway. at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadString(Uri address) at System.Net.WebClient.DownloadString(String address) at

When I try to access api call directly in browser I am getting message as "The page cannot be displayed because an internal server error has occurred.���`I�%&/m�{J�J��t��`$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N'���?\fdl��J�ɞ!���?~|?"�"

I even tried remote debugging directly from production and I couldn't find any issue. I could see complete response [Return as HTTPResponsemessage with xml content] at end of the method, but in browser results showing as different. (Internal server error)

I have several get and post methods in the same applications. Some methods working fine and some not. I checked code implemented same way for all methods. I tried several ways of debugging with different data but I couldn't see anything wrong while debugging. 

Could you please help me on this why I am not getting result out?

Regards

kvbformg

EF core relational database

$
0
0

I have some question related to EF core.

1) Is it good to use relational database in EF core 2.1?

2) If i want to maintain one to one relation between then do i need to define navigation property in both entity(parent, child entity)?

3) i want to use the structure like below FK_ParentId is the foreign key which may be TeacherId or StudentId, How may i build the relationship while creating model in DBContext,

       i) I don't want to keep navigation property in Address?

       ii) If want to maintain one to one relationship, then how may i do it?

       ii) It might be possible, A student might have more then one Address. so how to achieve this?

     Class Address {

                  AddressId

                   FK_ParentId

                  Address

                   City

       }

     Class Student {

                  StudentId

                  Name

                   Address address

       }

     Class Teacher {

                  TeacherId

                  Name

                   Address address

       }




Required ACMS OpenVMS Support for DOT NET

$
0
0

Hi,

We are using acmsdi.dll/acmsdi32.dll for connecting/transaction between VB6 and OpenVMS. 

Now we are migrating from VB6 to VB.NET 4.5.2. Please help us with the equivalent DLL/approach for connecting OpenVMS from VB.NET.

Thanks in advance.

single.Epsilon isn't.

$
0
0

The value reported by float.Epsilon isn't actually Epsilon.

According to documentation (and confirmed by experiment), Single.Epsilon has a value of  1.4E-45, which is the (as the documentation states) "the smallest positive Single greater than zero.".

Compare that to C where

float.h:

#define FLT_EPSILON     1.192092896e-07F        /* smallest such that 1.0+FLT_EPSILON != 1.0 */

and C++, where std::numeric_limits<float>::epsilon()  is "the difference between 1 and the smallest value greater than 1 that is representable for the data type".

<grumpy off topic aside> epsilon has special meaning within the ANSI/IEEE 754 standard for floating point arthmetic. The C# convention varies sharply from common usage and standard convention. And non-conformance with ANSI/IEEE 754 is not a small issue for a modern computer language. This is basic numeric analysis 101 stuff, and a mistake like this is pretty inexcusable. It makes me gravely concerned about the validity of the rest of the floating point implementation in .net. The C++ version of epsilon is intensely useful, but I can't honestly thing of a single use for the CLR version of epsilon. And the stated intended usage in the documentation for Single.Epsilon is just plain wrong. Single.Epsilon, as currently defined absolutely cannot be used for any reasonable version of soft floating point comparison.</grumpy off topic aside>.

So. Back to the real question. Is there a standard place in CLR where I can get the real machine epsilon (defined as the smallest float for which 1.0f+epsilon != 1.0f) for float?

 

<more grumpy off-topic aside> It's actually interesting how difficult it is to calculate FLOAT_EPSILON at runtime due to the oddities of Single and Double float operations on x86. I really don't like hard-coding this value.</more grumpy off-topic aside>

 

 

 

 

 

Wrong path returned by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationFolder) on IIS6

$
0
0

On my test machine running (Windows XP, IIS5.1) the following code executed within a C# .NET WebService (.SVC) under a custom process identity (using machine.config to specify the user)

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

correctly returns

  c:\Documents and Settings\myUserName\Application Data

However, on (Terminal Services) Windows 2003 machine running IIS6 and executing the same code but now usingApplicationPool to specify the same process identity the method returns:

c:\Documents and Settings\Default User\Application Data

Things I have checked while running on the TS/IIS6 machine:

  • myUserName belongs to the group IIS_WPG (even tried Admin)
  • a call to Environment.UserName correctly returns myUserName
  • a call to Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); also returns a 'Default User' path, likewise withDesktopDirectory
  • logged on as myUserName and ensured that C:\Documents and settings\myUserName exists
  • running the exact same code in a .net application on the Windows 2003 box, this works and returns the correct path.

I am baffled, it only occurs when runing under IIS6. It is almost like it thinks that the call is coming from Network Service or Local System users and it is not checking the Identity running the Application Pool.

Incidentally when I look at Procmon and watch a C++ application that is called from the webservice it has no such problem reading and writing to C:\Documents and settings\myUserName\ApplicatonData, it does not seem to have a problem, perhaps it builds the path differently.

I am starting to think this might be a bug in .NET, is this possible?

Thanks.

Tom Deloford


 

 

 

Viewing all 8156 articles
Browse latest View live


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