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

Solved: InstallUtil throws ArgumentOutOfRangeException when trying to install windows service.

$
0
0
This is just to help people troubleshoot the ArgumentOutOfRangeException problem when trying to install a windows service with installutil. It took me a good while to understand the reason of the install failure and I could not find anything about this on the web concerning this problem, so hopefully this will help others in the future so they don't waste as much time as I did.

If you get:

An exception occurred during the Install phase.
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length

Then:

1) Go to the deisgner of your ProjectInstaller
2) Select the ServiceProcessInstaller
3) Go to the properties of the ServiceProcessInstaller.
4) If you see Account property set to user, change it to LocalSystem.
5) Rebuild your project.
6) Rerun installutil YourService.exe

Then the exception should be gone and the installation successful.

HTH

Sylvain Boissé Software Architect Noesis Innovation www.noesisinnovation.net

Windows server 2012R2 - Cluster-aware application fails to detect an active cluster on target machines

$
0
0

Hi There,

We are maintaining an application based on 3 layers (DB, WS, Application services).
The application is cluster-aware, meaning once cluster is configured on the target machine the install shield is running,
Further optionallities is being unlocked and visible for editing and to define how resource groups will react as part of the application's operations.

This issue is, that when trying to run the install shield on WinServer 2012R2, it fails to detect the active cluster.We had no issue when we were using WinServer 2008R2 and older versions (Not sure if we will encounter any similar issues on WinServer 2012).

Upon debugging the install shield, it seems that it initiates a call to a pre-defined windows internal class, that aventually uses a windows dll named 'msclusterlib.dll'.
This dll cannot be located as part of the machines registry keys or assemblies.

1. Since i could not find any information over the net about it, I was wondering if in WinServer 2012R2 the validation and retrievement of cluster information should be done differently? 

2. Does someone ran into similar issue while working on WinServer 2012R2/2012?

Your help will be much appreciated.


 

Whether can SignTool appends a differnt company signature to a exe?

$
0
0

I have a application need to call a 3rd part SDK,  but we have sign my application with 3rd part certificate.  if I use signtool sign my application with their certificate, our certificate will miss from signature list. I saw there is /as option, but when I use it, it always throw "A required function is not present ". my os is window 7 ultimate.

 Is it possible to sign same exe with two certificates from two companies ? and how to do it?

Thanks in advance.

Nate

How to detect UseRandomizedStringHashAlgorithm?

$
0
0

.NET Framework 4.5 and later can be configured to use a randomized string hashing algorithm. How can a managed-code library check whether the framework is using such an algorithm?

A library of ours has a legacy feature that unfortunately depends on String.GetHashCode returning the same hash codes even on different machines. The legacy feature is now disabled by default. If an application attempts to enable the legacy feature in an application domain where String.GetHashCode uses a randomized algorithm, I'd like the library to throw an exception saying that the legacy feature is not supported in that configuration.

I can think of these solutions:
  • Call "test".GetHashCode() and check that the result is 0xEAE38E77 in a 32-bit process or 0xCC127386 in a 64-bit process. There is a small risk that the result matches even if randomized hashing is enabled, but it is extremely likely that a mismatch would be found during testing of the application.
  • Check for the UseRandomizedStringHashAlgorithm element in the application configuration file. This seems a bad solution because there are at least four other ways to enable randomized string hashing: environment variable, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, and AppDomainSetup.SetCompatibilitySwitches.
  • Call the private method String.UseRandomizedHashing() by reflection. Nobody guarantees it will still be there in future versions of the .NET Framework.

I'm leaning towards the first solution. Do you have better ideas?

I moved a webservice from 2003R2 to 2008R2 and now I am getting an error.

$
0
0

I am moving off of a 2003R2 server.

I have a webservice that runs fine on the 2003R2 server, but when I install and use it on the 2008R2 server I get an error.

The webservice seems to not run at all.  My debug and log code seems to not run at all.  

When I go to the event viewer and check in application I see these entries.

First it does this:

