chronoxor / CSharpServer

Ultra fast and low latency asynchronous socket server & client C# library with support TCP, SSL, UDP protocols and 10K connections problem solution
https://chronoxor.github.io/CSharpServer
MIT License
112 stars 31 forks source link

Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format. #7

Open mbpakalin opened 4 years ago

mbpakalin commented 4 years ago

Hello, First of all thanks for this awesome project. My problem is, i can use this project on console & desktop apps but can't use with MVC. The error as is title says, cant load the dll into the app. I'm putting full stack on the bottom. How can i fix this problem ?

=== Pre-bind state information ===
LOG: DisplayName = CSharpServer
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: CSharpServer | Domain ID: 4
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/x/source/repos/dllLoadTest/dllLoadTest/
LOG: Initial PrivatePath = C:\Users\x\source\repos\dllLoadTest\dllLoadTest\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\x\source\repos\dllLoadTest\dllLoadTest\web.config
LOG: Using host configuration file: C:\Users\x\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/f5bfae5a/2e8a1155/CSharpServer.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/f5bfae5a/2e8a1155/CSharpServer/CSharpServer.DLL.
LOG: Attempting download of new URL file:///C:/Users/x/source/repos/dllLoadTest/dllLoadTest/bin/CSharpServer.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
[BadImageFormatException: Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +37
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +159
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +80
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +29
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +39

[ConfigurationErrorsException: Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +777
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +229
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +140
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +176
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +99
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +310
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +165
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +590

[HttpException (0x80004005): Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10080656
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +263
chronoxor commented 4 years ago

You need C++ runtime to run this in release mode. Try to install VS redistributable packages: Visual Studio 2015, 2017 and 2019 x86 Visual Studio 2015, 2017 and 2019 x64

mbpakalin commented 4 years ago

I already built this. No problem there. When i create a empty MVC project or existing one, when i include built dll's or the ones on your github release. The error is still there.

mbpakalin commented 4 years ago

Like i said, it works very well with console & desktop apps. But on the web project. This error shows up.

chronoxor commented 4 years ago

You can also try new .NET Core version of server/client. It is written on pure C# without C++ dependency. It is recommended for .net projects - https://github.com/chronoxor/NetCoreServer

mbpakalin commented 4 years ago

I'm already using .Net core version on some other project. It works really really well. Thanks again for this project btw. But in this one, we still didnt transfer to the .Net Core. U have any tips for me to how to fix this ? Because i'm really stuck there :D What should i try ? I already tried all other github libs for tcp client. They can't handle after a little bandwidth spike.

chronoxor commented 4 years ago

I believe your web project cannot load some C++ library. Make sure all this libs are available through PATH envar: image

mbpakalin commented 4 years ago

Thanks mate. Trying right away.

mbpakalin commented 4 years ago

@chronoxor I tried but it didnt work. I guess, i need to start to moving .net Core :) Thanks anyway sir.

findli commented 2 years ago

Hello, First of all thanks for this awesome project. My problem is, i can use this project on console & desktop apps but can't use with MVC. The error as is title says, cant load the dll into the app. I'm putting full stack on the bottom. How can i fix this problem ?

=== Pre-bind state information ===
LOG: DisplayName = CSharpServer
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: CSharpServer | Domain ID: 4
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/x/source/repos/dllLoadTest/dllLoadTest/
LOG: Initial PrivatePath = C:\Users\x\source\repos\dllLoadTest\dllLoadTest\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\x\source\repos\dllLoadTest\dllLoadTest\web.config
LOG: Using host configuration file: C:\Users\x\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/f5bfae5a/2e8a1155/CSharpServer.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/f5bfae5a/2e8a1155/CSharpServer/CSharpServer.DLL.
LOG: Attempting download of new URL file:///C:/Users/x/source/repos/dllLoadTest/dllLoadTest/bin/CSharpServer.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
[BadImageFormatException: Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +37
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +159
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +80
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +29
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +39

[ConfigurationErrorsException: Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +777
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +229
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +140
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +176
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +99
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +310
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +165
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +590

[HttpException (0x80004005): Could not load file or assembly 'CSharpServer' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10080656
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +263

Hi, "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2202,5): warning MSB3274: The primary reference "CSharpServer, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null" could not be resolved because it was built against the ".NETFramework,Version=v4.8" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.7.2"."

as this log msg states it needs to be targeted to 4.8 and then it compiles.

in csproj file: <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>