How to set up VS 2017 C# to make .dll for Access 2016 reference

Ivan Starr

Member
Joined
Nov 5, 2019
Messages
10
Programming Experience
5-10
Dear Sirs,

Does anyone know how to setup VS 2017 C# project to make .dll for Access 2016 to be used through Tools->references?

I tried many combos of different options but just could not get anything to work. There is a function in System.Net.Sockets that I need to access in MS Access VBA.

If this is not the right place to post this, please advise where is.

Thanks,

Ivan
 
It's not really clear what exactly you're trying to achieve. If you just want to connect to an Access database then you don't need to reference anything, but the ACE database engine needs to be installed for ACCDB files. If you want to Automate the Access application then you need to reference the appropriate Office object library, just as you do for Word or Excel. If you want something else then you'll need to explain.
 
The OP wants to write VBA code and then use VBA's Tools.References...
Capture.png

Capture2.png


It's not a matter of setting up VS2017. It's a matter of writing your code such that it exposes COM objects.

See:
Example COM Class
 
Thanks for replying dude!

I tried your suggestion, I got back the following compiler errors:

Severity Code Description Project File Line Suppression State
Error Cannot register type library "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.tlb". Error accessing the OLE registry. (Exception from HRESULT: 0x8002801C (TYPE_E_REGISTRYACCESS)) ClassLibrary9

and

Severity Code Description Project File Line Suppression State
Warning "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.dll" does not contain any types that can be registered for COM Interop. ClassLibrary9


here's the code (I'm just writing this simple code to get the connection from Access to the VS2017 C# .dll):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary9
{
public static class Class1
{
public static double Add(double num1, double num2)
{
return num1 + num2;
}

}
}


Why should this be so hard?

My user account DOES have local admin rights so I do not know why I got the first error

I don't know why I got the 2nd one either.

All I wanna do is to be able to run code written in some .dll in VS2017 in the Access VBA environnment.

Thanks,

Ivan
 
I just copied the end of the second error message into a search engine and got multiple relevant results with regards to applying attributes to types to enable them to be registered for COM Interop.
 
It's not really clear what exactly you're trying to achieve. If you just want to connect to an Access database then you don't need to reference anything, but the ACE database engine needs to be installed for ACCDB files. If you want to Automate the Access application then you need to reference the appropriate Office object library, just as you do for Word or Excel. If you want something else then you'll need to explain.
No, I don't wanna connect an Access db to VS C#, I wanna connect a C# .dll to Access through Tools->References. More along the lines of what JohnH said, although I still have not been able to get his suggestion to work yet
 
No, I don't wanna connect an Access db to VS C#, I wanna connect a C# .dll to Access through Tools->References. More along the lines of what JohnH said, although I still have not been able to get his suggestion to work yet
You didn't mention specifically that you wanted to create the connection in Access. That didn't occur to me but obviously there are others who are more familiar with the process.
 
Error Cannot register type library "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.tlb". Error accessing the OLE registry.
That error is because you are not running with elevated permissions.
No, I don't wanna connect an Access db to VS C#, I wanna connect a C# .dll to Access through Tools->References.
Maybe you should be a little clearer when describing what you're trying to do in future. It's nobody's fault if they misunderstand you. That's your own fault for assuming everyone should know what you're writing or thinking of. While I too knew what you meant, I didn't bother replying previously, because I can't be bothered to make an assumption on your vague request. If you explain precisely what you want to do, you will get better feedback from the community.

Lastly, this is not the correct forum to post in, and can you kindly use code tags when posting code to the forums.

Thanks
 
I tried your suggestion, I got back the following compiler errors:

Severity Code Description Project File Line Suppression State
Error Cannot register type library "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.tlb". Error accessing the OLE registry. (Exception from HRESULT: 0x8002801C (TYPE_E_REGISTRYACCESS)) ClassLibrary9
That error is because you are not running with elevated permissions.
Note you must run VS as admin for registration to happen.
Right-click the VS start icon and click "Run as administrator".
Severity Code Description Project File Line Suppression State
Warning "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.dll" does not contain any types that can be registered for COM Interop. ClassLibrary9
That's what enabling "Make assembly COM visible" is for, which I also pointed you to.
1573029769914.png
or
1573029893933.png
 
Mr. Sheepings,

Thanks for responding! Yes I'm new here, thnks for putting up with my newbieness.

"That error is because you are not running with elevated permissions."
- Ok ima gonna get on that thanks

"Maybe you should be a little clearer when describing what you're trying to do in future. It's nobody's fault if they misunderstand you."
- There is no blame to be assigned. I accept all blame if I was not clear. Sorry if I wasn't. Of course its not anyones fault if they dont understand me.

"That's your own fault for assuming everyone should know what you're writing or thinking of."
- I never made any such assumption. Also, there is an implicit assumption that I am upset or something, which I'm not. Why would I be? You guys are great! It's all good!

"While I too knew what you meant, I didn't bother replying previously, because I can't be bothered to make an assumption on your vague request."
- Yup. Couldn't agree more. Or you could just ask for a clarification. Because part of the problem of ignorance, the problem people are here to cure, is that sometimes not knowing also means not knowing what to ask exactly.

Lastly, this is not the correct forum to post in, "
- Please advise which forum to post this matter inand if there is a way to migrat this thread there. Thanks. Sorry about that.

"and can you kindly use code tags when posting code to the forums."
- Wuts code tags

Thanks
[/QUOTE]
 
Or you could just ask for a clarification.
Do you have any idea how many times I ask that question on a daily basis, both on this and other forums.
sometimes not knowing also means not knowing what to ask exactly.
I disagree. If you have a problem, you state your problem. If you don't know the problem, then you elaborately explain in great detail what you are doing. How you are doing it. And what you are experiencing which complexes you. There is no science or rocket science involved in expressing an issue you are having or experiencing really. Is there?
Please advise which forum to post this
There is no subsection for vb6 related questions. But this forums is for VS, which makes it unrelated. Perhaps one of the C# sub forums, or even C# General Discussion.
Wuts code tags
These are code tags :
[CODE=csharp] Put your code here [/CODE]
They help keep the formatting and indentation of your code which makes it easier for us to read, so please post your code using code tags in the future. There are three ... dots on the post editor beside the smilie face. Click it and click code tags and paste your code into the box that pops up.

Did you get the above working?

Btw, welcome to the forums.
 
Right-click the VS start icon and click "Run as administrator".

That's what enabling "Make assembly COM visible" is for, which I also pointed you to.
View attachment 695 or View attachment 697
Mr. JohnH,

Thanks for replying! That was great. Well I did the administrator thing like you and Mr. Sheepings said and that worked great to get rid of the error, but the warning,

"warning MSB3214: "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.dll" does not contain any types that can be registered for COM Interop.",

still remains and I think there's some other setting or statement I;m missing (obviously). I'm sure you know the answer!

Thanks,

Ivan
 
If I recall correctly, static classes cannot be exposed to COM. This is because the COM class factory needs to instantiate a class.
 
Mr. Sheepings,

Yes as mentioned ur suggestion re the administrator right-click thing did fix the error but there is still lurking a problemita with the warning,

"warning MSB3214: "C:\Users\GL552V\source\repos\ClassLibrary9\ClassLibrary9\bin\Debug\ClassLibrary9.dll" does not contain any types that can be registered for COM Interop.",

I remember the other build setting I was told about, on the build property page "Register for COM Interop", but there's something still missing obviously, some directive-like thing maybe.

I know you know what it is, so....

Thanks,

Ivan
 

Latest posts

Back
Top Bottom