Using System.Messaging引用报错解决办法

如何在项目中引用System.Messaging并解决编译错误
通过在项目中执行添加引用步骤,搜索并引入System.Messaging库,然后在代码中使用usingSystem.Messaging导入命名空间,可以避免编译时的错误,确保对消息队列功能的正确调用。

1.在项目的引用上选择“添加引用”

2.在搜索里输主system.messaging,然后在列表中选中此项

 

3.这时候在代码中加入using System.Messaging就不会报错了

 

unity报错: SerializationException: Unable to find assembly 'UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly () (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType (System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo assemblyInfo, System.String name) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor (System.String objectName, System.String[] memberNames, System.Runtime.Serialization.Formatters.Binary.BinaryTypeEnum[] binaryTypeEnumA, System.Object[] typeInformationA, System.Int32[] memberAssemIds, System.Runtime.Serialization.Formatters.Binary.ObjectReader objectReader, System.Int32 objectId, System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo assemblyInfo, System.Runtime.Serialization.Formatters.Binary.SizedArray assemIdToAssemblyTable) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create (System.String name, System.String[] memberNames, System.Runtime.Serialization.Formatters.Binary.BinaryTypeEnum[] binaryTypeEnumA, System.Object[] typeInformationA, System.Int32[] memberAssemIds, System.Runtime.Serialization.Formatters.Binary.ObjectReader objectReader, System.Int32 objectId, System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo assemblyInfo, System.Runtime.Serialization.Formatters.Binary.SizedArray assemIdToAssemblyTable) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped (System.Runtime.Serialization.Formatters.Binary.BinaryObjectWithMapTyped record) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped (System.Runtime.Serialization.Formatters.Binary.BinaryHeaderEnum binaryHeaderEnum) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run () (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize (System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Runtime.Serialization.Formatters.Binary.__BinaryParser serParser, System.Boolean fCheck, System.Boolean isCrossAppDomain, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck, System.Boolean isCrossAppDomain, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck, System.Runtime.Remoting.Messaging.IMethodCallMessage methodCallMessage) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler, System.Boolean fCheck) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at <eae584ce26bc40229c1b1aa476bfa589>:0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at <eae584ce26bc40229c1b1aa476bfa589>:0) UnityEditor.Scripting.APIUpdater.AssemblyDependencyGraph.LoadFrom (System.IO.Stream stream) (at <970e850b448646cc95471fb650b1c784>:0) UnityEditorInternal.APIUpdating.APIUpdaterManager.ReadOrCreateAssemblyDependencyGraph (System.String assemblyDependencyGraphFilePath) (at <970e850b448646cc95471fb650b1c784>:0) UnityEditorInternal.APIUpdating.APIUpdaterManager.UpdateDependencyGraph (System.Collections.Generic.IEnumerable`1[T] addedAssemblyPaths) (at <970e850b448646cc95471fb650b1c784>:0) UnityEditorInternal.APIUpdating.APIUpdaterManager.ProcessImportedAssemblies (System.String[] assemblies) (at <970e850b448646cc95471fb650b1c784>:0)
06-26
严重性 代码 说明 项目 文件 行 禁止显示状态 错误 “FindRibbons”任务意外失败。 System.IO.FileNotFoundException: 未能加载文件或程序集“EzA10Addin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=35995b25910ac654”或它的某一个依赖项。系统找不到指定的文件。 文件名:“EzA10Addin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=35995b25910ac654” Server stack trace: 在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) 在 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 在 System.Reflection.Assembly.Load(String assemblyString) 在 System.UnitySerializationHolder.GetRealObject(StreamingContext context) 在 System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder) 在 System.Runtime.Serialization.ObjectManager.DoFixups() 在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) 在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) 在 System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm) 在 System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.FixupForNewAppDomain() 在 System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg) Exception rethrown at [0]: 在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 在 Microsoft.Build.Framework.ITask.Execute() 在 Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 在 Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() 警告: 程序集绑定日志记录被关闭。 要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。 注意: 会有一些与程序集绑定失败日志记录关联的性能损失。 要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。 EzA10Addin 这是什么报错
最新发布
07-09
<think>好的,我现在需要帮助用户解决在C#中添加System.Messaging引用的问题。首先,用户可能正在开发一个涉及消息队列的应用,比如使用MSMQ进行进程间通信。根据引用[4],用户可能在配置权限时遇到问题,但当前的问题是关于如何添加引用的。 首先,我应该回忆一下如何在C#项目中添加引用System.Messaging.NET Framework的一部分,但在较新的.NET版本中可能需要不同的方式引用。用户可能使用的是.NET Core或.NET 5+,这时候可能需要安装NuGet包。 根据引用[2]和[5],示例代码使用了System.Messaging命名空间,说明在传统.NET Framework项目中可以直接添加引用。但如果是.NET Core或更高版本,可能需要通过NuGet获取。因此,我需要分两种情况说明:传统框架项目和新的.NET项目。 接下来,用户可能不知道在哪里找到添加引用的选项。在Visual Studio中,右击项目选择“添加”->“引用”,然后在程序集中查找。对于.NET Core,需要转到NuGet包管理器安装System.Messaging的兼容包,比如System.Messaging。 另外,用户可能会遇到权限问题,如引用[4]提到的访问被拒绝,但当前问题先解决引用添加,之后再处理权限配置。不过可能在回答中需要简要提及,以预防后续问题。 需要确保步骤清晰,分点说明,并包含代码示例,如引用[2]中的发送消息代码。同时,提示用户根据项目类型选择正确的方法,并注意权限设置,引用[4]中的解决方案可能对后续有帮助。 最后,生成相关问题,帮助用户深入理解,比如如何发送消息、处理权限错误等,参考用户之前的引用内容来设计问题。</think>在C#中使用System.Messaging进行消息队列开发时,添加引用的配置方法分为以下两种场景: ### 一、.NET Framework项目配置 1. **添加程序集引用** - 右键项目 → 选择“添加” → “引用” - 在“程序集”选项卡中勾选`System.Messaging` - 代码头部添加命名空间: ```csharp using System.Messaging; ``` 2. **验证安装** 确保Windows功能已启用: ```powershell # 启用MSMQ核心功能 Enable-WindowsOptionalFeature -Online -FeatureName MSMQ-Server -All ``` ### 二、.NET Core/.NET 5+项目配置 1. **通过NuGet安装兼容包** - 打开NuGet包管理器控制台: ```bash Install-Package System.Messaging.MessageQueue -Version 5.0.0 ``` - 或通过VS的NuGet界面搜索安装`System.Messaging.MessageQueue` 2. **代码示例(发送消息)** ```csharp if (!MessageQueue.Exists(@".\Private$\MyQueue")) { MessageQueue.Create(@".\Private$\MyQueue"); } using var queue = new MessageQueue(@".\Private$\MyQueue"); queue.Send("Test Message", MessageQueueTransactionType.Single); ``` ### 三、关键注意事项 1. **权限配置** 如果出现`MessageQueueException: 访问被拒绝`错误,需在队列属性中添加`SYSTEM`用户并赋予完全控制权限[^4] 2. **兼容性说明** - `System.Messaging`仅支持Windows平台 - 跨平台方案建议使用RabbitMQ或Azure Service Bus
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值