Comments (9)
Please be more specific
from keralua.
an anycpu classlib default depens on a lua54.dll(x86)
when build with a classlib It build output with a x64 lua54.dll
when run with the classlib it show
System.BadImageFormatException: 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
from keralua.
dotnet framework 4.5
from keralua.
What are you trying to do? What are the repro steps?
from keralua.
.net framework4.5 classlib
using NLua;
namespace luali
{
public class Class1
{
public static void Run()
{
using(var lua=new Lua())
{
}
}
}
}
.net framework4.5 Console app
using luali;
using System;
namespace luan2
{
class Program
{
static void Main(string[] args)
{
try
{
Class1.Run();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.Read();
}
}
}
build and run
System.BadImageFormatException: 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
在 KeraLua.NativeMethods.luaL_newstate()
在 NLua.Lua..ctor()
在 luali.Class1.Run() 位置 C:\Users\heyz\Desktop\luali\Class1.cs:行号 9
在 luan2.Program.Main(String[] args) 位置 C:\Users\heyz\Desktop\luan\luan2\Program.cs:行号 12
from keralua.
The problem is because the NuGet target copies the x86 since the main program has the flag Preffer32 bit.
Try to uncheck that flag
ConsoleApp2.zip
from keralua.
i found that in the KeraLua.targets setting
<PropertyGroup>
<!-- handle x86/x64 specifically -->
<PreferredNativeLua Condition=" '$(PreferredNativeLua)' == '' and ( '$(PlatformTarget)' == 'x64' or '$(PlatformTarget)' == 'x86' ) ">$(PlatformTarget)</PreferredNativeLua>
<!-- handle Any CPU, considering Prefer32Bit -->
<PreferredNativeLua Condition=" '$(PreferredNativeLua)' == '' and '$(Prefer32Bit)' == 'False' ">x64</PreferredNativeLua>
<PreferredNativeLua Condition=" '$(PreferredNativeLua)' == '' and '$(Prefer32Bit)' == 'True' ">x86</PreferredNativeLua>
<!-- fall back to x64 on 64-bit machines -->
<PreferredNativeLua Condition=" '$(PreferredNativeLua)' == '' and $([System.Environment]::Is64BitOperatingSystem) ">x64</PreferredNativeLua>
<!-- fall back to x86 -->
<PreferredNativeLua Condition=" '$(PreferredNativeLua)' == '' ">x86</PreferredNativeLua>
</PropertyGroup>
but a classlib can never set the flag Preffer32 bit.
because my main app and my classlib was built separate ,so that will be a problom
from keralua.
Change the Prefer32Bit flag from your final .exe 😉
from keralua.
Let me try to explain what is happening:
When you run a AnyCPU assemply that contains the flag Prefer32 bit the CLR may or may not run your application as x64.
In your case when you reference a class library (AnyCPU) CLR is loading your application as x64.
The way that the .targets works, will copy the x64 version if the flag Prefer32 is not set.
There a couple of options you can workaround this:
- You can move your assemblies to a specific target e.g x64
- You can remove the flag Prefer32bits and the .targets will copy the x64 bit
- You can p/Invoke SetDllDirectory and specify the directory you want to load the DLL depending if you are running x86 or x64 (Some binding libraries do this, but I don't think is a good idea since that afect the whole process I guess is up to the user if they want to change the DLL directory search.
I hope this help you thank you.
from keralua.
Related Issues (20)
- Xamarin/Android: dlopen liblua53.so fails HOT 12
- Logo Copyright HOT 1
- Can't Build using VS 2019 Native Tools HOT 5
- 当lua代码出现死循环 我该怎么停止运行 这个时候button没有反应
- Fails to load lua53 assembly when building with Mono. HOT 9
- State.NewLib State.SetFuncs: Attempted to read or write protected memory HOT 1
- Docs / Examples HOT 2
- How to use KeraLua.Lua.NewUserData correctly HOT 2
- Where is cyrillic support? HOT 6
- LuaSocket Debugger Support
- Build fails in Ubuntu/WSL using latest git HOT 1
- Linux library is not portable across distributions HOT 1
- Is it thread clean , when use as one tread one lua VM
- Can you open only some libraries? HOT 5
- Why data can be written at an offset memory location? HOT 1
- Can The State Be Set?
- Value returned from Lua.FromIntPtr should not be Disposable HOT 6
- DllNotFoundException with Unity
- NLua.Exceptions.LuaScriptException:“[string "chunk"]:3: attempt to index a nil value (global 'bit')” HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keralua.