Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest 4.5.3.20211226 windows binding package breaks .NET Framework #1359

Closed
sdcb opened this issue Dec 28, 2021 · 1 comment · Fixed by #1361
Closed

Latest 4.5.3.20211226 windows binding package breaks .NET Framework #1359

sdcb opened this issue Dec 28, 2021 · 1 comment · Fixed by #1361

Comments

@sdcb
Copy link

sdcb commented Dec 28, 2021

I saw this commit: 889c573 and this commit: 51fee5e switched from detect .NET Core into detect .NET Framework, however, this might buggy and actually failed in .NET Framework.

Because the tranditional-style .NET Framework projects is actually using TargetFrameworkVersion to identify .NET Framework version, instead of TargetFramework (latest line):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<PropertyGroup>
		<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
		<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
		<ProjectGuid>{9211D76F-6902-4B3E-81D5-8DC81EC730D1}</ProjectGuid>
		<OutputType>Exe</OutputType>
		<RootNamespace>ConsoleApp3</RootNamespace>
		<AssemblyName>ConsoleApp3</AssemblyName>
		<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

In your .prop file, you're using TargetFramework to detect .NET Framework version, in this case, it will be always empty, so OpenCvSharpExtern.dll cannot be linked:

未经处理的异常:  System.TypeInitializationException: “OpenCvSharp.Internal.NativeMethods”的类型初始值设定项引发异常。 ---> System.DllNotFoundException: 无法加载 DLL“OpenCvSharpExtern”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。
   在 OpenCvSharp.Internal.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
   在 OpenCvSharp.Internal.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
   在 OpenCvSharp.Internal.NativeMethods..cctor()
   --- 内部异常堆栈跟踪的结尾 ---
   在 OpenCvSharp.Internal.NativeMethods.imgcodecs_imdecode_vector(Byte* buf, Int32 bufLength, Int32 flags, IntPtr& returnValue)
   在 OpenCvSharp.Cv2.ImDecode(ReadOnlySpan`1 span, ImreadModes flags)
   在 OpenCvSharp.Cv2.ImDecode(Byte[] buf, ImreadModes flags)
   在 ConsoleApp3.Program.<Main>d__0.MoveNext() 位置 C:\Users\ZhouJie\source\repos\ConsoleApp3\ConsoleApp3\Program.cs:行号 31
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   在 ConsoleApp3.Program.<Main>(String[] args)

You can try it by adding this target text in .csproj file:

	<Target Name="BeforeBuild">
		<Message Text="TargetFrameworkVersion: $(TargetFrameworkVersion)" Importance="high"/>
		<Message Text="TargetFramework: $(TargetFramework)" Importance="high"/>
	</Target>

In my machine, it will output following texts:

已启动重新生成…
1>------ 已启动全部重新生成: 项目: ConsoleApp3, 配置: Debug Any CPU ------
1>  TargetFrameworkVersion: v4.7.2
1>  TargetFramework: 
1>  ConsoleApp3 -> C:\Users\ZhouJie\source\repos\ConsoleApp3\ConsoleApp3\bin\Debug\ConsoleApp3.exe
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========

I suggest change the .prop file into detecting by TargetFrameworkVersion.

shimat added a commit that referenced this issue Dec 28, 2021
shimat added a commit that referenced this issue Dec 28, 2021
@shimat
Copy link
Owner

shimat commented Dec 28, 2021

Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants