C#: Could not load file or assembly 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' or one of its dependencies

StackOverflow https://stackoverflow.com/questions/9999441

  •  28-05-2021
  •  | 
  •  

Question

I am attempting to use OpenPop.NET to access a gmail account, however I am receiving the error message below even with basic testing code.

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' at ST_1694f4bcdf2a4068ae871201a2216457.csproj.ScriptMain.Main()

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

--- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

I am trying to do this in an SSIS package in SQL Server Business Intelligence Development Studio 2008 on a Windows 7 machine with .NET framework 3.5 and 4. Both the OpenPop dll and the script task that is referencing it are being built in 3.5. I have been researching this for a few days but haven't been able to find anything that could fix it. I have tried recompiling the OpenPop dll from source and removing and re-adding the reference multiple times.

The code I am currently working with is posted below:

        Pop3Client client = new Pop3Client();

        try
        {
            client.Connect("pop.gmail.com", 995, true);

            try
            {
                client.Authenticate("user@domain.com", "mypassword");
                Console.WriteLine("Success");
                client.Disconnect();
            }
            catch
            {
                Console.WriteLine("Failed to authenticate");
                Dts.TaskResult = (int)ScriptResults.Failure;
                return;
            }
        }
        catch
        {
            Console.WriteLine("Failed to connect");
            Dts.TaskResult = (int)ScriptResults.Failure;
            return;
        }

        Dts.TaskResult = (int)ScriptResults.Success;

Thank you in advance.

Was it helpful?

Solution

Ive experience this problem too and the solution is actually quite simple. You have to install the referenced assembly to the GAC of the server youre running the package on.

1) Verify that the assembly is signed, if you created your own assembly, sign it.

2) Install the DLL to the GAC using gacutil.exe from SDK tools of Visual Studio. For more info, see How to: Install an Assembly into the Global Assembly Cache.

3) Reference the same DLL from your Script Task

Voila, it should work perfectly now!

OTHER TIPS

Installing your DLL to GAC(global assembly cache)

1)Visual Studio Command Prompt => Run as Adminstrator

2)gacutil /i "dll file path"

3) see assembly on C:\Windows\system32\

It Will also solve dll missing or "Could not load file or assembly" in SSIS Script task

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top