Jump to content
AppleB

Defined in assembly but not referenced

Recommended Posts

AppleB

It says I need to reference an assembly, but I do not know where to do that or what assembly to reference

error:

image.thumb.png.32eeeea39ec67dd34fc034976ef7471f.png

VS code:

image.thumb.png.c0c72e707c2cf254556da34bee1cbd81.png

 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

post the code please. not images. also, What are you using to build this DLL?

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

try this

1) use your IDE to create your DLL

2) look at the DotNet examples group number 4, DotNet_LoadAssembly and load your DLL like that?

If everything is built right and all the correct references made then it will work. What are you using to build your dll?

also, I don't think you can use static methods in your CS code, at least the _connect() method

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
AppleB

Hopefully this is what you need.

And will I have to load every assembly that I need to use?

I loaded my assembly correctly because it worked before i needed to use different libraries to connect with a database

AtoCLib.sln

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

no mate. I need the .vcsproj files and such

I would build the dll properly, then just load that assembly. you don't have to slow down to compile that way either.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
AppleB

this?

Sorry This is my first week using .NET, C#, or AutoIt. So I'm not that familiar with some of the stuff.

 

I guess I dont know how to build a dll properly. I just always used the dll that i got from compiling my class

AtoCLib.csproj

Share this post


Link to post
Share on other sites
Earthshine

ok then. take that compiled dll, that compiles correctly, I assume, and use the Load_Assembly stuff on that dll and see what happens.


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

from your infomation

<ItemGroup>
    <Reference Include="Dapper, Version=1.50.5.0, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>..\packages\Dapper.1.50.5\lib\net451\Dapper.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="DataAccessLayer.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config" />
    <None Include="packages.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

we can see what all the dependencies are.

    <Reference Include="System" /> = System.dll, etc... do the rest for the rest
    <Reference Include="System.Core" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />

      <HintPath>..\packages\Dapper.1.50.5\lib\net451\Dapper.dll</HintPath>
 is your db stuff, right?

and the Microsoft.CSharp.dll so you had better be loading ALL of those if you are compiling. Look at the output directory where you get your DLL, is there any other DLLs there? you may need those at run time in the same directory


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

if you are running this on a test machine where those dlls are not installed, you must have them all included with your dll to run properly, compiled or not


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
AppleB

The only other dll is the dapper dll which i have referenced.

And its a test database, but i am not running it on a test machine. 

i thought I included all of those. Here is my Autoit code. could I be missing something here?

Process.au3

Share this post


Link to post
Share on other sites
Earthshine

if you want to run it as an exe, we can do that with a little mod to the source if you post the csharp code


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
AppleB

Will that help?

I just dont understand why AutoIt doesnt recognize it

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

dude, if you are going to compile code, yes, it needs all the dependencies listed

    Local $oCode = DotNet_LoadCScode( FileRead( "..\..\AtoCLib\AtoCLib\Class1.cs" ))
you need to specify all those dlls i quoted from your vcsproj file, something like the sample I posted

Local $oCode = DotNet_LoadCScode( FileRead( "Program.cs" ), "Microsoft.CSharp.dll | System.dll | System.Core.dll | System.Data.dll | System.Windows.Forms.dll | System.Data.DataSetExtensions.dll | System.Net.Http.dll | System.Xml.dll | System.Xml.Linq.dll" ) ; You must add the "System.Windows.Forms.dll"

just add dapper to the list and that will probably work in your code.

Local $oCode = DotNet_LoadCScode( FileRead( "Class1.cs" ), "Microsoft.CSharp.dll | System.dll | System.Core.dll | System.Data.dll | System.Windows.Forms.dll | System.Data.DataSetExtensions.dll | System.Net.Http.dll | System.Xml.dll | System.Xml.Linq.dll | Dapper.dll" ) ;

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
AppleB

Yeah I already tried that when i started, but i get the same errors that i do now.

And when I asked if it would help, i was replying to this.

11 minutes ago, Earthshine said:

if you want to run it as an exe, we can do that with a little mod to the source if you post the csharp code

 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

post the .cs fike and i will show you 

 

oh, did you try this?

#include "..\..\Includes\DotNetUtils.au3"

Opt( "MustDeclareVars", 1 )

Example()

Func Example()
    ; Loads a .NET assembly DLL-file into the default domain
    Local $oXPTable = DotNet_LoadAssembly( "Class1.dll" )
    If @error Then Return ConsoleWrite( "DotNet_LoadAssembly ERR" & @CRLF )
    ConsoleWrite( "DotNet_LoadAssembly OK" & @CRLF )
    DotNet_ListDomainsEx()
    DotNet_ListAssembliesEx()
    #forceref $oXPTable
EndFunc

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

as for running it as compiled code, check the snippet I posted in the other thread

class Foo
{
    public void Test(string dir, string filespec)
    {
//        if (argv.Length < 2)
//        {
//            Console.WriteLine(value: "ERROR: args = null please provide a path and a file specification to search for.");
//            Console.WriteLine(value: "Example: list c:\\ *.dll");
//        }
//        else
//        {       
            //DirectoryInfo testdr = new DirectoryInfo(path: argv[0]);
            //WalkDirectoryTree(testdr, searchname: argv[1]);
            DirectoryInfo testdr = new DirectoryInfo(path: dir);
            WalkDirectoryTree(testdr, searchname: filespec);
//        }
    }
.....
}

do it that way, not declaring it a class the way you do in your code above. and, you cannot call STATIC methods directly in your class or exe, the class itself may still access it's static methods of course, but you can't directly, notice my 'public void Test()' not public static void, you can't do it from AutoIt at least is my point. so remember do not make your entry points static. thanks.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×