Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
579 stars 96 forks source link

Unable to load file or composition Discord RPC #24

Closed ghost closed 6 years ago

ghost commented 6 years ago

Unmanaged exception: System.IO.FileNotFoundException: Unable to load file or composition Discord RPC, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null, or one of its dependencies. The file can not be found.     at DiscordRPCTest.Program.Main (String [] args)

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

namespace DiscordRPCTest
{
    class Program
    {
        public static DiscordRpcClient client;

        static void Main(string[] args)
        {
            client = new DiscordRpcClient("458202823641792512", true, 1);

            //Subscribe to events
            client.OnPresenceUpdate += (sender, e) =>
            {
                Console.WriteLine("Received Update! {0}", e.Presence);
            };

            //Connect to the RPC
            client.Initialize();

            //Set the rich presence
            client.SetPresence(new RichPresence()
            {
                Details = "CrunchyHub",
                State = "csharp example",
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "Lachee's Discord IPC Library",
                    SmallImageKey = "image_small"
                }
            });
            Console.ReadLine();
        }
    }
}
Lachee commented 6 years ago

Hello, been meaning to respond to your other issue but glad you have managed to get started. Make sure you have the required dependencies in your project. The only dependency this library has is Newtonsoft.Json which you can install through the nuget package manager.

ghost commented 6 years ago

@Lachee Thank you for answering! I am installing Newtonsoft.Json now. I have a question. What is the DiscordPipe? I just put a random number there (1).

ghost commented 6 years ago

Update: I installed Newtonsoft but still get a error

Unmanaged exception: System.IO.FileNotFoundException: Unable to load file or composition Discord RPC, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null, or one of its dependencies. The file can not be found. at DiscordRPCTest.Program.Main (String [] args)

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

namespace DiscordRPCTest
{
    class Program
    {
        public static DiscordRpcClient client;

        static void Main(string[] args)
        {
            client = new DiscordRpcClient("458202823641792512", true, 1);

            //Subscribe to events
            client.OnPresenceUpdate += (sender, e) =>
            {
                Console.WriteLine("Received Update! {0}", e.Presence);
            };

            //Connect to the RPC
            client.Initialize();

            //Set the rich presence
            client.SetPresence(new RichPresence()
            {
                Details = "CrunchyHub",
                State = "csharp example",
                Assets = new Assets()
                {
                    LargeImageKey = "image_large",
                    LargeImageText = "Lachee's Discord IPC Library",
                    SmallImageKey = "image_small"
                }
            });
            Console.ReadLine();
        }
    }
}
Lachee commented 6 years ago

Discord Pipe is the pipe number that discord is currently hosted on. It can be 0 to 9. Setting it to -1 will let the library to automatically scan for discord through those pipes.

What version of .NET are you working with? Are you using .NET Standard or a older version?

Lachee commented 6 years ago

I think I found the solution hopefully. So in Visual Studio when you add the assembly, you need to make the library "Copy to Local". It should look similar to the following image: Visual Studio Project View

ghost commented 6 years ago

.Net Framework 4.6.1 and yes, i have copy local enabled but it still doesn't work

ghost commented 6 years ago

And i dont have it as a assembly i have it as a reference. It's a console application

ghost commented 6 years ago

Made a github repo https://github.com/Hampusm/DiscordRPC-Csharp-test

ghost commented 6 years ago

@Lachee

Lachee commented 6 years ago

@Hampusm found the problem. Your filename is DiscordRPC.dll, however when you build DiscordRPC it outputs Discord RPC.dll .NET expects the filename to be the same as the assembly name, but with .dll appended to the end. Since you renamed it (or bad build), it could not locate the correct file.

You can fix this by simply renaming your DiscordRPC.dll to Discord RPC.dll.

I have also just made made a commit which changes the assembly name from Discord RPC.dll to DiscordRPC.dll since it makes more sense, so I recommend you rebuild the library and replace our previous .dll with the new one.

ghost commented 6 years ago

Just to let you know. Dont close the issue yet i dont know it it works yet. i am cloning rn

Lachee commented 6 years ago

Just updated my comment to be a bit clearer about the issue.

ghost commented 6 years ago

Got it to work now! Thank you @Lachee for the help!

ghost commented 6 years ago

Never mind it doesnt work. No error or anything discord just doesnt say anything dontwork

ghost commented 6 years ago

https://github.com/Hampusm/DiscordRPC-Csharp-test

ghost commented 6 years ago

@Lachee

ghost commented 6 years ago

Nvm it works