Log Name:      Application
Source:        .NET Runtime
Date:          10/28/2015 6:03:38 PM
Event ID:      1023
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      TK0121WB05X
Description:
.NET Runtime version 2.0.50727.5485 - Fatal Execution Engine Error (6CE8FB1E) (80131506)
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1023</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2015-10-28T22:03:38.000000000Z" />
    <EventRecordID>18973</EventRecordID>
    <Channel>Application</Channel>
    <Computer>TK0121WB05X</Computer>
    <Security />
  </System>
  <EventData>
    <Data>.NET Runtime version 2.0.50727.5485 - Fatal Execution Engine Error (6CE8FB1E) (80131506)</Data>
  </EventData>
</Event>

Then it does this:

Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7a5f8
Faulting module name: mscorwks.dll, version: 2.0.50727.5485, time stamp: 0x53a121fa
Exception code: 0xc0000005
Fault offset: 0x0002b2ea
Faulting process id: 0x%9
Faulting application start time: 0x%10
Faulting application path: %11
Faulting module path: %12
Report Id: %13

--

I can find no reference on how to fix this.

What can I do?

Jerry

FontFamily Memory Leak on Windows 10

$
0
0

Hi,

On Windows 10, the System.Drawing.FontFamily.IsStyleAvailable method seems to leave the allocated space into memory even after the Dispose method has been called.

I wrote a simple console application to test it:

using System;
using System.Drawing;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        static string getMemoryStatusString()
        {
            using (Process p = Process.GetCurrentProcess())
            {
                return "(p: " + p.PrivateMemorySize64 + ", v:" + p.VirtualMemorySize64 + ")";
            }
        }

        static void Main(string[] args)
        {
            string s = getMemoryStatusString();
            foreach(FontFamily fontFamily in FontFamily.Families)
            {
                Console.Write(fontFamily.Name + " " + getMemoryStatusString() + " -> ");

                fontFamily.IsStyleAvailable(FontStyle.Regular);
                fontFamily.Dispose();

                Console.WriteLine(getMemoryStatusString());
            }
            string e = getMemoryStatusString();
            Console.WriteLine(s + " -> " + e);
            Console.ReadLine();
        }
    }
}

Any idea on why this is happening?

Thanks in advance!

.Net DLL version insight Required

$
0
0

Hi,

I have one query regarding .net assemblies. If we have Aseembly1 and Assembly2, where Assembly1 has a dependency on Assembly2 and both are build/deployed with version 2.0.0.0. Now if I do a patch in Assembly2 and deploy it with a version 2.0.0.1 version, will the Assembly1 will be able to load Assembly2?

I have tried doing this POC and no matter what version I give to Assembly2, Assembly1 is able to load it, I was expecting Assembly2 load to fail due to version conflict because Assembly1 is expecting Assembly2 to have version 2.0.0.0 but it has a diff assembly version. DLL's are not signed.

Please explain what am I missing here?

Thanks!


deepak

WinRT (C++) with C# solution , Runtime issue.

$
0
0

Hi,

    I am being practicing Windows app development with VS 2015. I did a C# program which calls WinRT created by C++. 

    I have created two solution C++ RT and C#.

           1] WinRT (C++) .winwd solution (with simple class and a method)

           2] C# (Instance of C++ object created and call the method) (reference added through Solution explorer)

        I am able to build without any issue, but run time i am getting error as the class what i defined and trying to use from C++ RT not able to find.

          "An unhandled exception of type 'System.TypeLoadException' occurred in mscorlib.dll
           Additional information: Could not find Windows Runtime type 'RT_Com.RTClass'.

      Where it is going wrong. Any help.

Thanks,

 

          

  



Releasing COM Objects

$
0
0

Hi,

 

I just started with vb.net and I am not really familiar with releasing COM object yet.

I am using Visual Studio 2015 and my program is for Office 2007 and above.

So I am trying to do it perfect but I am not sure if this is the correct way to release COM objects.

Example:

 [...]

If ActiveWindow IsNot Nothing Then

    Marshal.ReleaseComObject(ActiveWindow.SELECTION.ShapeRange)

    Marshal.ReleaseComObject(ActiveWindow.SELECTION)

    Marshal.ReleaseComObject(ActiveWindow)

    ActiveWindow = Nothing

End If

 [...]

  1. Is it necessary to release each level separately?

Seen here: http://www.codeproject.com/Tips/235230/Proper-Way-of-Releasing-COM-Objects-in-NET

  1. Is it “dangerous” to use more than two dots at a time when working with COM objects (ActiveWindow.SELECTION.ShapeRange) - Or should I assign each level to a seperate variable?

