0

I created standard .exe file:

Private Sub Command1_Click()
Dim proxy As Person
Set proxy = New Person 'here get error 70'
proxy.FirstName = "Bejaoui"
proxy.LastName = "Bechir"
proxy.Persist ("D:\myFile.xml")
End Sub

(Person it is class in COM file(.tlb)).

Person.cs in COM file:

using System.Xml.Serialization;
using System.IO;
using System.Runtime.InteropServices;

namespace COM
{
    [ClassInterface(ClassInterfaceType.None)]
    public class Person : System.EnterpriseServices.ServicedComponent, IPerson
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public bool IsMale { get; set; }
        public void Persist(string FilePath)
        {
            StreamWriter oFile = new StreamWriter(FilePath);
            XmlSerializer oXmlSerializer = new XmlSerializer(typeof(Person));
            oXmlSerializer.Serialize(oFile, this);
            oFile.Flush();
            oFile.Close();
        }
        static public Person Retrieve(string FilePath)
        {
            StreamReader oFile = new StreamReader(FilePath);
            XmlSerializer oXmlSerilizer = new XmlSerializer(typeof(Person));
            Person oPerson = oXmlSerilizer.Deserialize(oFile) as Person;
            return oPerson;

        }
    }
}

When I touch the button, I get error 70 and it mark string "Set proxy = New Person".

Run .exe in Windows 7

What I did and it didn't help:

  • Disable UAC
  • Created file myFile.xml
  • Changed acces to file "D:\myFile.xml"
  • Changed acces to COM file
  • Run .exe as a administrator

Object Browser: Object Browser

Donax
  • 13
  • 3
  • 1
    `Set proxy = New Person` is VB6, not VB.NET. Which are you actually using? – HardCode Oct 15 '21 at 18:29
  • @HardCode Edited, thanks – Donax Oct 16 '21 at 04:20
  • What environment are you running this in? In Windows Vista or 7, you may need to disable UAC. Are any of the files in read-only mode? Have you tried running the .exe as an administrator? – eglease Oct 16 '21 at 16:20
  • @Eglease I running this in Windows 7, disable UAC, all files with open acces. I was runing .exe as a administrator - got error. – Donax Oct 17 '21 at 06:13
  • What is happening inside of the class Initialize event? – Brian M Stafford Oct 17 '21 at 13:02
  • @Brian M Stafford Added code – Donax Oct 17 '21 at 14:49
  • Running _As Admin_ (or with UAC off) isn't necessary for a VB6 **executable** _unless_ you're touching "off-limit" territory. Then it needs the same persmissions like any other applicication would do. [Have you registered the tlb on the target machine with the 32-bit version of RegASM?](https://stackoverflow.com/questions/24451812/how-to-do-regasm-so-that-it-cover-32-bit-and-64-bit). – Hel O'Ween Oct 18 '21 at 07:59
  • @Hel O'Ween Yes, I registered, but it still don`t work – Donax Oct 18 '21 at 09:06
  • Just to be sure, D: isn't %SystemDrive%, right? And your C# assembly doesn't try to create/write/modify stuff in protected folders? Just to be sure. I'd try to persist the XML somewhere else than the root of D:\ and see if that makes a difference. – Hel O'Ween Oct 18 '21 at 10:51
  • @HelO'Ween D: isn`t %SystemDrive%. C# assembly doesn`t try to touch something in protected folders. I tried to move XML in folders and in D:\ and C:\(SystemDrive) - don`t helped. – Donax Oct 18 '21 at 11:33
  • And a C# test app like the above VB6 sample using the assemebly works fine? – Hel O'Ween Oct 18 '21 at 13:09
  • Oh, it just dawned to me that the object might be named differently. Hit F2 (like in VS.NET) to launch the Object Explorer and look up your Person object. You might need to define the variable differently, e.g. `Dim proxy As (YourAssmeblyCOMName).Person`. If your component is named `Person` and the class is also name `Person` you need to declare the variable `Dim proxy As Person.Person`. This can become consfusing due to how VB6 resolves the names of COM components and objects. – Hel O'Ween Oct 18 '21 at 13:13
  • @HelO'Ween Test app in C# doesn't work at all :D(Error MSB3290. I tried to solve this error and ask question on Stackoverflow, but I can't solve problem). To 2 comment: I tried this advice: COM file name - COM.tlb. I wrote `Dim proxy As COM.Person` and `Set proxy = New COM.Person`, but there is still an error. Did I understand your advice correctly? – Donax Oct 18 '21 at 19:44
  • If you already posted the question here, you should have linked it so that we didn't give the same advice twice. As for your question re. declaration: I can't answer that. Edit your question and post a screenshot of VB6's [Object Browser](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/object-browser) with your component selected from the dropdown, select your Person class and make sure the bottom pane is visible. – Hel O'Ween Oct 19 '21 at 07:15
  • @HelO'Ween Added screenshot. I didn't add link because there is another problem, but if it can help solve the problem: https://stackoverflow.com/questions/69506052/warning-msb3290 – Donax Oct 19 '21 at 13:37
  • So yeah, `Dim proxy As COM.Person` seems to be right. But given the info in the other SO question, you're trying to create a ServicedComponent, right? That's way outa my ballpark. :-) And the problem isn't with VB, it seems, but with your component. See if [this](https://flylib.com/books/en/2.575.1.91/1/) or [this](https://www.codeproject.com/Articles/43428/My-First-COM-Serviced-Component) might lead you to something. – Hel O'Ween Oct 19 '21 at 14:00

0 Answers0