无法找到程序集'DynamicAssembly,Version = 0.0.0.0';可序列化的动态类 [英] Unable to find assembly 'DynamicAssembly, Version=0.0.0.0'; serializable dynamic class
问题描述
我创建了一个可序列化的动态类。我使用这个类作为gridview的数据源。我能够创建动态类,正确填充并通过GridView显示数据。但是,一旦显示,如果我点击网页上的另一个控件,我会收到以下错误:
无法找到程序集'DynamicAssemblyDS,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null'。
I have created a serializable dynamic class. I use this class as a datasource to a gridview. I am able to create the dynamic class, populate correctly and display the data via the GridView. However once displayed if I click on another control on the web page i get the following error:
Unable to find assembly 'DynamicAssemblyDS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
错误描述
ERROR DESCRIPTION
System.Runtime.Serialization.SerializationException:无法找到程序集'DynamicAssemblyDS,Version = 0.0.0.0,Culture = neutral ,PublicKeyToken = null'。
System.Runtime.Serialization.SerializationException: Unable to find assembly 'DynamicAssemblyDS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
在System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo,String name)
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
在System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName,String [] memberNames, BinaryTypeEnum [] binaryTypeEnumA,Object [] typeInformationA,Int32 [] memberAssemIds,ObjectReader objectReader,Int32 objectId,BinaryAssemblyInfo assemblyInfo,SizedArray assemIdToAssemblyTable)...
at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) ...
我已将动态装配生成器设置为runAndSave并指定了dll文件并调用了Save方法?
代码如下;任何想法?
I have set the dynamic assembly builder to runAndSave andalso specified dll file and called the Save method?
Code is below; any ideas?
Dim currentDomain作为AppDomain = Thread.GetDomain
Dim dynamicAssemblyName As New AssemblyName(" DynamicAssemblyDS")
Dim dynamicAssemblyBuilder As AssemblyBuilder = currentDomain.DefineDynamicAssembly(dynamicAssemblyName,AssemblyBuilderAccess.RunAndSave)
Dim dynamicModuleBuilder As ModuleBuilder = dynamicAssemblyBuilder.DefineDynamicModule(dynamicAssemblyName.Name, "动态Assembly.dll")
Dim dynamicTypeBuilder As TypeBuilder = dynamicModuleBuilder.DefineType(" DynamicClassDS",TypeAttributes.Class And TypeAttributes.Serializable And TypeAttributes.Sealed And TypeAttributes.Public)
Dim constInfo As ConstructorInfo = GetType(SerializableAttribute).GetConstructor (New System.Type(){})
Dim attBuilder = New CustomAttributeBuilder(constInfo,New Object(){})
dynamicTypeBuilder.SetCustomAttribute(attBuilder)
Dim getSetAttr As MethodAttributes = MethodAttributes.Public或MethodAttributes.SpecialName Or MethodAttributes.HideBySig
'类字段,属性和方法设置
.......
Dim reportDataSourceType As System.Type = dynamicTypeBuilde r.CreateType
dynamicAssemblyBuilder.Save(" DynamicAssembly.dll")
返回reportDataSourceType
推荐答案
dynamicAssemblyBuilder.Save(" DynamicAssembly.dll")
发送文件到?为了能够由ASP.NET加载,需要位于虚拟目录的\bin目录中。
但是你可能只是想要一个不同的问题;我很确定当\ bin目录的内容发生变化时,ASP.NET会自动回收应用程序。这很可能会导致当前请求失败。
你想在这里实现什么目标?有没有比发出动态装配更简单的方法?
-steve
这篇关于无法找到程序集'DynamicAssembly,Version = 0.0.0.0';可序列化的动态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!