RoslynPad: could not load file or assembly exception - .net-assembly

I am using RoslynPad project to test how external plugins (Class libraries) could be used in the script.
I have created Class Library with a single class and method.
In roslynPad project i have added "plugin_demo" into RoslynHostReferences NamespaceDefault structure.
I have also added reference to plugin dll:
MetadataReference newref = MetadataReference.CreateFromFile("G:\\projects\\demos\\plugin_demo\\plugin_demo\\bin\\Debug\\plugin_demo.dll");
MetadataReferences = MetadataReferences.Add(newref);
Now i see that my new class is seen by diagnostics and autocomplition also works.
The code with a method call compiles fine.
But when i run it i get exception:
Could not load assembly or file. File not found.
I have copied plugin_demo.dll into directory where compiled roslynPad dll resides. Still no result.
I have checked that class library and roslynpad use the same .Code version.
What can be the problem?
What is correct way of adding assemblies to roslyn project?
Thanks

I have solved the problem after debugging. The roslynPad project generates file nams_deps.json when editor is launched. It must be deleted and after that the assembly is found.

Related

DLL needs LIB, but looking for DLL

In my source I have:
#pragma comment(lib, "ldv32.lib")
Originally this was:
#pragma comment(lib, "ldv32")
When I build and then try to register the DLL it fails:
I used "Dependency Walker" to look at the DLL and I could see that it was trying to open LDV32.DLL, so I then edited the project and modified the pragma. Cleaned and Rebuilt project, however it still fails and "Dependency Walker" still reports that the DLL is looking for LDV32.DLL
How do I fix this, I've checked the path and project build, the location of the LIB is specified but why is it looking for a DLL and not the LIB?
The library ldv32.lib is an import library. It resolves the externals that are used in your DLL module. But it implements only small stubs. When the module is loaded with LoadLibrary, some code in the the ldv32.lib tries to load the DLL ldv32.dll that implements the actual functionality.
You should lookup the Echolon OpenLDV DLL "ldv32.dll" and copy it in the folder where the process is loaded from. If you share your program or DLL make sure to include that DLL.
You can also check if a static LIB exists. In that case you can link with that.

Error Running Code Analysis in VS2012: Could not resolve type reference

When I click the Run Code Analysis project context menu item. Building starts, but stops with following error:
CA0001 Error Running Code Analysis
CA0001 : The following error was encountered while reading module 'EntityFramework':
Could not resolve type reference:
[System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35]System.ComponentModel.DataAnnotations.Schema.ColumnAttribute. [Errors and Warnings] (Global)
Analysis on other projects works well. How to eliminate this problem?
I tried the solution mentioned by Scott Wylie. I tried adding a reference to System.ComponentModel.DataAnnotations in my project but that did not help.
I then tried copying and pasting the System.ComponentModel.DataAnnotations.dll directly into my bin folder and that did the trick. Add the dll into your local bin folder, publish the solution, then manually add the dll into the bin folder of your published project (if it didn't copy up on its own).
The System.ComponentModel.DataAnnotations dll may not be used by your application but it is internally referenced by EntityFramework.dll. Code Analysis will look at all of your referenced dll's and try to resolve their references too. If you add the System.ComponentModel.DataAnnotations.dll to your application, this error will go away next time you run Code Analysis.

How to use tlb files in a native C++ project

I have a tlb files that contains some function declaration that I need to use.
If I use
#import "type_library.tlb"
I can correclty reference the function from my code:
tlb_namespace::required_function();
But when I compile the project the linker says that tlb_namespace::required_function is an unresolved external symbol.
How can I succesfully build this kind of project?
EDIT:
I have used the same type library in a Dummy VBA access project. I have added the reference to the type library and I have noticed that some of the function contained in the type library are correctly called. But some of them are not. VBA says It can't locate their entry point in the related dll.
Can this explain the unresolved external symbol when building c++ app?
I have also noticed that the failing function are declared in the tlb like this:
UPPER_function_name
but in the dll are declared like this:
Upper_function_name
Can this be the issue?
Is it possible to solve this kind of error directly modifying the binary tlb file or dll?
Use IDE to view TLB information.
Use this help : How to: View Type Library Information
At IDE : View-> Object Browser, click "..." Edit Custom Component Set, browse your TLB file and Add to view information.
Confirm namespace used for.
use the namespace to resolve the linker error:
example:
#import "<>" raw_interfaces_only
using namespace <>
this will resolve the problem

Not able to find AssemblyFactory class using Mono.Cecil

I am using the Mono.Cecil DLL file and writing this code:
AssemblyDefinition sourceAssembly = AssemblyFactory.GetAssembly(assemblyPath);
My project is not getting compiled, because it is not able to find the class "AssemblyFactory". As if this class is not present in the DLL file at all. I have added the mono.cecil.dll file as a reference to my project. Is this class present somewhere outside the DLL file, maybe in some other DLL file at the .NET level?
This simply means that you're using an up to date version of Mono.Cecil where this deprecated type has been removed.
Please have a look at the migration page on Cecil's wiki to know how to convert code for Cecil 0.9. You'll see that you just have to change this line to read:
var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);

Cruise Control .NET ignoring project dependencies

I have been using CC.Net successfully for some time, but now I have a problem. I added new solution to CC. It is compiled fine in VS2008, but fails in CC. The main reason is - projects in solution are built in wrong order, with no regard to dependencies. CC just tries to build them in the same order as they are stored on disc (alphabetical order).
For example, in solution there is proect Proj1 and Proj2, Proj1 has reference to Proj2. On CCNET Proj1 is built before Proj2 and throws error "CSC : error CS0006: Metadata file 'D:\xxx\Proj2\bin\Debug\Proj2.dll' could not be found".
I know this could happen when devenv is used to build solutions, but I use MSBuild.
The following code is responsible for building:
<exec>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<baseDirectory>code\src</baseDirectory>
<buildArgs>/p:Configuration=Debug /t:Rebuild PM.sln</buildArgs>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
</exec>
What am I doing wrong?
The error Metadata file could not be found:
When it happened to me, it was because there was a file called proj1.exe at that location that should not have been there. So when it used proj1.exe as the reference (instead of a proj1.dll), proj1.exe's reference to a local System.EnterpriseServices.dll failed. This was happening to me with proj1.exe referencing System.EnterpriseServices.dll which referenced System.EnterpriseServices.Wrapper.dll. Where proj1.exe was not supposed to be included in the build but someone had named a unit test app project against our team conventions.
So I recommend checking the references in the project files(unload project and edit project in vs2010 or open each project file with a text or xml editor) to make sure they are ProjectReference not Reference. Also try doing the build with /v:d in the buildArgs list so you get a more detailed build log that will show you where files were resolved to and in what order. Aa different reference that is 'successfully' resolved could be attempting to load x.dll that directly locally references your D:\xxx\Proj2\bin\Debug\Proj2.dll but fails.

Resources