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

How to protect my dll by only allowing my project to use.

$
0
0

Hi All,

i would like to create an encryption DLL where only my application can instantiate the dll. May i know if there is any solution to this as i would not like other application to use the DLL.

regards,

Joh


SNMP Traps in C#

$
0
0
Hi i'm doing snmp traps i want to do like if the cable is plug out from the switch or the router, my program in C# will prompt the user saying that the port "1" is being plug out in messagebox. is it possible to do it? i'm still a newbie programmer 

patch server

$
0
0
can anyone tel what do you mean by patch server and the link for know more about it indepth

When signing 2 GB XML file SignedXml.ComputeSignature throwing out of memory exception in 64 bit windows with 8 GB RAM

$
0
0
I am trying to sign a 2 GB XML file using  SignedXML.ComputeSignature however i am getting out of memory exception. I am using 64 bit machine with 8 GB RAM.It may be because of the file size. While computing the signature the function loads whole XML file into the memory. Do we have any alternative ay to sign an XML file. Is it possible in to sign XML file in chucks or stream.

Guid becomes NULL after a while

$
0
0

Hi to everyone

Currently I'm facing a very weird issue.

I have a GUID variable which is static and which has a value from DB (and everything it's fine) and I use it through the code 

but after a while it just became NULL, without assigning any values..

and I don't have any ideas how that can be, the variable suppose to keep it's value if it's static, right?

Thank you in advance for helping me to solve this problem.

Vadim

Online file converter in c# using asp.net with mvc3

$
0
0

hi every one i am develping a online file converter in c sharp using asp.net with mvc3. i dont found the which .net libraries are used for video and audio format conversion and also for image,doc, and other related

Thanks

Dynamic tabs in C#

$
0
0
I want to create a form with the tab if user clicks "add new tab" the 2nd tab will have the same content as tab 1, if user add tab again, the new 3rd tab will also follow the same content as tab 1 is it possible?

App Crash

$
0
0

Hi ,I am using a  background thread in order to generate the World  files,

My windows application file works fines at local environment,but on server my application crash  with these problem details.

Please help me how to catch the application crash reason.

Error :

Description:
   Stopped working

Problem signature:
   Problem Event Name:APPCRASH
   ApplicationName:MyApp.exe
   Application Version:2.0.0.0
   ApplicationTimestamp: 523c2a57
   FaultModule Name:winhttp.dll
   FaultModule Version:6.1.7600.16385
   FaultModuleTimestamp:4a5bdb3e
   Exception Code: c0000005
   ExceptionOffset:000015cb
   OS Version:6.1.7600.2.0.0.16.7
   Locale ID:2055

Read ourprivacy statement online:
   http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0407

Ifthe online privacystatement is not available, please readourprivacy statement offline:
   C:\Windows \ system32 \en-US\erofflps.txt


rishi


Windows Service hangs python script execution

$
0
0

Hi there

Currently i have a windows service that preforms some database operations via entity framework fallowed by the execution of a python script.

This script runs very well directly in the command line (cmd.exe). It happens that it hangs almost every time when run from the windows service or a console application.

My guess is that the problem related to threads. I’ll try to be concise and not to paste to many code but here it is:

In the windows service I have a threaded timer (System.Threading.Timer) that ticks until a given hour, and then starts the worker process that executes the database operations and python execution:

//Locker to prevent more than one worker process at the same time
private readonly object locker = new object();
…..

public void Worker(object state)
{

   if (Monitor.TryEnter(locker))
   {
     try
     {

	//Should i run?
	var now = System.DateTime.Now;

	if (now < timeToRun.AddMinutes(5) && now > timeToRun.AddMinutes(-5))
	{
              //Run the process
	     ExecuteWorkerProcess();              
	}

       }
       catch (Exception ex)
       {
	logger.LogException(...);
        }
        finally
        {
	Monitor.Exit(locker);
         }
     }

}

Inside the worker process is this:

…..
//Async as in with events
IAction script = new AsyncPythonScript(arguments, fileName, scriptFolder, logger);
script.Execute();
…..

Now, the part that hangs:

public void Execute()
{
	proc = new System.Diagnostics.Process();

	try
	{

		if (!System.IO.Directory.Exists(scriptFolder))
		{
			logger.LogWarning(String.Format("Could not find {0} directory ", scriptFolder));
			return;
		}

		System.IO.Directory.SetCurrentDirectory(scriptFolder);

		logger.LogDebug(String.Format("Current execution directory:{0}", System.IO.Directory.GetCurrentDirectory()));

		ProcessStartInfo arg = new ProcessStartInfo()
		{
			Arguments = string.Concat(scriptFolder, @"\", arguments),
			FileName = fileName
		};


		logger.LogDebug("Process parameters:");
		logger.LogDebug(String.Format("Arguments:{0}", arg.Arguments));
		logger.LogDebug(String.Format("FileName:{0}", arg.FileName));


		proc.StartInfo = arg;

		proc.StartInfo.UseShellExecute = false;
		proc.StartInfo.CreateNoWindow = false;
		proc.StartInfo.RedirectStandardOutput = true;
		proc.StartInfo.RedirectStandardError = true;
		proc.StartInfo.RedirectStandardOutput = true;

		proc.EnableRaisingEvents = true;
		proc.Exited += new EventHandler(proc_Exited);

		proc.Start();


		logger.LogDebug("Async process started.");

	}
	catch (Exception ex)
	{
		logger.LogException("Exception from python process:", ex);

		//try kill the process
		try
		{
			if (proc != null)
			{
				proc.Close();
				proc.Dispose();

				logger.LogDebug("Process closed and disposed of.");
			}
		}
		catch //if we cant dispose the process it´s because there is nothing to dispose
		{
		}
	}

}



void proc_Exited(object sender, EventArgs e)
{

	logger.LogDebug("Process exited");

	try
	{

		string stderr = proc.StandardError.ReadToEnd();
		string stdout = proc.StandardOutput.ReadToEnd();


		logger.LogDebug("Dump from python output");
		logger.LogDebug(stdout);

		if (!string.IsNullOrEmpty(stderr))
		{
			logger.LogWarning("Error log from python process:" + stderr);
		}

		proc.Close();
		proc.Dispose();
		logger.LogDebug("Process closed and disposed of.");
	}
	catch (Exception ex)
	{
		logger.LogException("An exception was thrown when the process exited", ex);
	}
}

In this case the exit event is never reached.

I have tried to run this with proc.WaitForExit() and the result is the same, the process never ends......

Can anyone of you see something I don’t?

Thanks


Jorge Vinagre

Authenticate Cross Domain User with Active Directory

$
0
0

Hi All,

Can any one suggest me how to authenticate cross domain user with active directory and with in different network?

Ex: suppose we run our application on "abc" domain and active directory is on "def" so how we can authenticate it using directory services.


Prevent timeout with system.net.ftpclient and FTP Server with lots of files

$
0
0

We have an FTP Server that has thousands of files in the root folder. I've written a simple program that will use the system.net.ftpclient to loop through all the files, creating folders for every 1000 files and move the files to the created folder. My program works on my test FTP server with only a handful of files.

When I run the program against our production FTP server, the ftpclient.getlisting method fails after 15 to 20 seconds on timeout. Using another FTP client (WINSCP) takes a long time (30 secs+) to retrieve the file list on the same production FTP server which tells me that the FTP server is going to take a long time to return the directory contents. I have tried increasing all of the timeout parameters that I was able to find to much larger values, but I still get the timeouts.

Here's my code (with server connection details hidden);

    Private Sub TestFTPButton_Click(sender As Object, e As EventArgs) Handles TestFTPButton.Click

        Dim myFTP As New FtpClient()
        myFTP.Host = "ftp server name"
        myFTP.Credentials = New Net.NetworkCredential("UserName", "Password")
        myFTP.SetWorkingDirectory("/")
        Dim newFolderName As String = ""
        myFTP.ConnectTimeout = 3000000
        myFTP.DataConnectionReadTimeout = 3000000
        myFTP.DataConnectionConnectTimeout = 3000000
        myFTP.ReadTimeout = 3000000
        myFTP.SocketKeepAlive = True
        myFTP.SocketPollInterval = 0
        myFTP.EnableThreadSafeDataConnections = False
        myFTP.Connect()
        Dim filesProcessedCounter As Integer = 0
        For Each ftpItem In myFTP.GetListing(myFTP.GetWorkingDirectory())
            If Not ftpItem.Type = FtpFileSystemObjectType.File Then         ' We must ignore things that aren't files.
                Continue For
            End If
            If newFolderName = "" Then                                      ' If we haven't created a folder to store files in yet,
                newFolderName = DetermineFolderName(ftpItem.FullName, ftpItem.Modified) ' We need to invoke a subroutine to use filename and date for a reasonable folder name
                myFTP.CreateDirectory(newFolderName, True)
            End If
            Dim renameDest As String = newFolderName & "/" & ftpItem.Name
            myFTP.Rename(ftpItem.FullName, renameDest)                                      ' Use FTP's rename function to move the file to the new folder
            filesProcessedCounter += 1                                                      ' keep a track of how many files we've done
            If filesProcessedCounter >= FilesPerFolder Then                                 ' so that we don't put too many files in one folder
                newFolderName = ""                                                          ' clear the folder name so that we invoke the code to create a new one
                filesProcessedCounter = 0                                                   ' and start the counter again
                Exit For
            End If
        Next
        myFTP.Disconnect()
    End Sub

Question

$
0
0

I have to use array index upto 4294967296 to store all IP addresses , what language I use that will support array indices from 0 to 4294967296?

waiting for your favorable response.

System.DirectoryServices: Change Type interpretation for attributes

$
0
0

Hi, I have a kind of specific problem. I am accessing an OpenLDAP server with System.DirectoryServices. Connection, searching and retrieving properties works just fine.

However, one attribute I need to read has very large integer values in it that may (and do) exceed the maximum value for Int32.

The attribute (shadowexpire) is defined with the syntax OID 1.3.6.1.4.1.1466.115.121.1.27, which is INTEGER. The library classes interpret this as an Int32, which is acurate according to http://msdn.microsoft.com/en-us/library/ms180868(v=vs.80).aspx.

As the attribute's values do exceed the maximum value for Int32, the results I get back are not the same as in the LDAP.

I cannot change the attribute's syntax, so... is there a way around to this? Is it possible, for example, to tell the library to interpret INTEGER as an Int64 or String (which I then could parse)?

Thanks for any hints!

Gregor

Outlook type meeting recurrence for email notication

$
0
0

Hi Experts,

In my project, we have a module to send an meeting request same as outlook which includes meeting recurrence. This is C#, Asp.net web application. As per design, I have to write a Windows service which will send email notification as per meeting request timings which can be recurring also. Can you please provide me any logic or working code for windows service which can help me achieve the same. ?

thanks in advance.

why I do not find System.IO.Compression.ZipFile

$
0
0

I've the .net 4.5 & 4.5.1 installed but if I try (as from example By Microsoft):

Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim startPathAs String = "c:\example\start" 
        Dim zipPathAs String = "c:\example\result.zip" 
        Dim extractPathAs String = "c:\example\extract"

        ZipFile.CreateFromDirectory(startPath, zipPath)

        ZipFile.ExtractToDirectory(zipPath, extractPath)
    End Sub 

End Module

The system is not finding the command ZipFile

What mistake I've done?


Calling a CE Compiled DLL from a Desktop Application

$
0
0

 I'm customizing an ERP program that uses the Visual Studio IDE to allow customization. The ERP is a desktop application and I'm trying to integrate the customer's scanners with the ERP program. The scanners are Motorola MC92 and they use Windows 7 Embedded Compact. The customization that I'm using requires that I use a dll from Motorola that was compiled with .NET Compact Framework. So when I run the customization now with my code calling their dll, I get a Unable to load CoreDLL.dll file on load. 

Is there any way to use this dll that references the compact framework in my desktop application, which I can't recompile the any references. Is there a way to reference a .NET compact framework dll during runtime and have the manufacturer's dll point to that? 


MCTS

XSD System.Xml.Schema.XmlSchemaSequence.Items property not giving inner sequence

$
0
0

Hello,

I'm working on a project that takes xsd file as an input, compiles the schema in XmlSchemaSet and then iterates over the elements in compiled schema.

I'm using property XmlSchemaSequence.Items and XmlSchemaChoice.Items to iterate over the XmlSchemaObject inside them.

following is a sample complex type that I'm using

<xs:complexType name="aaa">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="hi" type="xs:string" />
      <xs:choice maxOccurs="unbounded">
        <xs:element name="v" type="xs:byte"/>
        <xs:sequence maxOccurs="unbounded">
          <xs:element name="z" type="xs:byte"/>
        </xs:sequence>
      </xs:choice>
      <xs:sequence maxOccurs="unbounded">
        <xs:element name="y" type="xs:byte"/>
      </xs:sequence>
    </xs:sequence>
  </xs:complexType>

I get inner sequence  from Items property when MaxOccur is set to greater than 1, also, I'm getting choice inside sequence without maxOccur attribute. but, for the other cases of nested choice and sequence, if I removed the maxOccur attribute or set to less than or equal to 1, Items property gives me elements inside them and not the sequence or choice as XmlSchemaObject. 

please tell me how do I get inner/nested sequence or choice even if maxOccur attribute is not present.

please help!!!

VS style Object Watch Window

$
0
0

I would like to watch and interact with a object during runtime in my WinForm App.

How do I embed a VS watch windows in my WinForm App? Is there for a control for this?


-SD

Drag and Drop from server explorer not working

$
0
0

I found today that drag and drop from server it's not working.

I think that's because I've installed some days ago VS 11 Beta.

After that I faound many problems with .NET 4.5 so I've uninstall it but it seems something remains there.

Or maybe because I've updated the database to SQL Server 2012.

How can I correct this ?

I am using Visual Studio 2010 SP1

Thank you !


Sorin Sandu

Calling SHGetFileInfo in C# - Win x64

$
0
0

I am using the Knowledge Base example on how to call SHGetFileInfo in C# and I am also retrieving File Type Names for my application. I have noticed something strange though; If I compile my application for the x64 platform (or leave as any CPU and run on a 64-bit system), a part of the string isn't returned. For example if i pass app.exe, in 32-bit systems i get "Application". In x64 systems I get "ication". I played around with the attribute data types and concluded that the smaller the data type, the more characters it will return. Specifically: if I declare sbyte dwAttributes instead of uint as the KB article suggests, I return "pplication". I was wondering if there is a solution to this issue.

The code had the same result on Vista x64 and Windows XP x64 (.NET 2.0).

Source Code:

Code Snippet

using

System;

using

System.Collections.Generic;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Text;

using

System.Windows.Forms;

using

System.Runtime.InteropServices;

namespace

WindowsApplication1

{

publicpartialclassForm1 : Form

{

public Form1()

{

InitializeComponent();

this.Text = GetFileTypeDisplayName(Application.ExecutablePath);

}

publicconstuint SHGFI_ICON = 0x000000100;

publicconstuint SHGFI_DISPLAYNAME = 0x000000200;

publicconstuint SHGFI_TYPENAME = 0x000000400;

publicconstuint SHGFI_ATTRIBUTES = 0x000000800;

publicconstuint SHGFI_ICONLOCATION = 0x000001000;

publicconstuint SHGFI_EXETYPE = 0x000002000;

publicconstuint SHGFI_SYSICONINDEX = 0x000004000;

publicconstuint SHGFI_LINKOVERLAY = 0x000008000;

publicconstuint SHGFI_SELECTED = 0x000010000;

publicconstuint SHGFI_ATTR_SPECIFIED = 0x000020000;

publicconstuint SHGFI_LARGEICON = 0x000000000;

publicconstuint SHGFI_SMALLICON = 0x000000001;

publicconstuint SHGFI_OPENICON = 0x000000002;

publicconstuint SHGFI_SHELLICONSIZE = 0x000000004;

publicconstuint SHGFI_PIDL = 0x000000008;

publicconstuint SHGFI_USEFILEATTRIBUTES = 0x000000010;

publicconstuint SHGFI_ADDOVERLAYS = 0x000000020;

publicconstuint SHGFI_OVERLAYINDEX = 0x000000040;

// public const uint SHGFI_ICON = 0x100;

// public const uint SHGFI_LARGEICON = 0x0; // 'Large icon

// public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

publicconstuint ILD_TRANSPARENT = 0x1;

[DllImport("shell32.dll", CharSet = CharSet.Ansi)]

publicstaticexternIntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, refSHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);

[DllImport("user32")]

publicstaticexternint DestroyIcon(IntPtr hIcon);

publicstatic System.Drawing.Icon getIconFromFilename(string fName)

{

////IntPtr hImgSmall; //the handle to the system image list

//IntPtr hImgLarge; //the handle to the system image list

SHFILEINFO shinfo = newSHFILEINFO();

Form1.SHGetFileInfo(fName, 0, ref shinfo,

(uint)Marshal.SizeOf(shinfo),

// WindowsApi.SHGFI_ICON |

// WindowsApi.SHGFI_SMALLICON |

// WindowsApi.SHGFI_ADDOVERLAYS |

// WindowsApi.SHGFI_OVERLAYINDEX |

Form1.SHGFI_USEFILEATTRIBUTES |

//WindowsApi.SHGFI_SMALLICON |

Form1.SHGFI_ICON// | WindowsApi.SHGFI_LARGEICON //|

// WindowsApi.SHGFI_TYPENAME |

// WindowsApi.SHGFI_DISPLAYNAME |

//WindowsApi.SHGFI_LINKOVERLAY

// WindowsApi.SHGFI_SYSICONINDEX

);

//Use this to get the large Icon

//hImgLarge = SHGetFileInfo(fName, 0,

//ref shinfo, (uint)Marshal.SizeOf(shinfo),

//WindowsApi.SHGFI_ICON | WindowsApi.SHGFI_LARGEICON);

//The icon is returned in the hIcon member of the shinfo

//struct

System.Drawing.Icon myIcon = (System.Drawing.Icon)(System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone());

Form1.DestroyIcon(shinfo.hIcon);

return myIcon;

}

publicstaticstring GetFileTypeDisplayName(string fileName)

{

SHFILEINFO shinfo = newSHFILEINFO();

Form1.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)Form1.SHGFI_USEFILEATTRIBUTES |

Form1.SHGFI_TYPENAME | Form1.SHGFI_DISPLAYNAME);

return shinfo.szTypeName;

}

 

 

[StructLayout(LayoutKind.Sequential)]

publicstructSHFILEINFO

{

publicIntPtr hIcon;

publicIntPtr iIcon;

publicuint dwAttributes;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]

publicstring szDisplayName;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]

publicstring szTypeName;

};

}

}

 

 

Viewing all 8156 articles
Browse latest View live


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