IL2CPP does not support marshaling delegates that point to instance methods to native code.

NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we’re attempting to marshal is: UMP.Wrappers.WrapperStandalone::DebugLogHandler
NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we’re attempting to marshal is: UMP.MediaPlayerStandalone::InitBufferSize

using AOT;
[MonoPInvokeCallback(typeof(ManageLogCallback))]
private static void DebugLogHandler(string msg)
{
UnityEngine.Debug.LogError(msg);
}

_manageBufferSizeCallback = InitBufferSizeCallBack;
[MonoPInvokeCallback(typeof(ManageBufferSizeCallback))]
private static void InitBufferSizeCallBack(int width, int height)
{
if(instance!=null)
{
instance.InitBufferSize(width,height);
}
}

1、必须使用[MonoPInvokeCallback(typeof(ManageBufferSizeCallback))]
2、必须改为static方法

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
PInvoke插件 RedGate.PInvokeExtension VS平台调用插件 PInvoke 平台调用 调用C++ 调用系统 C#调C++, Search Module: Directory Constants Delegates Enums Interfaces Structures Desktop Functions: advapi32 avifil32 cards cfgmgr32 comctl32 comdlg32 credui crypt32 dbghelp dbghlp dbghlp32 dhcpsapi difxapi dmcl40 dnsapi dtl dwmapi faultrep fbwflib fltlib fwpuclnt gdi32 gdiplus getuname glu32 glut32 gsapi hhctrl hid hlink httpapi icmp imm32 iphlpapi iprop irprops kernel32 mapi32 MinCore mpr mqrt mscorsn msdelta msdrm msi msports msvcrt ncrypt netapi32 ntdll ntdsapi odbc32 odbccp32 ole32 oleacc oleaut32 opengl32 pdh powrprof printui propsys psapi pstorec query quickusb rasapi32 rpcrt4 scarddlg secur32 setupapi shell32 shlwapi twain_32 unicows urlmon user32 userenv uxtheme version wer wevtapi winfax winhttp wininet winmm winscard winspool wintrust winusb wlanapi ws2_32 wtsapi32 xolehlp xpsprint Smart Device Functions: aygshell coredll ipaqutil rapi Glossary distributed computing LibHolocaust Marshaling Marshalling Marshalling PInvoke test pinvoke Show Recent Changes Subscribe (RSS) Misc. Pages Comments FAQ Helpful Tools Playground Suggested Reading Website TODO List Support Forum Download Visual Studio Add-In Terms of Use Privacy Policy Create page PInvoke (glossary) Summary The mechanism provided by the CLR that enables managed code to call static DLL exports. Access PInvoke.net directly from VS: Terms of Use Edit This Page Find References Show Printable Version Revisions Show changes
以下是一个简单的示例代码,使用 Gin 框架和 Redis 6.0,同时使用 Go 的协程来处理多线程,并且在高并发下保证数据一致性。该示例使用的是快递鸟API进行查询物流信息。 ```go package main import ( "encoding/json" "fmt" "log" "net/http" "sync" "github.com/gin-gonic/gin" "github.com/go-redis/redis/v8" ) type LogisticsInfo struct { CompanyName string `json:"company_name"` Origin string `json:"origin"` Destination string `json:"destination"` LastTime string `json:"last_time"` LastLocation string `json:"last_location"` Courier string `json:"courier"` CourierMobile string `json:"courier_mobile"` Site string `json:"site"` IsSigned bool `json:"is_signed"` Details string `json:"details"` } var ( redisClient *redis.Client mu sync.Mutex ) func init() { redisClient = redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", // no password set DB: 0, // use default DB }) } func main() { router := gin.Default() router.GET("/logistics/:id", func(c *gin.Context) { id := c.Param("id") // Try to get the logistics info from Redis cache logistics, err := getLogisticsFromCache(id) if err != nil { log.Printf("Error getting logistics info from cache: %v", err) } // If the logistics info is not in cache, query from the API if logistics == nil { logistics, err = queryLogisticsFromAPI(id) if err != nil { log.Printf("Error querying logistics info from API: %v", err) c.AbortWithError(http.StatusInternalServerError, err) return } // Save the logistics info to Redis cache if err := saveLogisticsToCache(id, logistics); err != nil { log.Printf("Error saving logistics info to cache: %v", err) } } c.JSON(http.StatusOK, logistics) }) router.Run(":8080") } func getLogisticsFromCache(id string) (*LogisticsInfo, error) { mu.Lock() defer mu.Unlock() val, err := redisClient.Get(redisClient.Context(), id).Result() if err == redis.Nil { // Key does not exist in Redis cache return nil, nil } else if err != nil { return nil, fmt.Errorf("error getting logistics info from cache: %v", err) } var logistics LogisticsInfo if err := json.Unmarshal([]byte(val), &logistics); err != nil { return nil, fmt.Errorf("error unmarshaling logistics info from cache: %v", err) } return &logistics, nil } func saveLogisticsToCache(id string, logistics *LogisticsInfo) error { mu.Lock() defer mu.Unlock() jsonBytes, err := json.Marshal(logistics) if err != nil { return fmt.Errorf("error marshaling logistics info to cache: %v", err) } if err := redisClient.Set(redisClient.Context(), id, string(jsonBytes), 0).Err(); err != nil { return fmt.Errorf("error saving logistics info to cache: %v", err) } return nil } func queryLogisticsFromAPI(id string) (*LogisticsInfo, error) { // TODO: Replace with your own API key and API URL apiKey := "your_api_key" apiURL := "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx" // Create the HTTP request to query the API req, err := http.NewRequest("POST", apiURL, nil) if err != nil { return nil, fmt.Errorf("error creating HTTP request: %v", err) } // Set the required headers for the API request req.Header.Set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36") req.Header.Set("Accept", "*/*") // Set the query parameters for the API request q := req.URL.Query() q.Add("RequestData", "") q.Add("EBusinessID", "") q.Add("RequestType", "") q.Add("DataSign", "") q.Add("DataType", "") req.URL.RawQuery = q.Encode() // Send the HTTP request to the API and parse the response client := http.Client{} resp, err := client.Do(req) if err != nil { return nil, fmt.Errorf("error querying logistics info from API: %v", err) } defer resp.Body.Close() var logistics LogisticsInfo if err := json.NewDecoder(resp.Body).Decode(&logistics); err != nil { return nil, fmt.Errorf("error decoding logistics info from API response: %v", err) } return &logistics, nil } ``` 使用协程来处理多线程,我们可以在路由处理函数中使用 `go` 关键字开启一个协程,以异步方式处理 Redis 缓存的读取和写入操作。在读取 Redis 缓存时,我们使用 `sync.Mutex` 来保证数据一致性,以避免在高并发下出现数据竞争的问题。同时,为了提高并发能力,我们可以使用 Redis 的连接池来处理多个并发请求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值