Seen here: http://www.siddharthrout.com/2012/08/06/vb-net-two-dot-rule-when-working-with-office-applications-2/

  1. Is there a way to check at the end of each function – at least in debugging mode – if there is any COM object left behind and not released yet?

Many thanks.

Simple question newbie to .net

$
0
0

I am creating an application in vb.net for a manufacturing test.  At the end of the test, I am using a windows form to display either PASS on a green background or FAIL on a red background.  Everything is working, but when I call the second form to show the label always appears as no text with a white background.   Feel stupid that I can't figure out what is going on.  The problem I have is that I had done a lot of programming in VB6, but have gotten away from development altogether until recently.

If blnPassFail = True

      me.lblpassfail.text = "PASS"

     me.lblpassfail.backcolor=color.green

     me.backcolor=color.green

Else

     me.lblpassfail.text = "FAIL"

     me.lblpassfail.backcolor = color.red

     me.backcolor = color.red

Endif

The label always just shows as a white box on the form.  The forecolor is black, the text is arial 72.  Can't figure it out.

To Share or Not To Share .NET DLLs

$
0
0
The Build Manager (Me) and an Architect Lead are going back and forth on how to implement his common DLLs.  Our current setup is 20+ individual .NET websites of which some are compiled and some are not (just the raw code out deployed).  This is just for one environment (QA) and one of our clients. So when he updates his DLLs he wants them deployed to each individual bin folder location, where I want the .NET web sites to reference one shared location and where the DLLs are deployed to instead of potentially hundreds of bin locations every time the DLL changes.  GAC is also out of the question.  What do you all think is the best way to go? Any other details about our setup let me know.

PerfView complains merged data not merged

$
0
0

Hello,

I'm running PerfView 1.8 from the command line. The log file specified with  -LogFile shows:

[DONE 14:04:22 SUCCESS: PerfView start -AcceptEULA -BufferSizeMB:64 -CircularMB:512 -DataFile:Data_3984_5_11_2015_14_4_21 -LogFile=Log_3984_5_11_2015_14_4_21 -KernelEvents:Process+Thread+ImageLoad+VirtualAlloc+VAMap -OSHeapProcess:3984 -zip]

The -zip option instructs PerfView to merge the data.

Later the log file shows that merging completed successfully:

Merging took 152.7 sec
Moving C:\PerfviewMon\mem-mon\Data_3984_5_11_2015_14_4_21.etl.new to C:\PerfviewMon\mem-mon\Data_3984_5_11_2015_14_4_21.etl
Deleting temp file
Merge took 152.880 sec.
Merge output file C:\PerfviewMon\mem-mon\Data_3984_5_11_2015_14_4_21.etl
[Zipping ETL file C:\PerfviewMon\mem-mon\Data_3984_5_11_2015_14_4_21.etl]
[Writing 7 PDBS to Zip file]
ZIP generation took 44.844 sec
ZIP output file C:\PerfviewMon\mem-mon\Data_3984_5_11_2015_14_4_21.etl.zip
Stop Completed at 11/5/2015 2:09:05 PM
[DONE 14:09:05 SUCCESS: PerfView stop -DataFile:Data_3984_5_11_2015_14_4_21 -LogFile=Log_3984_5_11_2015_14_4_21]

I then copy the .zip file for analysis on a different machine. In PerfView  I select "Net Virtual Alloc Stacks" and then select my process and then PerfView displays this message box:

---------------------------
Data not merged before leaving the machine!
---------------------------
Warning!   This file was not merged and was moved from the collection

machine.  This means the data is incomplete and symbolic name resolution

will NOT work.  The recommended fix is use the perfview (not windows OS)

zip command.  Right click on the file in the main view and select ZIP.


See merging and zipping in the users guide for more information.
---------------------------
OK   
---------------------------

But as you can see from the above info from the log file the merging succeeded.

Any ideas?

thanks,

Marc Sherman


Does ASP.net need access to the temp folder ?

$
0
0
The government entity decided to deny processes from running from the temp folder. Now when i run my ASP.net website in either debug mode or without debugging I get some strange access denied errors. Does ASP.net running on local workstation need access to the temp folder ?

Passing array of struct to unmanaged code

$
0
0

Hi,

 

I am relatively new to C# and I am having a hard time implementing one function and was hoping that I could get some help from here.

 

