Hong dan cai microsoft primary interop assemblies là gì
Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật. Show
Error when you build a project in Visual Studio
Trong bài viết nàyThis article helps you resolve the problem where you cannot build a .NET Framework-based project in Visual Studio. Original product version: .NET Framework 4.5 Original KB number: 2956788 SymptomsConsider the following scenario:
In this scenario, when you build the project, this build program cannot load the interop assembly for the control. Additionally, you receive an error message that resembles the following: AxImp Error: Cannot resolve dependency to assembly 'office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event. Note This issue only occurs on the computer that has the .NET Framework 4.0, the .NET Framework 4.5 or the .NET Framework 4.5.1, and the Microsoft Office product installed. CauseThis issue occurs because of a design change between common language runtime (CLR) 2.0 and CLR 4.0 on how the type libraries and dependencies are loaded. The .NET Framework 4.0 needs certain assemblies to be loaded when you resolve types from a type library that references a primary interop assembly. However, that was not the case in the .NET Framework 2.0. The ActiveX importer did not change behavior between the .NET Framework 2.0 and the Framework 4.0. This design change prevents generation of the interop assemblies. Therefore, when ActiveX importer runs in Visual Studio, the importer cannot resolve and preload all references for this ActiveX control. WorkaroundTo work around this issue, create the interop assemblies by using AxImp.exe. For example, the error message that is mentioned in the section indicates that the required Microsoft office assembly is version 12.0. To resolve this issue, follow these steps:
Note If Office primary interop assembly is not installed on the computer, the AxImp.exe tool still can resolve the types without any assistance, even when it runs from the Visual Studio build process. More informationAxImp.exe is a command-line tool and is available with the Visual Studio. This tool accepts reference assemblies as command-line arguments. Therefore, this tool can load the additional assemblies that are expected by the .NET Framework 4.0. Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.
Trong bài viết nàyYou can create Component Object Model (COM) wrappers by using Visual Studio features or the .NET Framework tools Tlbimp.exe and Regasm.exe. Both methods generate two types of COM wrappers:
In Visual Studio, you can add the COM wrapper as a reference to your project. To create a runtime callable wrapper using Visual Studio
You can now write code to access the COM object. You can begin by declaring the object, such as with an To create a runtime callable wrapper using .NET Framework tools
This tool creates an assembly that contains run-time metadata for the types defined in the original type library. Wrap Managed Objects in a Native ApplicationTo create a COM callable wrapper using Visual Studio
When you build the project, the assembly is automatically registered for COM interop. If you are building a native application in Visual Studio, you can use the assembly by clicking Add Reference on the Project menu. To create a COM callable wrapper using .NET Framework toolsRun the Regasm.exe (Assembly Registration Tool) tool. This tool reads the assembly metadata and adds the necessary entries to the registry. As a result, COM clients can create .NET Framework classes transparently. You can use the assembly as if it were a native COM class. You can run Regasm.exe on an assembly located in any directory, and then run the Gacutil.exe (Global Assembly Cache Tool) to move it to the global assembly cache. Moving the assembly does not invalidate location registry entries, because the global assembly cache is always examined if the assembly is not found elsewhere. |