Calling referenced .NET assemblies: Could not load file or assembly
See original GitHub issueUsing an DllExported-dll as a broker between VBA and other .NET code (separate dll’s) doesn’t seem to work.
How to reproduce
See attached project DllExportTest.zip
- ClassLibrary1 exposes UnmanagedExport.CreateBroker(). Works fine.
- CreateBroker returns new Class1 (from ClassLibrary1). Works fine.
- Class1.DoNothingOnClass2() creates an instance of Class2 (from ClassLibrary2) and runs a quite simple method on it.
Build de project. In a VBA-module (I used Access):
Declare Function CreateBroker Lib "C:\source\repos\DllExportTest\ClassLibrary1\bin\Debug\ClassLibrary1.dll" () As Object
Public Sub RunTest()
Dim class1 As Object
Set class1 = CreateBroker()
class1.DoNothingOnClass2
Set class1 = Nothing
End Sub
(be sure to correct the path in the Declare Function to point to the built dll)
Execute the RunTest()
VBA gives “'Could not load file or assembly ‘ClassLibrary2, version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of iets dependencies. The system cannot find the file specified.”
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Could not load file or assembly or one of its dependencies
NET assembly (a .dll or .exe file) to get a graph of all the referenced assemblies while highlighting conflicting or missing references.
Read more >How to resolve “Could not load file or assembly … or one of its ...
Code base or Probing: First checks in location in <codeBase> element. If not present, then probing is done in Application base considering culture,...
Read more >Could not load file or assembly
In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were...
Read more >UnitTest fails for a DLL which uses assemblies (Could not ...
NET) => I'm currently getting “false” test results (I know this library ... FileNotFoundException : Could not load file or assembly 'System.
Read more >Understanding How Assemblies Load in C# .NET
Determine the version of the assembly that needs to load according to configuration files (app.config or web.config). That configuration file ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanx Denis, got it work with following change: In Class1.DoNothingOnClass2 (where Class2 was initialized), change body of DoNothingOnClass2() from
to
After that, found that AssemblyResolve works better, because it loads all types from referenced assembly, and in ClassLibrary1 everything is typed. Solution (for others reference): static class UnmanagedExport (from sample project) should be:
Thank you so far Denis, I will dive into it and share my experience here