I am trying to call a function from c/c++ library which takes in an array of struct for one of its inputs. I have read few other topics of similar nature, however I was not able to implement this and was hoping that someone could point out what I am doing wrong. It's a function to control FT232RL usb to serial converter.

 

FT_STATUS FT_GetDeviceInfo (FT_DEVICE_LIST_INFO_NODE *pDest, LPDWORD lpdwNumDevs)

 

where

 

FT_DEVICE_LIST_INFO_NODE (see FT_GetDeviceInfoList )
typedef struct _ft_device_list_info_node {
DWORD Flags;
DWORD Type;
DWORD ID;
DWORD LocId;
char SerialNumber[16];
char Description[64];
FT_HANDLE ftHandle;
} FT_DEVICE_LIST_INFO_NODE;

 

where DWORD and FT_Handle are simply Uint32 and LPDWORD is a pointer to unsigned long (4bytes)

 

And this is what I have done in c#

 

[StructLayout(LayoutKind.Sequential)]
        public unsafe struct FT_DEVICE_LIST_INFO_NODE
        {
         
            public UInt32 ftFlag;           
            public UInt32 ftType;         
            public UInt32 ID;         
            public UInt32 Locld;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
            public char[] SerialNumber;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
            public char[] Description;           
            public FT_HANDLE ftHandle;
        }

 

Imported the function by,

 

[DllImport("FTD2XX.dll")] 
        static extern unsafe FT_STATUS FT_GetDeviceInfoList([MarshalAs(UnmanagedType.LPArray)] ref FT_DEVICE_LIST_INFO_NODE[] pdest, ref UInt32 IpdwNumDevs);

 

and am calling the function using,

 

FT_DEVICE_LIST_INFO_NODE[] ftNodes = new FT_DEVICE_LIST_INFO_NODE[ftnumdevs];                    
ftStatus = FT_GetDeviceInfoList(ref ftNodes, ref ftnumdevs);

 

Where ftnumdevs is the number of devices that are connected, obtained from another function which I have checked and verified it as working. THere are 20+ additional functions in this FTD2XX.dll which I have implemented successfully except for two functions which are the one listed above and another function which allows you to program the EEPROM of the chip and one thing common between the functions are that they take an array of struct as an input.

 

The error I get when I call this function is

 

"The runtime has encountered a fatal error. The address of the error was at 0x79e95b95, on thread 0x1454. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack."

 

Can anyone tell me what I doing wrong?

I also tried implementing it using the IntPtr + Marshalling, however to no avail....

Any kind of help or direction will be appreciated,

 

Thanks in advance,

 

 

 

 

 

 

Which reflection operations will tolerate a missing DLL?

$
0
0

Suppose we have A.dll:

namespace A
{
    public class A1
    {
    }
}

and B.dll:

namespace B
{
    using System.Collections.Generic;
    using A;

    public class B1
    {
        public A1 Prop { get; set; }

        public IList<A1> Fun(A1 val)
        {
            return new A1[1] { val };
        }

        public static class Inner
        {
            public static readonly int X = 69;

            public static int Y { get { return 42; } }
        }
    }
}

and C.exe:

namespace C
{
    using System;
    using System.Reflection;
    using System.Diagnostics;

    internal static class Program
    {
        private static void Main()
        {
            Assembly b = Assembly.Load("B");
            Type[] types = b.GetExportedTypes();
            Type b1 = b.GetType("B.B1");
            Type inner = b.GetType("B.B1+Inner");
            Debug.Assert(b1 == inner.DeclaringType);
            FieldInfo[] fields = inner.GetFields(BindingFlags.Static | BindingFlags.Public);
            Debug.Assert(fields.Length == 1);
            fields[0].GetValue(null);
            PropertyInfo[] properties = inner.GetProperties(BindingFlags.Static | BindingFlags.Public);
            Debug.Assert(properties.Length == 1);
            properties[0].GetValue(null, null);
        }
    }
}

Then, we install B.dll and C.exe, but we do not install A.dll. Does the .NET Framework CLR promise that the operations in C.Program.Main will succeed even though A.dll is not found at run time? With .NET Framework 4.5.2 on Windows 7 SP1, these operations do succeed, but I have not found any documentation that promises they will work in future versions of the CLR as well.

If I change A.A1 to a value type, then b.GetExportedTypes() throws, presumably because the CLR cannot compute the memory layout of B.B1—even though the program did not attempt to create an instance of B.B1. If documentation exists on this topic, I hope it goes to this kind of detail.


error message: Failure adding assembly to the cache

$
0
0

I am able to install non-obfuscated delay-signed assemblies to the GAC.   When I attempt to install obfuscated delay-signed assemblies to the GAC then I get the error message:

   "Failure adding assembly to the cache: Strong name signature could not be verified.  Was the assembly built delay-signed?"

1) I have just started working with shared assemblies for the first time. I would like confirmation that it is to be expected that delay-signed assemblies with signing verification disabled (i.e.: sn.exe -Vr "myAssemblyName.dll") can be installed in the GAC. In other words, the fact that I am able to do this on my computer is normal and not somehow an anomaly.

2) When writing/developing delay-signed assemblies, is the 'best practice' to install/test/debug the assembly in the GAC or to test/debug the assembly in the project's local output directory? 

3) As mentioned, I can successfully install a delay-signed assembly in the GAC when it is non-obfuscated.   But when I obfuscate the delay-signed assembly and attempt to install it in the GAC then I get the error message reported above.  Is there anything special I need to do in this case to install the obfuscated, delay-signed assembly in the GAC?  Some additional information:

a) I am working with  Visual Studio 2013, ultimate
b) the delay-signed C# assembly is obfuscated in the project's post-build event
c) the obfuscator I am using is ConfuserEX (https://yck1509.github.io/ConfuserEx/)
d) in the project's post-build event, immediately after obfuscating the project's assembly, I attempt to install the assembly in the GAC using the 32 bit version of gacutil.exe.
e) I am developing under Win7 64 bits   

ThanX for all suggestions and comments



How to Prevent the .NET Compiler from Treating Object Return Value as Dynamic

$
0
0

We are in the process of migrating our COM/.NET Interop application from compiling against .NET 2.0 CLR to .NET 4.0 CLR. We are seeing a problem where we have to change our code because of the automatic interpretation of an ‘object’ return value as ‘dynamic’ by the compiler only under .NET 4.0. 

Our code has been executing in the .NET 4.0 runtime using the following content in our exe.config even though it compiled against .NET 2.0/3.5, so we are sure it can run properly in .NET 4.0:

  <startup useLegacyV2RuntimeActivationPolicy="true">

     <supportedRuntime version="v4.0.30319"/>

  </startup>

The issue appears to be methods that return variant/object type.  We have a COM TLB and Primary Interop  Assembly that define an interface with method that returns an object. Here’s the COM definition and the IL for that interface method in the PIA:

IDL Definition:

  [id(10), helpstring("Gets active components matching name passed in.")]

               HRESULT GetCompByName([in] BSTR CompName, [out, retval] VARIANT *Components);

PIA IL:

  .method public hidebysig newslot abstract virtual

          instance object

          marshal( struct)

          GetCompByName([in] string marshal( bstr) CompName) runtime managed internalcall

  {

    .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute::.ctor(int32) = ( 01 00 0A 00 00 00 00 00 )

  } // end of method ISession::GetCompByName

The VARIANT (object) always contains an array of IDispatch objects (VT_ARRAY | VT_DISPATCH).  

When our projects target .NET 2.0/3.5, the following code compiles and runs:

      System.Array v =null;

       //Try to get privileges from Session

        v = (System.Array)(session.GetCompByName("Some Prog ID"));      

        privileges = (JFW.IPrivileges)(v.GetValue(v.GetLowerBound(0)));

Now that we migrated the project to .NET 4.X, we get a runtime error for the same code. Some quick googling has shown that we can’t cast the object return type to an Array until we first get it into an Object. Using the object browser, we see that the return type of GetCompByName is no longer ‘Object’, but is instead ‘Dynamic’. Here’s what we had to change our client code to do:

      System.Array v =null;

      //Try to get privileges from Session

        v = (System.Array)(object)(session.GetCompByName("SomeProg ID"));       ç Exception at runtime without extra object cast

        privileges = (JFW.IPrivileges)(v.GetValue(v.GetLowerBound(0)));

My ultimate question is, how can we get the project and compiler to not interpret the PIA’s return value as ‘Dynamic’ and instead leave it alone as ‘Object’? We don’t want to change our code as we have this call in thousands of places and our application clients would all have to change as well.

