Reputation: 399
I would like to use a vb.net module in my c# project. I compiled the vb.net module and I added reference to its dll in c# project, but I can't see it in c# project. The module is public, I tried to write its namespace (dll file name) before the module name, I tried to manually insert using moduleNameSpace
, I checked that both projects have the same destination framework (4.5 without client profile), but I still can't see it. I have no idea about what I should do further.
Can anyone help me? Thanks!
A portion of vb.net module:
Namespace GestioneSetupFile
Public Module GestioneSetupFiles
Private Const TAB_POS As Short = 30
Dim Testo, Paragrafo As String
Dim PtrParagrafo As Integer
Public DEFAULT_APP_DIR As String = My.Application.Info.DirectoryPath
'Public DEFAULT_APP_DIR As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\BTSR\PC-LINK NEMO"
Public DEFAULT_CONFIG_DIR As String = DEFAULT_APP_DIR + "\Config"
Public Sub CheckConfigDir()
'Verifica la presenza della cartella Config
'Se non esiste la crea e per compatibilità con le versioni precedenti ci copia dentro tutti i files .cfg e .dat che trova
If Not My.Computer.FileSystem.DirectoryExists(DEFAULT_CONFIG_DIR) Then
'Dim NomeFile As String
My.Computer.FileSystem.CreateDirectory(DEFAULT_CONFIG_DIR)
'NomeFile = Dir(DEFAULT_APP_DIR + "\*.cfg")
'While NomeFile <> ""
' 'My.Computer.FileSystem.MoveFile(DEFAULT_APP_DIR + "\" + NomeFile, DEFAULT_CONFIG_DIR + "\" + NomeFile)
' 'per compatibilità con vecchio (se reinstallato) non sposta ma copia i file
' My.Computer.FileSystem.CopyFile(DEFAULT_APP_DIR + "\" + NomeFile, DEFAULT_CONFIG_DIR + "\" + NomeFile)
' NomeFile = Dir()
'End While
'NomeFile = Dir(DEFAULT_APP_DIR + "\*.dat")
'While NomeFile <> ""
' 'My.Computer.FileSystem.MoveFile(DEFAULT_APP_DIR + "\" + NomeFile, DEFAULT_CONFIG_DIR + "\" + NomeFile)
' 'per compatibilità con vecchio (se reinstallato) non sposta ma copia i file
' My.Computer.FileSystem.CopyFile(DEFAULT_APP_DIR + "\" + NomeFile, DEFAULT_CONFIG_DIR + "\" + NomeFile)
' NomeFile = Dir()
'End While
End If
End Sub
End Module
End Namespace
And this is my call in c# project:
using System;
/*Others using*/
using Microsoft.VisualBasic;
using GestioneSetupFile; //Compile error
namespace UltraFeederControl
{
public partial class Form1 : Form
{
private void updateConfigFile()
{
GestioneSetupFiles.CheckConfigDir();
}
}
}
Upvotes: 0
Views: 2482
Reputation: 549
There may be a better way to do it, but in my case the module in question was part of a VB project that also had a class library that I could reference. I just created a method in that library that called the function in the module. This gave me access and I didn't need to duplicate code. When we rewrite it, I should not need to change my C# code. It was a little different because I was accessing a function within the module, but here I THINK it would look like this, but you get the idea:
Public Class MyLibrary
Public Shared Sub GestioneSetupFiles()
GestioneSetupFile.GestioneSetupFiles()
End Sub
End Class
Upvotes: 0
Reputation: 18843
here is the C# converted code that you need.. make sure if you add this to a Class that you put the
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
namespace GestioneSetupFile
{
public static class GestioneSetupFiles
{
private const short TAB_POS = 30;
static string Testo;
static string Paragrafo;
static int PtrParagrafo;
public static string DEFAULT_APP_DIR = My.Application.Info.DirectoryPath;
public static string DEFAULT_APP_DIR = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\BTSR\\PC-LINK NEMO";
public static string DEFAULT_CONFIG_DIR = DEFAULT_APP_DIR + "\\Config";
public static void CheckConfigDir()
{
if (!My.Computer.FileSystem.DirectoryExists(DEFAULT_CONFIG_DIR))
{
string NomeFile = null;
My.Computer.FileSystem.CreateDirectory(DEFAULT_CONFIG_DIR);
NomeFile = FileSystem.Dir(DEFAULT_APP_DIR + "\\*.cfg");
while (!string.IsNullOrEmpty(NomeFile))
{
My.Computer.FileSystem.MoveFile(DEFAULT_APP_DIR + "\\" + NomeFile, DEFAULT_CONFIG_DIR + "\\" + NomeFile);
My.Computer.FileSystem.CopyFile(DEFAULT_APP_DIR + "\\" + NomeFile, DEFAULT_CONFIG_DIR + "\\" + NomeFile);
NomeFile = FileSystem.Dir();
}
NomeFile = FileSystem.Dir(DEFAULT_APP_DIR + "\\*.dat");
while (!string.IsNullOrEmpty(NomeFile))
{
My.Computer.FileSystem.MoveFile(DEFAULT_APP_DIR + "\\" + NomeFile, DEFAULT_CONFIG_DIR + "\\" + NomeFile);
My.Computer.FileSystem.CopyFile(DEFAULT_APP_DIR + "\\" + NomeFile, DEFAULT_CONFIG_DIR + "\\" + NomeFile);
NomeFile = FileSystem.Dir();
}
}
}
}
}
To see Hot Root NameSpace Work in VB vs C#.NET take a look here and you will see how to fix your problem otherwise the converted portion is what I have started for you is here..
Upvotes: 1