任何机构都可以告诉我regsvr32和RegAsm有什么区别?我的Dll在C#中,那么如何将类导入到c ++中呢?
当我尝试在我的 c# .NET Framework 4.7.2 类库中打开表单时出现此错误。检查自动生成绑定重定向
调用堆栈是
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) …Run Code Online (Sandbox Code Playgroud) [最近的笔记]
如果不是 com-visible 方面,这个问题将是这个问题的副本关于 assembly binding。我已经挣扎了好几天,因为我没有意识到我需要改变我的单元测试项目以及 com 可见项目。如果你不想通读我意识到这一点的挣扎,请跳到最后一次更新。
[前言]
我担心这可能是尝试通过 COM Visible Framework 4.7.2 库从 VB6 访问 dotnet 标准 2.0 库的桥梁,但想尝试一下。
你好世界确实有效。(即调用一个返回字符串的简单函数)
但是,当我尝试通过 IDE 或作为 .EXE 运行 VB6 程序时出现此错误。
该错误消息表明该问题发生在 c# dotnet standard2.0 库的代码中。
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions,
Version=3.1.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60' or one of its dependencies.
The system cannot find the file specified.
File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.0.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3()
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired) …Run Code Online (Sandbox Code Playgroud) 我想在.net Core中构建COM对象,然后通过RegAsm注册。
我的.csproj文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net4.7.2</TargetFrameworks>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<Platforms>x64</Platforms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我的program.cs:
using System;
using System.Runtime.InteropServices;
namespace ComExample
{
[Guid("7ce1e40f-760a-4d81-b70b-61108ed15cb4")]
[ComVisible(true)]
public interface IComExampleClass
{
IComModelClass ExampleMethod(string param1, string param2);
}
[Guid("a8436b3f-3657-4a01-a133-fd333a84cb58")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class ComExampleClass : IComExampleClass
{
public IComModelClass ExampleMethod(string param1, string param2)
{
return new ComModelClass()
{
Result = $"{param1} + {param2}"
};
}
}
[Guid("9f5aeede-ec3e-443d-8ba0-9a9f2a6b9e53")]
[ComVisible(true)]
public interface IComModelClass
{
string Result { get; set; }
}
[Guid("526c6cb5-264d-4629-a894-fff02aeb9ec1")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class ComModelClass …Run Code Online (Sandbox Code Playgroud) c# ×2
com ×2
regasm ×2
.net ×1
.net-core ×1
c++ ×1
com-interop ×1
datagridview ×1
tlbexp ×1
vb6 ×1
visual-c++ ×1
winforms ×1