See the document I have that includes screen captures of the same method VS with .NET 2 vs 4

https://onedrive.live.com/embed?cid=AE1D3AA8CFE3192F&resid=AE1D3AA8CFE3192F%21116

Thanks,


Brian R.


Static class vs singleton class

$
0
0

hi,

the main objective of both static class and a singleton class is that having a shared entity. but what is the basic difference between them?> which to use where?

thanks in advance

Swapnil

How I can hook OnAmbientPropertyChange for UserMode property in ActiveX writen on C#

$
0
0

I have ActiveX writeon on C#

[ComVisible(true)]
[Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IChart
{
        void Activate();
        void Deactivate();
        void StartRunTime();
        void StopRunTime();
}

[ComVisible(true)]
[Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IChartEvents
{
        [DispId(1)]
        void OnActivate();
        [DispId(2)]
        void OnDeactivate();
}
[ComVisible(true)]
[ProgId("NS.ChartControl")]
[Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IChart))]
[ComSourceInterfaces(typeof(IChartEvents))]
public partial class ChartControl : UserControl, IChart
{
        public event Action OnActivate;
        public event Action OnDeactivate;


        public void StopRunTime() {.....}
        public void StartRunTime() {.....}
        public void Activate() {.....}
        public void Deactivate() {.....}

        [ComRegisterFunction]
        public static void RegisterClass(string key)
        {
            var trimedkey = TrimRegKey(key);
            RegistryKey k = null;
            try
            {
                k = Registry.ClassesRoot.OpenSubKey(trimedkey, true);
                if (k == null)
                    return;

                RegistryKey ctrl = k.CreateSubKey("Control");
                ctrl.Close();

                RegistryKey insertb = k.CreateSubKey("Insertable");
                insertb.Close();

                RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
                inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
                inprocServer32.Close();
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                k?.Close();
            }
        }

        [ComUnregisterFunction]
        public static void UnregisterClass(string key)
        {
            var trimedkey = TrimRegKey(key);

            RegistryKey k = null;
            try
            {
                k = Registry.ClassesRoot.OpenSubKey(trimedkey, true);

                if (k == null)
                    return;

                k.DeleteSubKey("Control", false);
                k.DeleteSubKey("Insertable", false);
                RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);

                k.DeleteSubKey("CodeBase", false);
                inprocServer32.Close();
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                k?.Close();
            }
        }

        [ComVisible(false)]
        private static string TrimRegKey(string key)
        {
            return key.Replace(@"HKEY_CLASSES_ROOT\", "");
        }
}

And also i have ActiveX container where I inserted my control. It can change UserMode property of ActiveX Contorl's.

It work perfect). But IOleControl is nested private interface in Control class so I can't override OnAmbientPropertyChange foo from IOleControl.

How i can advise (subscribe) for changing UserMode property of ActiveX Contorl?

ASP.NET Web Api fails DllImport (LoadLibrary) on IIS

$
0
0

Hi, 
I'm developping a Web API that needs to call an unmanaged DLL written in C++.

Like here: http://blogs.msdn.com/b/eldar/archive/2006/09/22/how-to-call-c-dll-from-asp-net-c-code.aspx

In debugging (IIS Express), I'm able to call the function within the DLL and LoadLibrary is loaded correctly with a Handle.
Problem comes when I deploy my Web Api to my local machine (IIS 8): It recognizes the path of the DLL, permissions are also set properly, but LoadLibrary fails bacause I get a IntPtr.Zero.

I used Marshal.GetLastWin32Error() to detect the error, but I get error Code 193, which seems to have nothing to do with LoadLibrary.


Here's my code:

if (!Directory.Exists(PATH) && !File.Exists(PATH_DLL))
throw new Exception(string.Format("Dll not found: {0}.", PATH_DLL));

//LoadLibrary
hModule = DllInterop.LoadLibrary(PATH_DLL);
IsLoaded = (hModule != IntPtr.Zero);
if (!IsLoaded)
{
int errno = Marshal.GetLastWin32Error();
throw new Exception(string.Format("Failed to load library. Fehler:{0}.", errno));
}


I would be very grateful for your help. Thanks in advance!

Viewing all 1710 articles
Browse latest View live


Latest Images

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