Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

chandrap

@chandrap
About
Posts
18
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    Thank you for your replies. I found the solution to my problem. The problem is because the Managed C++ DLL that has been used in C# DLL refers to native C++ DLLs that have already been loaded in the main application i.e. default application domain. So when the managed C++ DLL is getting loaded via C# DLL, the framework instead of loading the native C++ DLL in the new applicaiton domain, uses the DLLs from the default application domain. This is causing the managed C++ DLL also to be loaded into the default application domain. Because of this reason I was not able to delete the managed C++ DLL.

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    I am not able to delete the Managed C++ DLL referenced inside the C# DLL. I checked the loaded assembly list using GetAssemblies. Then I found out the the Managed C++ DLL used in C# DLL is also loaded in the default application domain even though I do not use it anywhere except the C# DLL.

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    We use Managed C++ DLL to load the wrapper DLL which is C# DLL. This managed C++ DLL supplies the DLL name, class name to the wrapper DLL. The wrapper DLL loads the C# DLL. Creates the C# Class. The C# DLL uses another managed C++ DLL internally.

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    Thank you for your reply. I create Assembly Manager class inside the new application domain appDomain->CreateInstanceAndUnwrap("Wrapper.dll", "AssemblyMgr") Then ask the wrapper DLL to load. After this step we create the class in step 5 using the following code. Type testClassType = assembly.GetType(className); CSharpClass = (CSharpClass)Activator. CreateInstance(testClassType); Step3 is done to have the assembly loaded once, step 5 is used to create different classes from the same assembly. We do this because we do not know the DLL name at the compile time.

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    Hi After further investigation I found out that the default application domain is also loading the MC++ DLL even though I do not use it anywhere in the default application domain. The only place I use MC++ DLL is in the C#. The C# DLL gets unloaded when I unload the new application domain since it was loaded only in the new application domain. Why is the MC++ DLL getting loaded both in default and new application domain. Thanks Chandra

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    Yes you are correct, the Step3 is done in in the new application domain. Not in the default domain. Step5 uses the Step3 loaded assembly reference in the new appDOmain, to create the C# object. Since the C# DLL is only loaded in the new application domain, I was able to delete it.

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    I am having problem to delete a Managed C++ DLL that was used in a pure C# DLL even in the following scenario. 1. Launch the application. This applicatio has its own default applicaiton domain. 2. Create a new Application Domain. 3. Load the Pure C# DLL in the new applicaiton domain. This C# DLL uses managed C++ DLL. 4. Create a Proxy object using CreateInstanceAndUnwrap for the wrapper object which is a wrapper for the class used from the pure C# DLL. This wrapper object is exported from a seperate DLL. DLL Configuration:- Wrapper for C# DLL, C# DLL, Managed C++ DLL. The wrapper C# is used so that the main C# will not be loaded into the default application domain when creating a Proxy object using the menthod CreateInstanceAndUnwrap. The application domain talks with only the wrapper DLL. If we do not have wrapper class, then the main C# DLL will also be loaded into the default application. The sideeffect of this is that, even when the new application is unloaded, we will not be able to delete the main C# DLL. Wrapper is just a call frowader to the C# DLL class. 5. Give the class name exported from C# DLL to the wrapper object and ask it to create an instance of the class. The wrapper class creates the the class and initializes its membet to it, so that it can forward call requests. 6. From the default application domain, call a method on the wrapper object. This call on the wrapper object calls the method on the C# class. This C# class uses a function exported from a managed C++ DLL. 7. After executing the methods, unload the new application domain. 8. Now try to delete C# DLL, Mananged C++ DLL. I was able to delete C# DLL, but not MC++ DLL. After further investigation I found that the Visual Studio "Output" window has the following two lines:- 'Application.exe': Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded.----> LOADING FIRST TIME 'Application.exe' (Managed): Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded. ----> LOADING SECOND TIME When the method on C# class is getting executed, the output log file contains the above two lines. The .NET framework is loading it twice. Once as Native C++ DLL, second time as Managed DLL. Does any one know how to delete the MC++ DLL.

    C# csharp c++ dotnet visual-studio debugging

  • Problem of Unloading Managed C++ DLL...
    C chandrap

    I am having problem to delete a Managed C++ DLL that was used in a pure C# DLL even in the following scenario. 1. Launch the application. This applicatio has its own default applicaiton domain. 2. Create a new Application Domain. 3. Load the Pure C# DLL in the new applicaiton domain. This C# DLL uses managed C++ DLL. 4. Create a Proxy object using CreateInstanceAndUnwrap for the wrapper object which is a wrapper for the class used from the pure C# DLL. This wrapper object is exported from a seperate DLL. DLL Configuration:- Wrapper for C# DLL, C# DLL, Managed C++ DLL. The wrapper C# is used so that the main C# will not be loaded into the default application domain when creating a Proxy object using the menthod CreateInstanceAndUnwrap. The application domain talks with only the wrapper DLL. If we do not have wrapper class, then the main C# DLL will also be loaded into the default application. The sideeffect of this is that, even when the new application is unloaded, we will not be able to delete the main C# DLL. Wrapper is just a call frowader to the C# DLL class. 5. Give the class name exported from C# DLL to the wrapper object and ask it to create an instance of the class. The wrapper class creates the the class and initializes its membet to it, so that it can forward call requests. 6. From the default application domain, call a method on the wrapper object. This call on the wrapper object calls the method on the C# class. This C# class uses a function exported from a managed C++ DLL. 7. After executing the methods, unload the new application domain. 8. Now try to delete C# DLL, Mananged C++ DLL. I was able to delete C# DLL, but not MC++ DLL. After further investigation I found that the Visual Studio "Output" window has the following two lines:- 'Application.exe': Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded.----> LOADING FIRST TIME 'Application.exe' (Managed): Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded. ----> LOADING SECOND TIME When the method on C# class is getting executed, the output log file contains the above two lines. The .NET framework is loading it twice. Once as Native C++ DLL, second time as Managed DLL. Does any one know how to delete the MC++ DLL.

    .NET (Core and Framework) csharp c++ dotnet visual-studio debugging

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    Hello everyone, thanks for your help. I was able to find the solution for my requirement. Following is the code

    class ListElement
    {
        public ListElement()
        {
            m\_element = 0;
        }
    
        public ListElement(int element)
        {
            m\_element = 1;
        }
    
        public int m\_element;
    }
    
    class TestClass
    {
        public int i = 0;
    
        public int IValue
        {
            get
            {
                return i;
            }
            set
            {
                i = value;
            }
    
        }
        public List m\_intList = new List();
        public List m\_lstElement = new List();
    }
    class Program
    {
        static void Main(string\[\] args)
        {
            TestClass tcObject = new TestClass();
            tcObject.i = 1;
            tcObject.m\_intList.Add(1);
            tcObject.m\_intList.Add(2);
            tcObject.m\_lstElement.Add(new ListElement(1));
    
            // Following code modifies the field "I".
            {
                FieldInfo fieldInfo = tcObject.GetType().
                                        GetField(
                                        "i",
                                        BindingFlags.Static |
                                        BindingFlags.Instance |
                                        BindingFlags.NonPublic |
                                        BindingFlags.Public);
    
                fieldInfo.SetValue(tcObject, 2);
    
                System.Console.WriteLine("I value '{0}'", fieldInfo.GetValue(tcObject));
            }
    
            // Following code modifies the IValue property.
            {
                PropertyInfo propertyInfo = tcObject.GetType().
                                        GetProperty(
                                        "IValue",
                                        BindingFlags.Static |
                                    BindingFlags.Instance |
                                    BindingFlags.NonPublic |
                                    BindingFlags.Public);
    
                MethodInfo propertySetMethodInfo =
                                propertyInfo.GetSetMethod(true);
    
                propertySetMethodInfo.Invoke(tcObject, new Object\[\] { 3 });
    
                System.Console.WriteLine("Property IValue '{0}'", tcObject.i);
            }
    
            {
                FieldInfo fieldInfo = tcObject.Get
    
    C# help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    Hello everyone, thanks for your help. I was able to find the solution for my requirement. Following is the code

    class ListElement
    {
        public ListElement()
        {
            m\_element = 0;
        }
    
        public ListElement(int element)
        {
            m\_element = 1;
        }
    
        public int m\_element;
    }
    
    class TestClass
    {
        public int i = 0;
    
        public int IValue
        {
            get
            {
                return i;
            }
            set
            {
                i = value;
            }
    
        }
        public List m\_intList = new List();
        public List m\_lstElement = new List();
    }
    class Program
    {
        static void Main(string\[\] args)
        {
            TestClass tcObject = new TestClass();
            tcObject.i = 1;
            tcObject.m\_intList.Add(1);
            tcObject.m\_intList.Add(2);
            tcObject.m\_lstElement.Add(new ListElement(1));
    
            // Following code modifies the field "I".
            {
                FieldInfo fieldInfo = tcObject.GetType().
                                        GetField(
                                        "i",
                                        BindingFlags.Static |
                                        BindingFlags.Instance |
                                        BindingFlags.NonPublic |
                                        BindingFlags.Public);
    
                fieldInfo.SetValue(tcObject, 2);
    
                System.Console.WriteLine("I value '{0}'", fieldInfo.GetValue(tcObject));
            }
    
            // Following code modifies the IValue property.
            {
                PropertyInfo propertyInfo = tcObject.GetType().
                                        GetProperty(
                                        "IValue",
                                        BindingFlags.Static |
                                    BindingFlags.Instance |
                                    BindingFlags.NonPublic |
                                    BindingFlags.Public);
    
                MethodInfo propertySetMethodInfo =
                                propertyInfo.GetSetMethod(true);
    
                propertySetMethodInfo.Invoke(tcObject, new Object\[\] { 3 });
    
                System.Console.WriteLine("Property IValue '{0}'", tcObject.i);
            }
    
            {
                FieldInfo fieldInfo = tcObject.GetType
    
    .NET (Core and Framework) help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    Its a requirement in my application. Given an instance of class and values for the members, we should be able to update the members with the corresponding values.

    .NET (Core and Framework) help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    I even tried the following code

                MethodInfo addMethodInfo = fieldInfo.FieldType.GetMethod("Add"); 
                object\[\] intValue = { 5 }; 
                addMethodInfo.Invoke(tcObject, new Object\[\] { 5 }); 
    

    But the above code gives me error "Unhandled Exception: System.Reflection.TargetException: Object does not match target type." when executing the "invoke"

    C# help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    I even tried the following code

                MethodInfo addMethodInfo = fieldInfo.FieldType.GetMethod("Add"); 
                object\[\] intValue = { 5 }; 
                addMethodInfo.Invoke(tcObject, new Object\[\] { 5 }); 
    

    But the above code gives me error "Unhandled Exception: System.Reflection.TargetException: Object does not match target type." when executing the "invoke"

    .NET (Core and Framework) help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    At compile time I do not know whether the type is List or List. At runtime I should interpret it from the fieldInfo.FieldType.

    C# help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    At compile time I do not know whether the type is List or List. At runtime I should interpret it from the fieldInfo.FieldType.

    .NET (Core and Framework) help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    What do you mean by 'assembly type'. The assembly is .NET assembly written in C#.

    C# help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    Hi I am trying to modify class instance members using reflection. I am having problem when trying to add/remove/display elements related to List member. Following is the code. [CODE]

    class TestClass
    {
        public int i = 0;
    
        public int IValue
        {
            get
            {
                return i;
            }
            set
            {
                i = value;
            }
    
        }
        public List m\_intList = new List();
    }
    class Program
    {
        static void Main(string\[\] args)
        {
            TestClass tcObject = new TestClass();
            tcObject.i = 1;
            tcObject.m\_intList.Add(1);
            tcObject.m\_intList.Add(2);
    
            // Following code modifies the field "I".
            {
                FieldInfo fieldInfo = tcObject.GetType().
                                        GetField(
                                        "i",
                                        BindingFlags.Static |
                                        BindingFlags.Instance |
                                        BindingFlags.NonPublic |
                                        BindingFlags.Public);
    
                fieldInfo.SetValue(tcObject, 2);
    
                System.Console.WriteLine("I value '{0}'", fieldInfo.GetValue(tcObject));
            }
    
            // Following code modifies the IValue property.
            {
                PropertyInfo propertyInfo = tcObject.GetType().
                                        GetProperty(
                                        "IValue",
                                        BindingFlags.Static |
                                    BindingFlags.Instance |
                                    BindingFlags.NonPublic |
                                    BindingFlags.Public);
    
                MethodInfo propertySetMethodInfo =
                                propertyInfo.GetSetMethod(true);
    
                propertySetMethodInfo.Invoke(tcObject, new Object\[\] { 3 });
    
                System.Console.WriteLine("Property IValue '{0}'", tcObject.i);
            }
    
            // Following is the actual problem I am having. I would like to add
            // elements to the List member m\_intList.
            {
                FieldInfo fieldInfo = tcObject.GetType().
                                        GetField(
                                        "m\_intList",
                                        BindingFl
    
    .NET (Core and Framework) help

  • Using reflection modify List<int> type class member...</int> [modified]
    C chandrap

    Hi I am trying to modify class instance members using reflection. I am having problem when trying to add/remove/display elements related to List member. Following is the code. [CODE]

    class TestClass
    {
        public int i = 0;
    
        public int IValue
        {
            get
            {
                return i;
            }
            set
            {
                i = value;
            }
    
        }
        public List m\_intList = new List();
    }
    class Program
    {
        static void Main(string\[\] args)
        {
            TestClass tcObject = new TestClass();
            tcObject.i = 1;
            tcObject.m\_intList.Add(1);
            tcObject.m\_intList.Add(2);
    
            // Following code modifies the field "I".
            {
                FieldInfo fieldInfo = tcObject.GetType().
                                        GetField(
                                        "i",
                                        BindingFlags.Static |
                                        BindingFlags.Instance |
                                        BindingFlags.NonPublic |
                                        BindingFlags.Public);
    
                fieldInfo.SetValue(tcObject, 2);
    
                System.Console.WriteLine("I value '{0}'", fieldInfo.GetValue(tcObject));
            }
    
            // Following code modifies the IValue property.
            {
                PropertyInfo propertyInfo = tcObject.GetType().
                                        GetProperty(
                                        "IValue",
                                        BindingFlags.Static |
                                    BindingFlags.Instance |
                                    BindingFlags.NonPublic |
                                    BindingFlags.Public);
    
                MethodInfo propertySetMethodInfo =
                                propertyInfo.GetSetMethod(true);
    
                propertySetMethodInfo.Invoke(tcObject, new Object\[\] { 3 });
    
                System.Console.WriteLine("Property IValue '{0}'", tcObject.i);
            }
    
            // Following is the actual problem I am having. I would like to add
            // elements to the List member m\_intList.
            {
                FieldInfo fieldInfo = tcObject.GetType().
                                        GetField(
                                        "m\_intList",
                                        BindingFl
    
    C# help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups