Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all 1710 articles
Browse latest View live

How to block and unblock the ctrl-c singal in my windows application?

$
0
0

Hi,

I am having a use case where I want to block the ctrl-c signal generated by console application for doing some processing and then after the processing is done I would like to continue with the program by handling the ctrl-c signal handler.

I am able to do this successfully on UNIX platfroms by using

sigprocmask(SIG_BLOCK   and

sigprocmask(SIG_UNBLOCK, But i am not able to do the same on windows platform.

For implementing the same on windows i am using below logic:

 signal(SIGINT, signal_handler); // To register the signal with the program
 if( SetConsoleCtrlHandler( NULL, TRUE ) == 1) // this will disable the signal handler
  { 
  Sleep(5000);
  } else {
   printf("failed to disable the signal handler.\n");
  }

if( SetConsoleCtrlHandler( NULL, FALSE ) ){ // this will enable the signal handler after the sleep is over
  Sleep(5000);
}

Here the issue I am facing is if user presses ctrl-c before the  disabling the singal handler, then in that case the ctrl-c signal is getting ignored and I am missing it. So when the program comes back to signal handler by enabling it, then we are missing the signal.

I would like to know if there is any way in windows we can block and unblock the signals.

Any help will be really appreciated.

Thanks,

Sushil


Running Profiler inside certain IIS ASP.NET 4.0 apps results in error (Exception from HRESULT: 0x80131401)

$
0
0

I have a IL rewriting profiler which uses the profiling API to intercept JITs and writes prologue\epilogues calling a supporting C# assembly(HP.Diagnostics).

We have been running our product(HP Diagnostics)successfully in many customer environments with success but have recently observed the following problem.

The supporting C# Profiler Assembly(HP.Diagnostics gets the following error when running in certain IIS hosted ASP.NET (.NET 4.0) applications on Windows 2008 R2.

   System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)

The supporting profiler DLL(HP.Diagnostics) is installed and loaded from GAC and should have full trust.

The Profiler logs show that the supporting C# Assembly(HP.Diagnostics) is loaded in multiple application domains, first in the Appdomain of the IIS application and then the "EE Shared Assembly Repository". This seems to be the cause of the problem.

The logs below are generated by the ICorProfilerCallback::AssemblyLoadFinished callback.

2013.02.14.14.48.57.295  [000019C4]  INFO     AssemblyLoadFinished hrStatus(00000000) appDomainId(067CC730) appDomainName(/LM/W3SVC/2/ROOT-1-130053449274613565) assemblyId(06A87D00) assemblyName(HP.Diagnostics)
2013.02.14.14.48.57.310  [000019C4]  INFO     AssemblyLoadFinished hrStatus(00000000) appDomainId(FA2862B0) appDomainName(EE Shared Assembly Repository) assemblyId(06A87EC0) assemblyName(HP.Diagnostics)

How can we work around this problem ? Is there a fix for this issue ?

In certain IIS applications, e.g. SharePoint 2013, the behavior can be altered by changing the "trust" setting as shown below in the web.config file.

<trust level="Full" originUrl="" legacyCasModel="false" />

    <!--<trust level="Full" originUrl="" legacyCasModel="true" />-->

This does not work for all applications so we have no work around in certain scenarios.

Can somebody explain why changing the legacyCasModel="false"  changes the way the assemblies are loaded in different appdomains ?

Regards,

Sanjay


Sanjay Mehta

PerformanceCounter somehow locks my dll...

$
0
0

Hi,

I use this code from a Windows service:

using (var c = new PerformanceCounter("Process", Working Set", instance, true))
   return c.RawValue;

Which Works, no problems. The problems come when I shutdown the Windows service. My dll is locked for 4 seconds or so, after the service has shut Down. If I remove the PerformanceCounter lines I can delete the dll right after service shutdown.

Is this normal?

--
Werner

Cryptography_CSP_NoPrivateKey error

$
0
0

Hello,

 I'm trying to call a webservice with WSE 2.0 (sp3) in a code implemented in a NT service (developed in .net). To do this, I'm adding a certificate token and creating a sign element, but when I send the message the framework rises the following error:

Cryptography_CSP_NoPrivateKey

This error doesn't happen if I call the same code (exactly) from a windows application...

 

Does anyone know what could be generating this behaviour???

Is this something related with permissions on my user account and the localsystem account who runs the service???

 

Regards,

Markus

C++ Interop: embedding an array in a UDT

$
0
0
I have an application that involves a lot of communication between managed (C#) and unmanaged (C++) code. We are using Visual Studio 2005 (!), and we use the interop assembly generated automatically by tlbimp.

We have fairly good luck passing simple structs back and forth as function arguments. And because our objects are fairly simple, we can pack them into SAFEARRAYs using the IRecordInfo interface. Passing these arrays as arguments to COM methods seems to work properly.

We would like to be able to embed variable-length arrays in our UDTs, but this fails badly. I don't think I have been able to find a single piece of documentation showing how someone has accomplished this. Nor have I found documentation that says it can't be done.

1) Naive approach: Simply declare a safearray in the managed code:

struct MyUdt {
  int member1;
  BSTR member2;
  SAFEARRAY *m3;
};
The C++ compiler is happy with this, but the generated IDL confounds tblimp.exe. It reports that it is unable to convert the signature for member m3, and the signature for member tagSAFEARRAY.rgsabound. These are only warnings, but they are meaningful, the resulting assembly is not usable.

Using LPSAFEARRAY, oddly enough, fails in different ways, but for the same reason, tblimp just can't deal with it.

2) Trickier: Pack it into a variant:

struct MyUdt {
  int member1;
  BSTR member2;
  VARIANT m3;
};
We have code that builds safearrays of UDTs, and it never gives us any trouble. It's basically copied from MSDN. Using that code to create a safearray, then:

pVal->m3.vt = VT_SAFEARRAY | VT_RECORD;
pval->parray = p;
Fails in odd ways. It always breaks, some variations produce an OutOFMemoryException... odd, others fail in different ways. (I'm not sure if a pRecInfo pointer is required here or not, but it fails the same way, present or not.)

The Google search space for this is badly polluted with answers to questions that I am not asking:

* How do you pass UDT/structs from unmanaged code.
* How do you pass a SAFEARRAY of structs? (We're doing this fine.)
* How do you use p/invoke or customer marshalling to pass UDTs.

And many answers describing how to define things from the managed side, not the unmanaged side.

And then there are a couple of Microsoft KBs describing problems with VT_RECORD in early versions of .NET. I don't think these are germane - VT_RECORD types work with VARIANT and with SAFEARRAY. (But maybe not with the UDT marshallling...)

If this won't ever work, it would be nice to at least know why.

- Mark

Digital Signature Algorithm with Secure Hash Algorithm (DSAwithSHA1)

$
0
0
I have seen lot of codes but in that codes, no role of public key.
How to implement Digital Signature Algorithm with Secure Hash Algorithm (DSAwithSHA1) for verifying the digital signature using public key in C#?

Unknown error when using .NET 4.0 above with unmanaged dll

$
0
0

I have an application that using a 3rd party library, and it just works fine in .NET 3.5.

The function of the unmanaged library accepting a byte array as one of the parameter.

However, we have planned to upgrade to .NET 4.0 this year. And then we found a weird error after the upgrade.

I guess that unmanaged library was developed by C/C++. I have called the vendor and tell them my situation but they said it is NOT their issue. It should be .NET Framework issue and asked me to call support from Microsoft. But they won't provide any source code to us because it is confidential.

On the other side, Microsoft said they can't do anything without the source code.

Then, I was stuck by this issue for a few months ago.

Could anyone please give me some hints about where the issue came from??

The image below was captured by Visual Studio 2012 after I enabled the Native Code Debug:

Native code error by Visual Studio 2012


Anson

string Array performance

$
0
0

In a method I am using following code.

       string[] Array1 =newstring[] {"Orange","Mango","welcome","power","Street","Visual"};

       string[] Array2 =newstring[] {"Orange","Mango","welcome"};

       string[] Array3 =newstring[] {"Orange","Mango", "power","Street" };

       string[] Array4 =newstring[] {"Orange","welcome","power","Street" };

I have total 4 arrays some items are repeating in the array. I want to take only the common items from all the array.

What is the best technique to improve the performance.


Base64String generated result with incorrect size

$
0
0

I use Rfc2898DeriveBytes to hash password for asp.net login

        public void HashPassword(string password, string salt = null)
        {
            byte[] saltB = (salt == null) ? GenSalt() : Convert.FromBase64String(salt);
            if (salt == null) salt = Convert.ToBase64String(saltB);

            // test // salt.length is 172
        }

        internal byte[] GenSalt()
        {
            RNGCryptoServiceProvider p = new RNGCryptoServiceProvider();

            byte[] b = new byte[128];
            p.GetBytes(b);
            return b;
        }

I set the byte array to size 128, but after performed the ToBase64String, the size is 172.

I expecting it to be 128.

how should I rectify this?



Why we should install custom cultures on local machine?

$
0
0
In .NET there are some ready-made Cultures and user allowed to create custom cultures. My question is why we should install or uninstall custom cultures in user local machine? What is the reason that Microsoft decided to implement it in a this way?

Stack overflow exception in mscorlib due to multiple assembly versions of a dll

$
0
0

Hi, 

I have 2 class libraries in C# targeting .net framework 4.0. Both class libraries are referencing a dll named ANTLR3.Runtime.dll. Project A uses a reference of ANTLR3.Runtime version 1.0 and Project B uses a reference of ANTLR3.Runtime version 3.0. I need both the dlls in my solution and both the dlls copy local is set to true. When I debug my UI project that is referencing both projects A & B, I am getting a stack overflow exception. When looking at the call stack, the mscorlib's on assembly resolve event was looking for ANTLR3.Runtime version 1.0. I think one version is overwritten by the other because both dlls copy local is set to true and 2 dlls can not exists in bin/debug folder with same name. [though both dlls are signed]

I can not add one dll to GAC because my application is a clickonce and I dont want to write/register the dlls to client machine's GAC due to security reasons.

I tried using extern alias but not successful or may be I have done it incorrectly. If someone tell me clearly how to implement the extern alias that will be great. If not possible using this, I need some other simple solution.  

Any help on this would be greatly appreciated. 

Thanks,

Arun.K.S

Failing to Call COM exposed class

$
0
0

Background

I have a powerbuilder program attempting to call a C# class that is exposed as com visible. The C# class is compiled at .Net 2.0, and is being called from PB 11.5.1.

C# Com Visible attributes

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("MyID")]

When I compile my DLL (Any CPU architecture) I give it a strong key file. Does this key file need to be deployed with the DLL??? I do this because without it I cannot register the DLL in the GAC. I should note that i do not make the whole DLL com visible, just the classes I want in the COM.

I used regasm.exe to generate a reg file. The regasm.exe i used was located here: C:\Windows\Microsoft.NET\Framework\v2.0.50727

I did not use the /tlb flag, not sure if that should be used, or what it even does.

I don't understand whole lot in that registry file, I just notice PublicKeyToken = 908dbed57b0543c7

I then use gacutil to register the DLL in the GAC. I navigate to C:\windows\assembly and verify the DLL is in fact shown, and that the PublicKeyToken matches the one from the registry file.

gacutil /i "MyDLL.dll"

Finally I start Procmon and attempt to call the DLL, I don't see much in procmon that matches my DLL, I see it searching the registry and finding stuff, but thats about it. Nothing stands out to me anyways, and my program never actually gets to the DLL, which kinda feels like to me that its not finding stuff correctly in the registry/assembly.

This issue ONLY happens on a 64 bit Windows 7 PC. Haven't tried 64 bit Windows XP, I have my UAC all the way down, and I am admin to my PC. I have run out of ideas, so I decided to post here to see if anyone has some thoughts, or maybe has experienced a similar issue. I am sure I am misunderstanding something, any advice would be GREATLY appreciated.

SerialPort.ReadByte() from USB "virtual port"

$
0
0

Using win8, x64. .NET 4.5 and "ST-Lab USB Serial Cable" with Prolific driver ser2pl64.sys version 3.4.48.272.

I open a port and just go directly into a read loop with port.ReadByte().
If the buffer is empty when ReadByte() is called, it generates an IOException (The I/O operation has been aborted because of either a thread exit or an application request.).

If I run the exact same code using a real physical comm port (driver is serial.sys), it just waits nice and quiet waiting for a byte (as expected).

There is no port.Close() being run, there is no GC taking down the port etc.
I have included resetting dcb AbortOnError just prior to opening the port.

Any clue why this happens ?
B.t.w. it seems to not happen if I register for the DataReceived event instead, but I prefer a simple readloop with blocking ReadByte() calls in own thread.

ATL/CLI dll loading issue

$
0
0

I have a COM/ATL DLL (Built in VS2012) that is built with /cli, and references a .NET assemly to do much of its internal work. The problem I am having is registering the DLL - it won't register unless the .NET assembly is either in the GAC or in the same directory as Regsvr32.exe (Windows\System). I would assume that the assembly will always need to be in the same directory as the calling process.

It would be preferable for it to load from the same same directory as the COM dll. Can I make that happen, and if so, how?

Creating both projects in VS2012.

Cheers,

Mick

COM+ activation failed because the activation could not be completed in the specified amount of time

$
0
0

Hi,

we are facing issue com+ time out more frequent with dot net framework 4.

Earlier our application using dot net framework 2.0 . No com+ time out issue being reported.

ya we did some code changes also but not around com plus component.

Any idea what are potential reason for that ?

I know there is way to increase time out for work around. But I want to get root cause of it.

Is there any way to get root cause of it ?


Exception information:

    Exception type: COMException

    Exception message: COM+ activation failed because the activation could not be completed in the specified amount of time. (Exception from HRESULT: 0x8004E024)



Process is not closed after Main function has terminated

$
0
0
Hello all,
 
In what cases can a .NET application stay in the process
list after its Main function has terminated? How to track
down what is causing this?
 
I am writing an addon for SAP Business One, and it is the
Business One client that invokes my program. Can a program
invoke another in such a way as to prevent the latter's
process from terminating?
 
--
Anton Shepelev (via NNTP Bridge)
 

C# callback crashes in c++

$
0
0

Hi,

 In c++ I am calling C# com dll function which in turns calls call backs. The c# com dll is retrieving Lync client presence.

If there is any change in lync client presence, the c# callbacks will be triggered automatically. This crashing the application since both c++ and c# code are trying to execute at the same time.

As of now I am not using marshalling and delegate concept in my application. Whether I need use marshalling and delegate concept  and how to use it in this case.

Please help me this problem.

COM Interop with VBScript on 64 Bit Windows 7/ Server 2008

$
0
0

We are running into an issue with accessing a .NET DLL, compiled AnyCPU, from VBScript via COM Interop.  We are using the standard %windir%\Microsoft.Net\framework\v4.0.30319\regasm command to create a tlb file off the dll, which is also in the GAC.  We have been unable to get the VBS to successfully call the script, and have tried the following:

  • running via command prompt.
  • running via cscript.exe
  • running via 32bit command prompt (syswow64)
  • running via 32bit cscript.exe (syswow64)

At this point, we are trying to trace out what the sequence of compile bitness, regasm version, cscript version, etc will be required to get COM interop working in 64Bit Win7 or Server 2008.

[interop] native DLL only accessible from my C# project.

$
0
0

Hello

In order to better protect the source code of some functions, I moved them from my C# project to a native C++ dll. The concerned functions are now declared as "extern "C" __declspec(dllexport)" and can thus be used by any external program.

Now, I would like to restrict the usage of these functions so that only my C# program can call them (or at least make these functions throw an exception if they are not called by my authenticated program). How can such verification be made in a very safe way? Is it possible to check inside the C++ functions the strong name of the calling assembly?

Thank you in advances for any advices regarding this matter.

max

Change path from c:\windows\temp

$
0
0

Is it possible to change the path that ASP.Net uses when compiling code from %SystemRoot%\Temp to another folder.

I'm fairly sure the answer is going to be either no, or yes, but it's not supported, but I'll give my reasons.

Our systems are managed by a third party and recently, somehow the C:\Windows\Temp folder got deleted and recreated with the wrong permissions, this caused failures for .NET (It actually moaned about not having access to %SystemRoot%\Microsoft.NET\Framework\versionNumber\Temporary ASP.NET Files, but this was fine and it was actually c:\windows\temp that was the issue)

The 3rd party has requested we look into not using this folder and instead use anothe folder, but I'm fairly sure it's not possible.

Viewing all 1710 articles
Browse latest View live


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